public ActionResult RolePermission(int id, int[][] array) { var subject = RBACService.GetSubject(id, false, false, false); var roles = RBACService.GetRoles(); foreach (var roleId in array[0]) { var found = roles.First(n => n.RoleId == roleId); if (found != null) { subject.Add(found); } } var permissions = RBACService.GetPermissions(); foreach (var permissionId in array[1]) { var found = permissions.First(n => n.PermissionId == permissionId); if (found != null) { subject.Add(found); } } RBACWriteService.SaveSubjectRoles(subject); RBACWriteService.SaveSubjectPermissions(subject); return(new JsonNetResult(new object())); }
public ActionResult RolePermission(int id) { var subject = RBACService.GetSubject(id, true, false, true); ViewBag.Subject = subject; var roles = RBACService.GetRoles(); var treeRole = TreeService.GetTree(Constants.ROLE_TREE_ID); var jsTreeRole = new JsTreeBuilder <Role>(x => x.Name, x => x.RoleId) .Build(treeRole, roles); jsTreeRole.Each(x => { if (x == jsTreeRole) { return; } if (subject.HaveRole(x.data.content)) { x.state.selected = true; } }); ViewBag.RoleTree = jsTreeRole.children; var permissions = RBACService.GetPermissions(); var treePermission = TreeService.GetTree(Constants.PERMISSION_TREE_ID); var jsTreePermission = new JsTreeBuilder <Permission>(x => x.Name, x => x.PermissionId) .Build(treePermission, permissions); jsTreePermission.Each(x => { if (x == jsTreePermission) { return; } if (subject.HaveDirectPermission(x.data.content)) { x.state.selected = true; } }); ViewBag.PermissionTree = jsTreePermission.children; return(View()); }
public ActionResult Permission(int id) { var subject = RBACService.GetSubject(id, true, true, true); var permissions = RBACService.GetPermissions(); var treePermission = TreeService.GetTree(Constants.PERMISSION_TREE_ID); var jsTreePermission = new JsTreeBuilder <Permission>(x => x.Name, x => x.PermissionId) .Build(treePermission, permissions); jsTreePermission.Each(x => { if (x == jsTreePermission) { return; } x.state.disabled = true; if (subject.HavePermission(x.data.content)) { x.state.selected = true; } }); return(new JsonNetResult(jsTreePermission.children)); }
public ActionResult Role(int id) { var subject = RBACService.GetSubject(id, true, false, false); var roles = RBACService.GetRoles(); var treeRole = TreeService.GetTree(Constants.ROLE_TREE_ID); var jsTreeRole = new JsTreeBuilder <Role>(x => x.Name, x => x.RoleId) .Build(treeRole, roles); jsTreeRole.Each(x => { if (x == jsTreeRole) { return; } x.state.disabled = true; if (subject.HaveRole(x.data.content)) { x.state.selected = true; } }); return(new JsonNetResult(jsTreeRole.children)); }