diff --git a/BExIS.Modules.Fmt.UI.csproj b/BExIS.Modules.Fmt.UI.csproj index 97955c3..6540c78 100644 --- a/BExIS.Modules.Fmt.UI.csproj +++ b/BExIS.Modules.Fmt.UI.csproj @@ -18,7 +18,7 @@ Properties BExIS.Modules.Fmt.UI BExIS.Modules.Fmt.UI - v4.5.2 + v4.8 false true @@ -29,6 +29,7 @@ + true @@ -65,12 +66,16 @@ True - + ..\..\..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll True + + + + ..\..\..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll True @@ -83,7 +88,6 @@ ..\..\..\..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll True - @@ -116,51 +120,10 @@ True ..\..\..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll + ..\..\..\..\packages\TelerikMvcExtensions.2013.2.611\lib\net40\Telerik.Web.Mvc.dll - - ..\..\..\..\Libraries\Vaiona\Vaiona.Core.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.Entities.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.Entities.Orm.NH.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.IoC.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.Logging.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.Model.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.MultiTenancy.Api.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.MultiTenancy.Services.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.Persistence.Api.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.PersistenceProviders.NH.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.Utils.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.Web.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.Web.Mvc.dll - - - ..\..\..\..\Libraries\Vaiona\Vaiona.Web.Mvc.Modularity.dll - ..\..\..\..\packages\WebActivator.1.2.0.0\lib\NETFramework40\WebActivator.dll True @@ -181,6 +144,8 @@ + + @@ -191,16 +156,17 @@ - - + + + + - @@ -213,6 +179,9 @@ + + + @@ -221,14 +190,18 @@ + + - + + + web.config @@ -248,7 +221,6 @@ - @@ -271,6 +243,54 @@ {e4795f06-20c2-4c4c-a720-9a79896384df} BExIS.IO + + {c4d4bc9e-8832-4966-be58-cb684e9a74e8} + Vaiona.Entities.Orm.NH + + + {0815d220-3625-4e23-bbbc-8152345637fe} + Vaiona.Entities + + + {29a7be0f-a17c-4ae8-8ca1-15fe4dd74129} + Vaiona.IoC + + + {e8b37581-1cac-463d-903b-b4bee8b2b0e3} + Vaiona.Logging + + + {a60ac05f-8c9a-4efd-9826-452e6049da4d} + Vaiona.Model + + + {bccd3d7b-8a50-4fa2-b9d3-2cb31bea60b3} + Vaiona.MultiTenancy.Api + + + {640bf81d-354a-4bf0-85fc-f0ad587cf8a2} + Vaiona.Persistence.Api + + + {8c5c0209-69a3-4579-9f9b-4d5f084a3b85} + Vaiona.Persistence.NH + + + {63fcacaa-9534-4fdd-a082-78dcc06baf28} + Vaiona.Utils + + + {705f8751-e58a-453e-a7fd-0c310fd3cae8} + Vaiona.Web.Mvc.Modularity + + + {5f5d22e8-8c05-49cd-854e-8fe8eff1aa6c} + Vaiona.Web.Mvc + + + {5b48b5a8-eae8-4ef8-8f2c-7fedb1b095d3} + Vaiona.Web + {252f7872-a69c-43a6-84b4-4d2abdbdd9ab} BExIS.Xml.Helpers @@ -338,7 +358,7 @@ mkdir "$(SolutionDir)Console\Workspace\Modules\FMT" -C:\Windows\System32\xcopy "$(ProjectDir)Fmt.Settings.xml" "$(SolutionDir)Console\Workspace\Modules\FMT" /C /Y /I +C:\Windows\System32\xcopy "$(ProjectDir)Fmt.Settings.json" "$(SolutionDir)Console\Workspace\Modules\FMT" /C /Y /I - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/Fmt.Settings.json b/Fmt.Settings.json new file mode 100644 index 0000000..72a6dfc --- /dev/null +++ b/Fmt.Settings.json @@ -0,0 +1,23 @@ +{ + "id": "fmt", + "name": "File management", + "description": "...", + "entries": [ + { + "key": "help", + "title": "Help URL", + "value": "", + "type": "String", + "description": "URL to the manual. If empty, it links to the latest manual from BEXIS2" + }, + { + "key": "SourcePathToFiles", + "title": "Source path to files", + "value": "C:\\inetpub\\wwwroot\\2030-TestSite\\Data_2030", + "description": "", + "type": "String", + "options": [] + } + + ] +} \ No newline at end of file diff --git a/Helper/MenuHelper.cs b/Helper/MenuHelper.cs index 0ec0fc7..581e207 100644 --- a/Helper/MenuHelper.cs +++ b/Helper/MenuHelper.cs @@ -12,12 +12,24 @@ using System.Web; using System.Xml; using System.Xml.Linq; +using Vaiona.IoC; using Vaiona.Utils.Cfg; namespace BExIS.Modules.FMT.UI.Helper { public class MenuHelper { + private readonly UserManager _userManager; + + public MenuHelper(UserManager userManager) + { + _userManager = userManager; + } + + public MenuHelper() + { + _userManager = IoCFactory.Container.Resolve(); + } private XmlDocument GetMenuXmlDoc() { string FMTPath = Path.Combine(AppConfiguration.DataPath, "FMT"); @@ -42,21 +54,21 @@ private XmlDocument GetMenuXmlDoc() xDoc = XDocument.Load(menuConfigPath); xmlDoc.Load(xDoc.CreateReader()); foreach (XmlNode node in xmlDoc.SelectNodes("/Item")) - CreateDirectoriesByXmlConfig(node, FMTPath); + CreateDirectoriesByXmlConfig(node, FMTPath); } return xmlDoc; } - internal bool HasUserAccessRights(string root, string userName, string node = "") + internal bool HasUserAccessRights(string root, string userName = null, string node = "") { XmlDocument xmlDoc = GetMenuXmlDoc(); string[] rootGroups; bool hasRights = false; - + string temp = ""; try { - string temp = xmlDoc.SelectSingleNode(string.Format("//Items[@Name='{0}']", root)).Attributes.GetNamedItem("Group").Value; + temp = xmlDoc.SelectSingleNode(string.Format("//Items[@Name='{0}']", root)).Attributes.GetNamedItem("Group").Value; rootGroups = temp.Split(','); } catch (Exception ex) @@ -66,24 +78,28 @@ internal bool HasUserAccessRights(string root, string userName, string node = "" //if node is empty then check only root node access if (node == "") { - if (rootGroups.Length > 0) + if (!String.IsNullOrEmpty(temp)) { - using (UserManager userManager = new UserManager()) + if (!String.IsNullOrEmpty(userName)) { - foreach (string roleName in rootGroups) - { - var userTask = userManager.FindByNameAsync(userName); - userTask.Wait(); - var user = userTask.Result; - - if (user.Groups.Select(a => a.Name).Contains(roleName)) + foreach (string roleName in rootGroups) { - hasRights = true; - break; + var userTask = _userManager.FindByNameAsync(userName); + userTask.Wait(); + var user = userTask.Result; + + if (user.Groups.Select(a => a.Name).Contains(roleName)) + { + hasRights = true; + break; + } } - } } } + else + { + hasRights = true; + } } //if node not empty check access rights to the singel node dependence on root. else @@ -91,26 +107,29 @@ internal bool HasUserAccessRights(string root, string userName, string node = "" //if node has an entry in Group check rights for user. If group empty skip access rights check try { - string temp = xmlDoc.SelectSingleNode(string.Format("//Items[@Name='{0}']", node)).Attributes.GetNamedItem("Group").Value; - if(String.IsNullOrEmpty(temp)) + temp = xmlDoc.SelectSingleNode(string.Format("//Items[@Name='{0}']", node)).Attributes.GetNamedItem("Group").Value; + if (String.IsNullOrEmpty(temp)) + { hasRights = true; + } else { - var nodeGroups = temp.Split(','); - using (UserManager userManager = new UserManager()) + if (!String.IsNullOrEmpty(userName)) { - foreach (string roleName in nodeGroups) - { - var userTask = userManager.FindByNameAsync(userName); - userTask.Wait(); - var user = userTask.Result; + var nodeGroups = temp.Split(','); - if (user.Groups.Select(a => a.Name).Contains(roleName)) + foreach (string roleName in nodeGroups) { - hasRights = true; - break; + var userTask = _userManager.FindByNameAsync(userName); + userTask.Wait(); + var user = userTask.Result; + + if (user.Groups.Select(a => a.Name).Contains(roleName)) + { + hasRights = true; + break; + } } - } } } } @@ -123,7 +142,7 @@ internal bool HasUserAccessRights(string root, string userName, string node = "" return hasRights; } - internal List GetMenu(string root, string userName) + internal List GetMenu(string root, string userName = null) { List menuItems = null; @@ -140,8 +159,11 @@ internal List GetMenu(string root, string userName) string path = FMTPath + @"\\" + root; foreach (var xmlMenuItem in GetMenuItems(xmlNodeList[0], path, root, userName).MenuItems) { + bool hasRights = false; + //check if user has rights to see menu entry (rights via groups) - bool hasRights = HasUserAccessRights(root, userName, xmlMenuItem.Name); + hasRights = HasUserAccessRights(root, userName, xmlMenuItem.Name); + if (hasRights) menuItems.Add(xmlMenuItem); } @@ -157,12 +179,12 @@ internal void AppendToRootMenu(XElement newXElement) var newItemName = newXElement.Attribute("Name").Value; var lastXElement = xElement.Elements().FirstOrDefault(item => item.Attribute("Name").Value == newItemName); if (lastXElement != null) - lastXElement.Remove(); + lastXElement.Remove(); xElement.Add(newXElement); xElement.Save(menuConfigPath); } - FMTMenuItem GetMenuItems(XmlNode xmlNode, string directory, string root, string userName) + FMTMenuItem GetMenuItems(XmlNode xmlNode, string directory, string root, string userName = null) { if (xmlNode.Name != "Item" && xmlNode.Name != "Items") return null; @@ -175,6 +197,7 @@ FMTMenuItem GetMenuItems(XmlNode xmlNode, string directory, string root, string { //check if user has rights to see menu entry (rights via groups) bool hasRights = HasUserAccessRights(root, userName, childXmlNode.Attributes["Name"].Value); + if (hasRights) item.MenuItems.Add(GetMenuItems(childXmlNode, directory + @"\\" + childXmlNode.Attributes["Name"].Value, root, userName)); } @@ -216,7 +239,7 @@ FMTMenuItem CreateDirectoriesByXmlConfig(XmlNode xmlNode, string directory) string filenameOnly = System.IO.Path.GetFileName(directory); - if (filenameOnly.Length==0) + if (filenameOnly.Length == 0) Directory.CreateDirectory(directory); item.MenuItems = new List(); @@ -232,7 +255,7 @@ public XmlElement XElementToXmlElement(XElement el) doc.Load(el.CreateReader()); return doc.DocumentElement; } - + } - + } diff --git a/Helper/Settings.cs b/Helper/Settings.cs deleted file mode 100644 index 6f95fb2..0000000 --- a/Helper/Settings.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Web; -using System.Xml; -using System.Xml.Linq; -using Vaiona.Utils.Cfg; - -namespace BExIS.Modules.FMT.UI.Helper -{ - static class Settings - { - - private static String filePath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("FMT"), "Fmt.settings.xml"); - private static Dictionary settings = new Dictionary(); - - /// - /// setup settings model - /// * load settings from settings.xml - /// - static Settings() - { - // intial loading of settings - reloadSettings(); - - // set up file watcher to listen for changes - using (FileSystemWatcher fw = new FileSystemWatcher()) - { - fw.Path = Path.GetDirectoryName(filePath); - fw.Filter = Path.GetFileName(filePath); - fw.Changed += new FileSystemEventHandler(fw_Changed); - fw.EnableRaisingEvents = true; - } - - } - - /// - /// retrieve a value from the settings file - /// - /// the key for the parameter - /// the respective value - public static object get(String key) - { - if (settings.ContainsKey(key)) - { - return settings[key]; - } - else - { - return null; - } - } - - /// - /// add or change an entry in the settings - /// TODO persist changes in workflow file - /// - /// - /// - public static void set(String key, object value) - { - if (settings.ContainsKey(key)) - { - settings[key] = value; - } - else - { - settings.Add(key, value); - } - } - - /// - /// Handler to listen for changes in settings file - /// - /// - /// - private static void fw_Changed(object sender, FileSystemEventArgs e) - { - reloadSettings(); - } - - /// - /// load settings anew from settings.xml - /// - private static void reloadSettings() - { - // get XML data - XDocument xDoc = XDocument.Load(filePath); - XmlDocument xmlDoc = new XmlDocument(); - xmlDoc.Load(xDoc.CreateReader()); - - // empty old settings list - settings.Clear(); - - // parse values - foreach (XmlNode node in xmlDoc.SelectNodes("//settings/entry")) - { - // shortcuts - var key = node.Attributes["key"] != null ? node.Attributes["key"].Value : null; - var value = node.Attributes["value"] != null ? node.Attributes["value"].Value : null; - var type = node.Attributes["type"] != null ? node.Attributes["type"].Value : null; - - // only parse valid entries - if ((null == key) || (null == value)) - { - continue; - } - - // convert types - switch (type) - { - case "int": - int intVal; - if (Int32.TryParse(value, out intVal)) - { - settings.Add(key, intVal); - } - else - { - settings.Add(key, value); - } - break; - - // default is string - default: - settings.Add(key, value); - break; - } - } - } - - } -} \ No newline at end of file diff --git a/Models/FileModel.cs b/Models/FileModel.cs index e2983de..257c766 100644 --- a/Models/FileModel.cs +++ b/Models/FileModel.cs @@ -8,6 +8,7 @@ using System.Web.UI; using BExIS.Modules.FMT.UI.Helper; using Shell32; +using Vaiona.Web.Mvc.Modularity; namespace BExIS.Modules.FMT.UI.Models @@ -57,7 +58,8 @@ public FileModel(FileInfo file, string dir, FileContentResult filecontent, bool internal static List GetFileModelList(String FMTMenuItemPath, bool hasRights) { string folderpath = ""; - folderpath = Helper.Settings.get("SourcePathToFiles").ToString(); + var settings = ModuleManager.GetModuleSettings("fmt"); + folderpath = settings.GetValueByKey("SourcePathToFiles").ToString(); if (String.IsNullOrEmpty(folderpath)) folderpath = AppConfiguration.DataPath; diff --git a/Properties/PublishProfiles/BexisServer_BE_DevSite.pubxml b/Properties/PublishProfiles/BexisServer_BE_DevSite.pubxml new file mode 100644 index 0000000..59bcbc5 --- /dev/null +++ b/Properties/PublishProfiles/BexisServer_BE_DevSite.pubxml @@ -0,0 +1,18 @@ + + + + + FileSystem + FileSystem + Release + Any CPU + + True + False + C:\inetpub\wwwroot\BE_DevSite\Site\Areas\FMT + False + + \ No newline at end of file diff --git a/Views/SocialEcologicalFiles/SocialEcologicalFiles.cshtml b/Views/DmpFiles/DmpFiles.cshtml similarity index 93% rename from Views/SocialEcologicalFiles/SocialEcologicalFiles.cshtml rename to Views/DmpFiles/DmpFiles.cshtml index cecf4e3..97bb5cb 100644 --- a/Views/SocialEcologicalFiles/SocialEcologicalFiles.cshtml +++ b/Views/DmpFiles/DmpFiles.cshtml @@ -84,15 +84,15 @@ function loadFilesAndUploader() { val = SelectedValue; - contr = "SocialEcologicalFiles"; - adminContr = "SocialEcologicalFilesAdmin"; - $.get('@Url.Action("GetFileLists", "SocialEcologicalFiles", new { area="FMT"})', { menuItemPath: val, contollerName: contr }, function (data) { + contr = "DmpFiles"; + adminContr = "DmpFilesAdmin"; + $.get('@Url.Action("GetFileLists", "DmpFiles", new { area="FMT"})', { menuItemPath: val, contollerName: contr }, function (data) { $('#FMTFilesDIV').html(data); }); var adminrights = @Html.Raw(Json.Encode(ViewData["AdminRights"])); if (adminrights) { - $.get('@Url.Action("GetFileUploader", "SocialEcologicalFilesAdmin", new { area = "FMT" })', { menuItemPath: val, contollerName: adminContr }, function (data) { + $.get('@Url.Action("GetFileUploader", "DmpFilesAdmin", new { area = "FMT" })', { menuItemPath: val, contollerName: adminContr }, function (data) { $('#FMTFileUpload').html(data); }); } diff --git a/Views/SocialEcologicalFilesAdmin/readme.txt b/Views/DmpFilesAdmin/readme.txt similarity index 100% rename from Views/SocialEcologicalFilesAdmin/readme.txt rename to Views/DmpFilesAdmin/readme.txt diff --git a/Views/Shared/_fileList.cshtml b/Views/Shared/_fileList.cshtml index d914b02..67389bd 100644 --- a/Views/Shared/_fileList.cshtml +++ b/Views/Shared/_fileList.cshtml @@ -44,7 +44,9 @@ @Html.ActionLink(linkText: file.Filename, actionName: "DownloadFile", controllerName: file.controllerName, routeValues: new { path = file.Filepath, mimeType = file.MimeType }, htmlAttributes: null) @filesize - @file.Date.ToString("dd-MM-yyyy") + + @file.Date.ToString("dd-MM-yyyy") + @if (file.HasRights) { diff --git a/Views/TechniciansFiles/TechniciansFiles.cshtml b/Views/TechniciansFiles/TechniciansFiles.cshtml new file mode 100644 index 0000000..4459e7e --- /dev/null +++ b/Views/TechniciansFiles/TechniciansFiles.cshtml @@ -0,0 +1,168 @@ +@using Telerik.Web.Mvc.UI +@using System.Collections.Generic +@using BExIS.Modules.FMT.UI.Models + +@model List + +@{ + + if (ViewBag.UseLayout == null) + { + Layout = null; + } +} +
+ +
+ + @Html.ValidationMessage("Error")
+ @if (Model == null) + { + + } + else + { + @Html.Telerik().TreeView().Name("TreeView").ShowCheckBox(false).ExpandAll(false).ClientEvents(events => events + .OnSelect("onSelect").OnLoad("click_node") + + ).BindTo(Model, mappings => + { + mappings.For + (binding => binding.ItemDataBound((item, menuItem) => + { + item.Text = menuItem.Title; + item.Value = menuItem.Path; + item.LinkHtmlAttributes["id"] = menuItem.Path.Replace("\\", "_"); + item.ImageUrl = menuItem.MenuItems.Any() ? "~/Areas/FMT/Images/FMT_Images/Folders.png" : "~/Areas/FMT/Images/FMT_Images/Folder.png"; + }) + .Children(category => category.MenuItems)); + mappings.For + (binding => binding + .ItemDataBound((item, subMenuItem) => + { + item.Text = subMenuItem.Title; + item.Value = subMenuItem.Path; + item.LinkHtmlAttributes["id"] = subMenuItem.Path.Replace("\\", "_"); + item.ImageUrl = subMenuItem.MenuItems.Any() ? "~/Areas/FMT/Images/FMT_Images/Folders.png" : "~/Areas/FMT/Images/FMT_Images/Folder.png"; + })); + }); + + + } + +
+ +
+
+
+
+
+
+ +
+
+
+ +
+
+
+ + + + \ No newline at end of file diff --git a/Views/TechniciansFilesAdmin/readme.txt b/Views/TechniciansFilesAdmin/readme.txt new file mode 100644 index 0000000..678ffc4 --- /dev/null +++ b/Views/TechniciansFilesAdmin/readme.txt @@ -0,0 +1 @@ +emty folder needed! \ No newline at end of file diff --git a/Views/ThematicGroupsFiles/ThematicGroupsFiles.cshtml b/Views/ThematicGroupsFiles/ThematicGroupsFiles.cshtml new file mode 100644 index 0000000..9db69af --- /dev/null +++ b/Views/ThematicGroupsFiles/ThematicGroupsFiles.cshtml @@ -0,0 +1,167 @@ +@using Telerik.Web.Mvc.UI +@using System.Collections.Generic +@using BExIS.Modules.FMT.UI.Models + +@model List + +@{ + + if (ViewBag.UseLayout == null) + { + Layout = null; + } +} +
+ +
+ + @Html.ValidationMessage("Error")
+ @if (Model == null) + { + + } + else + { + @Html.Telerik().TreeView().Name("TreeView").ShowCheckBox(false).ExpandAll(false).ClientEvents(events => events + .OnSelect("onSelect").OnLoad("click_node") + + ).BindTo(Model, mappings => + { + mappings.For + (binding => binding.ItemDataBound((item, menuItem) => + { + item.Text = menuItem.Title; + item.Value = menuItem.Path; + item.LinkHtmlAttributes["id"] = menuItem.Path.Replace("\\", "_"); + item.ImageUrl = menuItem.MenuItems.Any() ? "~/Areas/FMT/Images/FMT_Images/Folders.png" : "~/Areas/FMT/Images/FMT_Images/Folder.png"; + }) + .Children(category => category.MenuItems)); + mappings.For + (binding => binding + .ItemDataBound((item, subMenuItem) => + { + item.Text = subMenuItem.Title; + item.Value = subMenuItem.Path; + item.LinkHtmlAttributes["id"] = subMenuItem.Path.Replace("\\", "_"); + item.ImageUrl = subMenuItem.MenuItems.Any() ? "~/Areas/FMT/Images/FMT_Images/Folders.png" : "~/Areas/FMT/Images/FMT_Images/Folder.png"; + })); + }); + + + } + +
+ +
+ +
+
+
+ +
+
+
+ +
+
+
+ + + + \ No newline at end of file diff --git a/Views/ThematicGroupsFilesAdmin/readme.txt b/Views/ThematicGroupsFilesAdmin/readme.txt new file mode 100644 index 0000000..678ffc4 --- /dev/null +++ b/Views/ThematicGroupsFilesAdmin/readme.txt @@ -0,0 +1 @@ +emty folder needed! \ No newline at end of file diff --git a/web.config b/web.config index 45a0240..6f79699 100644 --- a/web.config +++ b/web.config @@ -1,100 +1,109 @@ - + + - - + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - + + + + - + + \ No newline at end of file