public void Copy_should_not_include_permissions() { Role role1 = new Role() { Name = "Role 1" }; Role role2 = new Role() { Name = "Role 2" }; Section section = CreateSection(1, "Section 1", "main", 1); section.SectionPermissions.Add(new SectionPermission { Id = 1, Section = section, Role = role1, ViewAllowed = true, EditAllowed = true }); section.SectionPermissions.Add(new SectionPermission { Id = 2, Section = section, Role = role2, ViewAllowed = true, EditAllowed = false }); Assert.That(section.SectionPermissions.Count, Is.EqualTo(2)); Assert.That(section.EditAllowed(role1), Is.True); Assert.That(section.EditAllowed(role2), Is.False); Section copyOfSection = section.Copy(); Assert.That(copyOfSection.SectionPermissions, Is.Empty); }
public ActionResult NewRole() { ViewData["Rights"] = this._userService.GetAllRights(); Role role = new Role(); return View(role); }
public ActionResult CreateRole(int[] rightIds) { Role newRole = new Role(); try { UpdateModel(newRole, "role"); if (rightIds != null && rightIds.Length > 0) { IList<Right> rights = this._userService.GetRightsByIds(rightIds); foreach (Right right in rights) { newRole.Rights.Add(right); } } if (ValidateModel(newRole, this._roleModelValidator, new [] { "Name" })) { this._userService.CreateRole(newRole, CuyahogaContext.CurrentSite); Messages.AddFlashMessageWithParams("RoleCreatedMessage", newRole.Name); return RedirectToAction("roles"); } } catch (Exception ex) { Messages.AddException(ex); } ViewData["Title"] = GetText("NewRolePageTitle"); ViewData["Rights"] = this._userService.GetAllRights(); return View("NewRole", newRole); }
/// <summary> /// /// </summary> /// <param name="role"></param> /// <returns></returns> public virtual bool ViewAllowed(Role role) { foreach (NodePermission np in this.NodePermissions) { if (np.Role == role && np.ViewAllowed) { return true; } } return false; }
private void Page_Load(object sender, System.EventArgs e) { this.Title = "Edit role"; if (Context.Request.QueryString["RoleId"] != null) { if (Int32.Parse(Context.Request.QueryString["RoleId"]) == -1) { this._activeRole = new Role(); } else { this._activeRole = (Role)base.CoreRepository.GetObjectById(typeof(Role) , Int32.Parse(Context.Request.QueryString["RoleId"])); } if (! this.IsPostBack) { BindRoleControls(); BindPermissions(); } } }
/// <summary> /// Determine if the user is in a give Role. /// </summary> /// <param name="roleToCheck"></param> /// <returns></returns> public virtual bool IsInRole(Role roleToCheck) { foreach (Role role in this.Roles) { if (role.Id == roleToCheck.Id && role.Name == roleToCheck.Name) { return true; } } return false; }
/// <summary> /// Does the specified role have view rights to this Section? /// </summary> /// <param name="role"></param> /// <returns></returns> public virtual bool ViewAllowed(Role role) { foreach (SectionPermission sp in this.SectionPermissions) { if (sp.Role == role && sp.ViewAllowed) { return true; } } return false; }
/// <summary> /// Check if download of the file is allowed for the given role. /// </summary> /// <param name="roleToCheck"></param> /// <returns></returns> public virtual bool IsDownloadAllowed(Role roleToCheck) { foreach (Role role in this._allowedRoles) { if (role.Id == roleToCheck.Id && role.Name == roleToCheck.Name) { return true; } } return false; }
protected void Page_Load(object sender, EventArgs e) { this.Title = "Edit role"; if (Context.Request.QueryString["RoleId"] != null) { if (Int32.Parse(Context.Request.QueryString["RoleId"]) == -1) { this._activeRole = new Role(); } else { this._activeRole = base.UserService.GetRoleById(Int32.Parse(Context.Request.QueryString["RoleId"])); } if (!this.IsPostBack) { BindRoleControls(); BindRights(); } } }
public void Copy_should_inherit_permissions_new_parent() { Role role1 = new Role(); Role role2 = new Role(); this._rootNode.NodePermissions.Add(new NodePermission { Id = 1, Node = this._rootNode, Role = role1, ViewAllowed = true, EditAllowed = true }); this._rootNode.NodePermissions.Add(new NodePermission { Id = 2, Node = this._rootNode, Role = role2, ViewAllowed = true, EditAllowed = false }); Node page2 = this._rootNode.ChildNodes[1]; page2.NodePermissions.Add(new NodePermission { Id = 3, Node = page2, Role = role2, ViewAllowed = true, EditAllowed = true }); Node copyOfPage2 = page2.Copy(this._rootNode); Assert.That(page2.NodePermissions.Count, Is.EqualTo(1)); Assert.That(page2.EditAllowed(role1), Is.False); Assert.That(copyOfPage2.NodePermissions.Count, Is.EqualTo(2)); Assert.That(copyOfPage2.EditAllowed(role1), Is.True); }