Example #1
0
        public static void CheckMenuItemPermission(RFMenuItem item, List <RFUserPermission> permissions)
        {
            var area       = item.Area;
            var controller = item.Controller;

            if (string.IsNullOrWhiteSpace(controller) && !string.IsNullOrWhiteSpace(area))
            {
                item.Disabled = item.Disabled || !permissions.Any(p => p.Area == item.Area);
            }
            else if (!string.IsNullOrWhiteSpace(controller) && !string.IsNullOrWhiteSpace(area))
            {
                item.Disabled = item.Disabled || !permissions.Any(p => p.Area == item.Area && p.Controller == item.Controller);
            }
            if (item.SubMenu != null)
            {
                foreach (var child in item.SubMenu)
                {
                    CheckMenuItemPermission(child, permissions);
                }
            }
        }
Example #2
0
        public static RFMenu GetMenu(string username, bool presentationMode)
        {
            var permissions = UserRole.GetPermissions(username, RFAccessLevel.Read.ToString());

            // user menus + system menus
            var menu = Config.GetMenu(UserRole, username, presentationMode);

            var administrationMenu = new RFMenuItem
            {
                Text       = "Administration",
                Action     = null,
                Area       = null,
                Disabled   = UserRole.RequiresPermission(username) && !UserRole.HasPermission(username, "core", typeof(RIFF.Web.Core.Controllers.SystemController).Name, "Admin"), // special permission
                Controller = null,
                SubMenu    = new List <RFMenuItem> {
                    new RFMenuItem {
                        Text       = "Processes",
                        SubMenu    = null,
                        Action     = "Processes",
                        Area       = null,
                        Controller = "System",
                    },
                    new RFMenuItem {
                        Text       = "Input Files",
                        SubMenu    = null,
                        Action     = "InputFiles",
                        Area       = null,
                        Controller = "System",
                    },
                    new RFMenuItem {
                        Text       = "Data Editor",
                        SubMenu    = null,
                        Action     = "DataEditor",
                        Area       = null,
                        Controller = "System",
                    },
                    new RFMenuItem {
                        Text       = "Console",
                        SubMenu    = null,
                        Action     = "Console",
                        Area       = null,
                        Controller = "System",
                    },
                    new RFMenuItem {
                        Text       = "System Log",
                        SubMenu    = null,
                        Action     = "Logs",
                        Area       = null,
                        Controller = "System",
                    },
                    new RFMenuItem {
                        Text       = "Maintenance",
                        SubMenu    = null,
                        Action     = "Maintenance",
                        Area       = null,
                        Controller = "System",
                    }
                }
            };

            var systemMenu = new RFMenuItem
            {
                Text       = "System",
                Action     = null,
                Area       = "Core",
                Controller = "System",
                Icon       = "preferences",
                SubMenu    = new List <RFMenuItem> {
                    new RFMenuItem {
                        Text       = "Configuration",
                        Action     = "Config",
                        Area       = null,
                        Controller = "System",
                    },
                    new RFMenuItem {
                        Text       = "Access Control",
                        SubMenu    = null,
                        Action     = "Index",
                        Area       = null,
                        Controller = "Role",
                    },
                    new RFMenuItem {
                        Text       = "Activity Log",
                        SubMenu    = null,
                        Action     = "UserLog",
                        Area       = null,
                        Controller = "System",
                    },
                    new RFMenuItem {
                        Text       = "Error Queue",
                        SubMenu    = null,
                        Action     = "ErrorQueue",
                        Area       = null,
                        Controller = "System",
                    },
                    new RFMenuItem {
                        Text       = "Input Reports",
                        SubMenu    = null,
                        Action     = "InputReports",
                        Area       = null,
                        Controller = "System",
                    },
                    new RFMenuItem {
                        Text       = "Received Files",
                        SubMenu    = null,
                        Action     = "Index",
                        Area       = null,
                        Controller = "Mirror",
                    },
                    new RFMenuItem {
                        Text       = "Scheduled Tasks",
                        SubMenu    = null,
                        Action     = "Tasks",
                        Area       = null,
                        Controller = "System",
                    },
                    new RFMenuItem {
                        Text       = "Data Browser",
                        SubMenu    = null,
                        Action     = "Index",
                        Area       = null,
                        Controller = "Data",
                    },
                    new RFMenuItem {
                        Text       = "Graph Browser",
                        SubMenu    = null,
                        Action     = "GraphMap",
                        Area       = null,
                        Controller = "Mapper",
                    },
                    administrationMenu
                }
            };

            menu.Items.Add(systemMenu);

            // disable non-permissioned controllers
            if (UserRole.RequiresPermission(username))
            {
                foreach (var item in menu.Items)
                {
                    CheckMenuItemPermission(item, permissions);
                }
            }

            return(menu);
        }