Exemple #1
0
        public virtual void SeedPermissions(RoleView view)
        {
            MvcTreeNode root = new MvcTreeNode(Resource.ForString("All"));

            view.Permissions.Nodes.Add(root);

            foreach (IGrouping <String, Permission> area in GetAllPermissions().GroupBy(permission => permission.Area))
            {
                MvcTreeNode areaNode = new MvcTreeNode(area.Key);
                foreach (IGrouping <String, Permission> controller in area.GroupBy(permission => permission.Controller))
                {
                    MvcTreeNode controllerNode = new MvcTreeNode(controller.Key);
                    foreach (Permission permission in controller)
                    {
                        controllerNode.Children.Add(new MvcTreeNode(permission.Id, permission.Action));
                    }

                    if (areaNode.Title == null)
                    {
                        root.Children.Add(controllerNode);
                    }
                    else
                    {
                        areaNode.Children.Add(controllerNode);
                    }
                }

                if (areaNode.Title != null)
                {
                    root.Children.Add(areaNode);
                }
            }
        }
Exemple #2
0
        public virtual void SeedPermissions(RoleView view)
        {
            MvcTreeNode root = new MvcTreeNode(Resource.ForString("All"));

            view.Permissions.Nodes.Add(root);

            foreach (IGrouping <String?, PermissionView> area in GetAllPermissions().GroupBy(permission => permission.Area))
            {
                List <MvcTreeNode> nodes = new List <MvcTreeNode>();
                foreach (IGrouping <String, PermissionView> controller in area.GroupBy(permission => permission.Controller !))
                {
                    MvcTreeNode node = new MvcTreeNode(controller.Key);
                    foreach (PermissionView permission in controller)
                    {
                        node.Children.Add(new MvcTreeNode(permission.Id, permission.Action !));
                    }

                    nodes.Add(node);
                }

                if (area.Key == null)
                {
                    root.Children.AddRange(nodes);
                }
                else
                {
                    root.Children.Add(new MvcTreeNode(area.Key)
                    {
                        Children = nodes
                    });
                }
            }
        }
Exemple #3
0
        public void MvcTreeNode_SetsTitle()
        {
            MvcTreeNode actual = new MvcTreeNode("Title");

            Assert.Equal("Title", actual.Title);
            Assert.Empty(actual.Children);
            Assert.Null(actual.Id);
        }
        public void MvcTreeNode_SetsIdAndTitle()
        {
            MvcTreeNode actual = new MvcTreeNode(1, "Nodey");

            Assert.Equal("Nodey", actual.Title);
            Assert.Empty(actual.Children);
            Assert.Equal(1, actual.Id);
        }
        private MvcTree CreatePermissions()
        {
            MvcTreeNode root         = new MvcTreeNode(Resource.ForString("All"));
            MvcTree     expectedTree = new MvcTree();

            expectedTree.Nodes.Add(root);
            expectedTree.SelectedIds = new HashSet <Int64>(role.Permissions.Select(rolePermission => rolePermission.PermissionId));

            IEnumerable <PermissionView> permissions = role
                                                       .Permissions
                                                       .Select(rolePermission => rolePermission.Permission)
                                                       .Select(permission => new PermissionView
            {
                Id         = permission.Id,
                Action     = Resource.ForAction(permission.Action),
                Area       = permission.Area == null ? null : Resource.ForArea(permission.Area),
                Controller = Resource.ForController($"{permission.Area}/{permission.Controller}")
            });

            foreach (IGrouping <String?, PermissionView> area in permissions.GroupBy(permission => permission.Area).OrderBy(permission => permission.Key ?? permission.FirstOrDefault()?.Controller))
            {
                List <MvcTreeNode> nodes = new List <MvcTreeNode>();

                foreach (IGrouping <String, PermissionView> controller in area.GroupBy(permission => permission.Controller !))
                {
                    MvcTreeNode node = new MvcTreeNode(controller.Key);

                    foreach (PermissionView permission in controller)
                    {
                        node.Children.Add(new MvcTreeNode(permission.Id, permission.Action !));
                    }

                    nodes.Add(node);
                }

                if (area.Key == null)
                {
                    root.Children.AddRange(nodes);
                }
                else
                {
                    root.Children.Add(new MvcTreeNode(area.Key)
                    {
                        Children = nodes
                    });
                }
            }

            return(expectedTree);
        }
Exemple #6
0
        private MvcTree CreatePermissions()
        {
            MvcTreeNode root         = new MvcTreeNode(Resource.ForString("All"));
            MvcTree     expectedTree = new MvcTree();

            expectedTree.Nodes.Add(root);
            expectedTree.SelectedIds = new HashSet <Int32>(role.Permissions.Select(rolePermission => rolePermission.PermissionId));

            IEnumerable <Permission> permissions = role
                                                   .Permissions
                                                   .Select(rolePermission => rolePermission.Permission)
                                                   .Select(permission => new Permission
            {
                Id         = permission.Id,
                Area       = Resource.ForPermission(permission.Area),
                Controller = Resource.ForPermission(permission.Area, permission.Controller),
                Action     = Resource.ForPermission(permission.Area, permission.Controller, permission.Action)
            });

            foreach (IGrouping <String, Permission> area in permissions.GroupBy(permission => permission.Area).OrderBy(permission => permission.Key ?? permission.FirstOrDefault().Controller))
            {
                MvcTreeNode areaNode = new MvcTreeNode(area.Key);
                foreach (IGrouping <String, Permission> controller in area.GroupBy(permission => permission.Controller).OrderBy(permission => permission.Key))
                {
                    MvcTreeNode controllerNode = new MvcTreeNode(controller.Key);
                    foreach (Permission permission in controller.OrderBy(permission => permission.Action))
                    {
                        controllerNode.Children.Add(new MvcTreeNode(permission.Id, permission.Action));
                    }

                    if (areaNode.Title == null)
                    {
                        root.Children.Add(controllerNode);
                    }
                    else
                    {
                        areaNode.Children.Add(controllerNode);
                    }
                }

                if (areaNode.Title != null)
                {
                    root.Children.Add(areaNode);
                }
            }

            return(expectedTree);
        }