/// <summary> /// Generates the permission matrix for the cutrrent forum. /// </summary> private void CreateMatrix() { // Get forum resource info if (resForums == null) { resForums = ResourceInfoProvider.GetResourceInfo("CMS.Forums"); } // Get forum object if ((forum == null) && (ForumID > 0)) { forum = ForumInfoProvider.GetForumInfo(this.ForumID); } if ((resForums != null) && (forum != null)) { // Get permission matrix for roles of the current site/group int groupId = 0; if (this.IsGroupForum) { ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(forum.ForumGroupID); groupId = fgi.GroupGroupID; } // Get permissions for the current forum resource DataSet permissions = PermissionNameInfoProvider.GetResourcePermissions(resForums.ResourceId); if (DataHelper.DataSourceIsEmpty(permissions)) { lblInfo.Text = GetString("general.emptymatrix"); } else { TableRow headerRow = new TableRow(); headerRow.CssClass = "UniGridHead"; TableCell newCell = new TableCell(); TableHeaderCell newHeaderCell = new TableHeaderCell(); newHeaderCell.Text = " "; newHeaderCell.Attributes["style"] = "width:200px;"; headerRow.Cells.Add(newHeaderCell); foreach (string permission in allowedPermissions) { DataRow[] drArray = permissions.Tables[0].DefaultView.Table.Select("PermissionName = '" + permission + "'"); if ((drArray != null) && (drArray.Length > 0)) { DataRow dr = drArray[0]; newHeaderCell = new TableHeaderCell(); newHeaderCell.Attributes["style"] = "text-align:center;white-space:nowrap;"; newHeaderCell.Text = dr["PermissionDisplayName"].ToString(); newHeaderCell.ToolTip = dr["PermissionDescription"].ToString(); newHeaderCell.HorizontalAlign = HorizontalAlign.Center; headerRow.Cells.Add(newHeaderCell); } else { throw new Exception("[Security matrix] Column '" + permission + "' cannot be found."); } } newHeaderCell = new TableHeaderCell(); newHeaderCell.Text = " "; headerRow.Cells.Add(newHeaderCell); tblMatrix.Rows.Add(headerRow); // Render forum access permissions object[,] accessNames = new object[5, 2]; accessNames[0, 0] = GetString("security.nobody"); accessNames[0, 1] = SecurityAccessEnum.Nobody; accessNames[1, 0] = GetString("security.allusers"); accessNames[1, 1] = SecurityAccessEnum.AllUsers; accessNames[2, 0] = GetString("security.authenticated"); accessNames[2, 1] = SecurityAccessEnum.AuthenticatedUsers; accessNames[3, 0] = GetString("security.groupmembers"); accessNames[3, 1] = SecurityAccessEnum.GroupMembers; accessNames[4, 0] = GetString("security.authorizedroles"); accessNames[4, 1] = SecurityAccessEnum.AuthorizedRoles; TableRow newRow = null; int rowIndex = 0; for (int access = 0; access <= accessNames.GetUpperBound(0); access++) { SecurityAccessEnum currentAccess = ((SecurityAccessEnum)accessNames[access, 1]); // If the security isn't displayed as part of group section if ((currentAccess == SecurityAccessEnum.GroupMembers) && (!this.IsGroupForum)) { // Do not render this access item } else { // Generate cell holding access item name newRow = new TableRow(); newRow.CssClass = ((rowIndex % 2 == 0) ? "EvenRow" : "OddRow"); newCell = new TableCell(); newCell.Text = accessNames[access, 0].ToString(); newCell.Wrap = false; newCell.CssClass = "MatrixHeader"; newCell.Width = new Unit(28, UnitType.Percentage); newRow.Cells.Add(newCell); rowIndex++; // Render the permissions access items bool isAllowed = false; bool isDisabled = true; int permissionIndex = 0; for (int permission = 0; permission < (tblMatrix.Rows[0].Cells.Count - 2); permission++) { newCell = new TableCell(); // Check if the currently processed access is applied for permission isAllowed = CheckPermissionAccess(currentAccess, permission, tblMatrix.Rows[0].Cells[permission + 1].Text); isDisabled = ((currentAccess == SecurityAccessEnum.AllUsers) && (permission == 1)) || (!this.Enable); // Disable column in roles grid if needed if ((currentAccess == SecurityAccessEnum.AuthorizedRoles) && !isAllowed) { gridMatrix.DisableColumn(permissionIndex); } // Insert the radio button for the current permission string permissionText = tblMatrix.Rows[0].Cells[permission + 1].Text; string elemId = ClientID + "_" + permission + "_" + access; newCell.Text = "<label style=\"display:none;\" for=\"" + elemId + "\">" + permissionText + "</label><input type=\"radio\" id=\"" + elemId + "\" name=\"" + permissionText + "\" onclick=\"" + ControlsHelper.GetPostBackEventReference(this, permission.ToString() + ";" + Convert.ToInt32(currentAccess).ToString()) + "\" " + ((isAllowed) ? "checked = \"checked\"" : "") + ((isDisabled) ? " disabled=\"disabled\"" : "") + "/>"; newCell.Wrap = false; newCell.Width = new Unit(12, UnitType.Percentage); newCell.HorizontalAlign = HorizontalAlign.Center; newRow.Cells.Add(newCell); permissionIndex++; } newCell = new TableCell(); newCell.Text = " "; newRow.Cells.Add(newCell); // Add the access row to the table tblMatrix.Rows.Add(newRow); } } // Check if forum has some roles assigned this.mNoRolesAvailable = !gridMatrix.HasData; // Get permission matrix for current forum resource if (!this.mNoRolesAvailable) { // Security - Role separator newRow = new TableRow(); newCell = new TableCell(); newCell.Text = " "; newCell.Attributes.Add("colspan", Convert.ToString(tblMatrix.Rows[0].Cells.Count)); newRow.Controls.Add(newCell); tblMatrix.Rows.Add(newRow); // Security - Role separator text newRow = new TableRow(); newCell = new TableCell(); newCell.CssClass = "MatrixLabel"; newCell.Text = GetString("SecurityMatrix.RolesAvailability"); newCell.Attributes.Add("colspan", Convert.ToString(tblMatrix.Rows[0].Cells.Count)); newRow.Controls.Add(newCell); tblMatrix.Rows.Add(newRow); } } } }
/// <summary> /// Sets the security options for a media library. /// </summary> /// <param name="library">The specified <see cref="IMediaLibrary"/> to look for setting the security option.</param> /// <param name="option">The security option <see cref="SecurityPropertyEnum"/>.</param> /// <param name="securityAccess">The security acess enum <see cref="SecurityAccessEnum"/>.</param> public void SetMediaLibrarySecurityOption(IMediaLibrary library, SecurityPropertyEnum option, SecurityAccessEnum securityAccess) { this.MediaLibraryService.SetMediaLibrarySecurityOption(library, option, securityAccess); }
/// <summary> /// Indicates the permission acess. /// </summary> /// <param name="currentAccess">Currently processed integer representation of item from SecurityAccessEnum</param> /// <param name="currentPermission">Currently processed integer representation of permission to check</param> private bool CheckPermissionAccess(SecurityAccessEnum currentAccess, int currentPermission, string currentPermissionName) { bool result = false; if (project != null) { switch (currentPermission) { case 0: // Process 'AllowRead' permission and check by current access result = (project.AllowRead == currentAccess); break; case 1: // Set 'AttachCreate' permission and check by current access result = (project.AllowCreate == currentAccess); break; case 2: // Set 'AllowModify' permission and check by current access result = (project.AllowModify == currentAccess); break; case 3: // Set 'AllowDelete' permission and check by current access result = (project.AllowDelete == currentAccess); break; default: break; } } // Make note about type of permission with access set to 'OnlyAuthorizedRoles' if (result && (currentAccess == SecurityAccessEnum.AuthorizedRoles)) { onlyAuth[currentPermissionName] = true; } return result; }
/// <summary> /// Generates the permission matrix for the current forum. /// </summary> private void CreateMatrix() { // Get forum resource info if (resForums == null) { resForums = ResourceInfoProvider.GetResourceInfo("CMS.Forums"); } // Get forum object if ((forum == null) && (ForumID > 0)) { forum = ForumInfoProvider.GetForumInfo(ForumID); } if ((resForums != null) && (forum != null)) { // Get permissions for the current forum resource DataSet permissions = PermissionNameInfoProvider.GetResourcePermissions(resForums.ResourceID); if (DataHelper.DataSourceIsEmpty(permissions)) { ShowInformation(GetString("general.emptymatrix")); } else { TableHeaderRow headerRow = new TableHeaderRow(); headerRow.CssClass = "unigrid-head"; headerRow.TableSection = TableRowSection.TableHeader; TableCell newCell = new TableCell(); TableHeaderCell newHeaderCell = new TableHeaderCell(); newHeaderCell.CssClass = "first-column"; headerRow.Cells.Add(newHeaderCell); foreach (string permission in allowedPermissions) { DataRow[] drArray = permissions.Tables[0].DefaultView.Table.Select("PermissionName = '" + permission + "'"); if (drArray.Length > 0) { DataRow dr = drArray[0]; newHeaderCell = new TableHeaderCell(); newHeaderCell.Text = dr["PermissionDisplayName"].ToString(); newHeaderCell.ToolTip = dr["PermissionDescription"].ToString(); headerRow.Cells.Add(newHeaderCell); } else { throw new Exception("[Security matrix] Column '" + permission + "' cannot be found."); } } tblMatrix.Rows.Add(headerRow); // Render forum access permissions object[,] accessNames = new object[5, 2]; accessNames[0, 0] = GetString("security.nobody"); accessNames[0, 1] = SecurityAccessEnum.Nobody; accessNames[1, 0] = GetString("security.allusers"); accessNames[1, 1] = SecurityAccessEnum.AllUsers; accessNames[2, 0] = GetString("security.authenticated"); accessNames[2, 1] = SecurityAccessEnum.AuthenticatedUsers; accessNames[3, 0] = GetString("security.groupmembers"); accessNames[3, 1] = SecurityAccessEnum.GroupMembers; accessNames[4, 0] = GetString("security.authorizedroles"); accessNames[4, 1] = SecurityAccessEnum.AuthorizedRoles; TableRow newRow = null; for (int access = 0; access <= accessNames.GetUpperBound(0); access++) { SecurityAccessEnum currentAccess = ((SecurityAccessEnum)accessNames[access, 1]); // If the security isn't displayed as part of group section if ((currentAccess == SecurityAccessEnum.GroupMembers) && (!IsGroupForum)) { // Do not render this access item } else { // Generate cell holding access item name newRow = new TableRow(); newCell = new TableCell(); newCell.Text = accessNames[access, 0].ToString(); newCell.CssClass = "matrix-header"; newRow.Cells.Add(newCell); // Render the permissions access items bool isAllowed = false; bool isEnabled = true; int permissionIndex = 0; for (int permission = 0; permission < (tblMatrix.Rows[0].Cells.Count - 1); permission++) { newCell = new TableCell(); // Check if the currently processed access is applied for permission isAllowed = CheckPermissionAccess(currentAccess, permission, tblMatrix.Rows[0].Cells[permission + 1].Text); isEnabled = ((currentAccess != SecurityAccessEnum.AllUsers) || (permission != 1)) && Enable; // Disable column in roles grid if needed if ((currentAccess == SecurityAccessEnum.AuthorizedRoles) && !isAllowed) { gridMatrix.DisableColumn(permissionIndex); } // Insert the radio button for the current permission var radio = new CMSRadioButton { Checked = isAllowed, Enabled = isEnabled, }; radio.Attributes.Add("onclick", ControlsHelper.GetPostBackEventReference(this, permission + ";" + Convert.ToInt32(currentAccess))); newCell.Controls.Add(radio); newRow.Cells.Add(newCell); permissionIndex++; } // Add the access row to the table tblMatrix.Rows.Add(newRow); } } // Check if forum has some roles assigned headTitle.Visible = gridMatrix.HasData; } } }
/// <summary> /// Generates the permission matrix for the current library. /// </summary> private void CreateMatrix() { // Get library resource info if ((ResLibrary != null) && (LibraryInfo != null)) { // Get permissions for the current library resource DataSet permissions = PermissionNameInfoProvider.GetResourcePermissions(ResLibrary.ResourceID); if (DataHelper.DataSourceIsEmpty(permissions)) { lblInfo.ResourceString = "general.emptymatrix"; lblInfo.Visible = true; } else { TableRow headerRow = new TableRow(); headerRow.TableSection = TableRowSection.TableHeader; headerRow.CssClass = "unigrid-head"; TableHeaderCell newHeaderCell = new TableHeaderCell(); newHeaderCell.CssClass = "first-column"; headerRow.Cells.Add(newHeaderCell); DataView dv = permissions.Tables[0].DefaultView; dv.Sort = "PermissionDisplayName ASC"; // Generate header cells foreach (DataRowView drv in dv) { string permissionName = drv.Row["PermissionName"].ToString(); if (permissionArray.Contains(permissionName.ToLowerCSafe())) { newHeaderCell = new TableHeaderCell(); newHeaderCell.CssClass = "matrix-header"; newHeaderCell.Text = HTMLHelper.HTMLEncode(drv.Row["PermissionDisplayName"].ToString()); newHeaderCell.ToolTip = Convert.ToString(drv.Row["PermissionDescription"]); headerRow.Cells.Add(newHeaderCell); } } tblMatrix.Rows.Add(headerRow); // Render library access permissions object[,] accessNames = new object[5, 2]; accessNames[0, 0] = GetString("security.nobody"); accessNames[0, 1] = SecurityAccessEnum.Nobody; accessNames[1, 0] = GetString("security.allusers"); accessNames[1, 1] = SecurityAccessEnum.AllUsers; accessNames[2, 0] = GetString("security.authenticated"); accessNames[2, 1] = SecurityAccessEnum.AuthenticatedUsers; accessNames[3, 0] = GetString("security.groupmembers"); accessNames[3, 1] = SecurityAccessEnum.GroupMembers; accessNames[4, 0] = GetString("security.authorizedroles"); accessNames[4, 1] = SecurityAccessEnum.AuthorizedRoles; TableRow newRow; int rowIndex = 0; for (int access = 0; access <= accessNames.GetUpperBound(0); access++) { SecurityAccessEnum currentAccess = ((SecurityAccessEnum)accessNames[access, 1]); // If the security isn't displayed as part of group section if (((currentAccess == SecurityAccessEnum.GroupAdmin) || (currentAccess == SecurityAccessEnum.GroupMembers)) && (!(LibraryInfo.LibraryGroupID > 0))) { // Do not render this access item } else { // Generate cell holding access item name newRow = new TableRow(); TableCell newCell = new TableCell(); newCell.CssClass = "matrix-header"; newCell.Text = accessNames[access, 0].ToString(); newRow.Cells.Add(newCell); rowIndex++; // Render the permissions access items int permissionIndex = 0; for (int permission = 0; permission < (tblMatrix.Rows[0].Cells.Count - 1); permission++) { newCell = new TableCell(); int accessEnum = Convert.ToInt32(accessNames[access, 1]); // Check if the currently processed access is applied for permission bool isAllowed = CheckPermissionAccess(accessEnum, permission, tblMatrix.Rows[0].Cells[permission + 1].Text); // Disable column in roles grid if needed if ((currentAccess == SecurityAccessEnum.AuthorizedRoles) && !isAllowed) { gridMatrix.DisableColumn(permissionIndex); } // Insert the radio button for the current permission var radio = new CMSRadioButton { Checked = isAllowed, Enabled = Enable, }; radio.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(this, permission + "|" + accessEnum)); newCell.Controls.Add(radio); newRow.Cells.Add(newCell); permissionIndex++; } // Add the access row to the table tblMatrix.Rows.Add(newRow); } } // Check if media library has some roles assigned headTitle.Visible = gridMatrix.HasData; } } }
/// <summary> /// Generates the permission matrix for the cutrrent library. /// </summary> private void CreateMatrix() { // Get library resource info if ((this.ResLibrary != null) && (this.LibraryInfo != null)) { // Get permissions for the current library resource DataSet permissions = PermissionNameInfoProvider.GetResourcePermissions(this.ResLibrary.ResourceId); if (DataHelper.DataSourceIsEmpty(permissions)) { lblInfo.Text = GetString("general.emptymatrix"); lblInfo.Visible = true; } else { TableRow headerRow = new TableRow(); headerRow.CssClass = "UniGridHead"; TableCell newCell = new TableCell(); TableHeaderCell newHeaderCell = new TableHeaderCell(); newHeaderCell.Text = " "; newHeaderCell.CssClass = "MatrixHeader"; newHeaderCell.Attributes["style"] = "width:28%;"; headerRow.Cells.Add(newHeaderCell); DataView dv = permissions.Tables[0].DefaultView; dv.Sort = "PermissionDisplayName ASC"; // Generate header cells foreach (DataRowView drv in dv) { string permissionName = drv.Row["PermissionName"].ToString(); if (permissionArray.Contains(permissionName.ToLower())) { newHeaderCell = new TableHeaderCell(); newHeaderCell.CssClass = "MatrixHeader"; newHeaderCell.Attributes["style"] = "width:12%;text-align:center;white-space:nowrap;"; newHeaderCell.Text = HTMLHelper.HTMLEncode(drv.Row["PermissionDisplayName"].ToString()); newHeaderCell.ToolTip = Convert.ToString(drv.Row["PermissionDescription"]); newHeaderCell.HorizontalAlign = HorizontalAlign.Center; headerRow.Cells.Add(newHeaderCell); } } // Insert the empty cell at the end newHeaderCell = new TableHeaderCell(); newHeaderCell.Text = " "; headerRow.Cells.Add(newHeaderCell); tblMatrix.Rows.Add(headerRow); // Render library access permissions object[,] accessNames = new object[5, 2]; accessNames[0, 0] = GetString("security.nobody"); accessNames[0, 1] = SecurityAccessEnum.Nobody; accessNames[1, 0] = GetString("security.allusers"); accessNames[1, 1] = SecurityAccessEnum.AllUsers; accessNames[2, 0] = GetString("security.authenticated"); accessNames[2, 1] = SecurityAccessEnum.AuthenticatedUsers; accessNames[3, 0] = GetString("security.groupmembers"); accessNames[3, 1] = SecurityAccessEnum.GroupMembers; accessNames[4, 0] = GetString("security.authorizedroles"); accessNames[4, 1] = SecurityAccessEnum.AuthorizedRoles; TableRow newRow = null; int rowIndex = 0; for (int access = 0; access <= accessNames.GetUpperBound(0); access++) { SecurityAccessEnum currentAccess = ((SecurityAccessEnum)accessNames[access, 1]); // If the security isn't displayed as part of group section if (((currentAccess == SecurityAccessEnum.GroupAdmin) || (currentAccess == SecurityAccessEnum.GroupMembers)) && (!(this.LibraryInfo.LibraryGroupID > 0))) { // Do not render this access item } else { // Generate cell holding access item name newRow = new TableRow(); newRow.CssClass = ((rowIndex % 2 == 0) ? "EvenRow" : "OddRow"); newCell = new TableCell(); newCell.CssClass = "MatrixHeader"; newCell.Text = accessNames[access, 0].ToString(); newCell.Wrap = false; newRow.Cells.Add(newCell); rowIndex++; // Render the permissions access items int permissionIndex = 0; for (int permission = 0; permission < (tblMatrix.Rows[0].Cells.Count - 2); permission++) { newCell = new TableCell(); newCell.HorizontalAlign = HorizontalAlign.Center; int accessEnum = Convert.ToInt32(accessNames[access, 1]); // Check if the currently processed access is applied for permission bool isAllowed = CheckPermissionAccess(accessEnum, permission, tblMatrix.Rows[0].Cells[permission + 1].Text); // Disable column in roles grid if needed if ((currentAccess == SecurityAccessEnum.AuthorizedRoles) && !isAllowed) { gridMatrix.DisableColumn(permissionIndex); } // Insert the radio button for the current permission string permissionText = tblMatrix.Rows[0].Cells[permission + 1].Text; string elemId = ClientID + "_" + permission + "_" + access; newCell.Text = "<label style=\"display:none;\" for=\"" + elemId + "\">" + permissionText + "</label><input type=\"radio\" id=\"" + elemId + "\" name=\"" + permissionText + "\" " + (Enable ? "" : "disabled=\"disabled\"") + " onclick=\"" + Page.ClientScript.GetPostBackEventReference(this, permission + "|" + accessEnum) + "\" " + ((isAllowed) ? "checked = \"checked\"" : "") + "/>"; newCell.Wrap = false; newRow.Cells.Add(newCell); permissionIndex++; } newCell = new TableCell(); newCell.Text = " "; newRow.Cells.Add(newCell); // Add the access row to the table tblMatrix.Rows.Add(newRow); } } // Get permission matrix for roles of the current site/group mNoRolesAvailable = !gridMatrix.HasData; if (!this.mNoRolesAvailable) { // Security - Role separator newRow = new TableRow(); newCell = new TableCell(); newCell.Text = " "; newCell.Attributes.Add("colspan", Convert.ToString(tblMatrix.Rows[0].Cells.Count)); newRow.Controls.Add(newCell); tblMatrix.Rows.Add(newRow); // Security - Role separator text newRow = new TableRow(); newCell = new TableCell(); newCell.CssClass = "MatrixLabel"; newCell.Text = GetString("SecurityMatrix.RolesAvailability"); newCell.Attributes.Add("colspan", Convert.ToString(tblMatrix.Rows[0].Cells.Count)); newRow.Controls.Add(newCell); tblMatrix.Rows.Add(newRow); } } } }
/// <summary> /// Generates the permission matrix for the cutrrent widget. /// </summary> private void CreateMatrix() { // Get widget resource info if ((ResWidget != null) && (WidgetInfo != null)) { // Get permissions for the current widget resource DataSet permissions = PermissionNameInfoProvider.GetResourcePermissions(ResWidget.ResourceId); if (DataHelper.DataSourceIsEmpty(permissions)) { lblInfo.Text = GetString("general.emptymatrix"); } else { TableRow headerRow = new TableRow(); headerRow.CssClass = "unigrid-head"; headerRow.TableSection = TableRowSection.TableHeader; headerRow.HorizontalAlign = HorizontalAlign.Left; TableHeaderCell newHeaderCell = new TableHeaderCell(); newHeaderCell.CssClass = "first-column"; headerRow.Cells.Add(newHeaderCell); DataView dv = permissions.Tables[0].DefaultView; dv.Sort = "PermissionName ASC"; // Generate header cells foreach (DataRowView drv in dv) { string permissionName = drv.Row["PermissionName"].ToString(); if (permissionArray.Contains(permissionName.ToLowerCSafe())) { newHeaderCell = new TableHeaderCell(); newHeaderCell.CssClass = "matrix-header"; newHeaderCell.Text = HTMLHelper.HTMLEncode(drv.Row["PermissionDisplayName"].ToString()); newHeaderCell.ToolTip = Convert.ToString(drv.Row["PermissionDescription"]); headerRow.Cells.Add(newHeaderCell); } } tblMatrix.Rows.AddAt(0, headerRow); // Render widget access permissions object[,] accessNames = new object[3, 2]; //accessNames[0, 0] = GetString("security.allusers"); //accessNames[0, 1] = SecurityAccessEnum.AllUsers; accessNames[0, 0] = GetString("security.authenticated"); accessNames[0, 1] = SecurityAccessEnum.AuthenticatedUsers; accessNames[1, 0] = GetString("security.globaladmin"); accessNames[1, 1] = SecurityAccessEnum.GlobalAdmin; accessNames[2, 0] = GetString("security.authorizedroles"); accessNames[2, 1] = SecurityAccessEnum.AuthorizedRoles; TableRow newRow = null; for (int access = 0; access <= accessNames.GetUpperBound(0); access++) { SecurityAccessEnum currentAccess = ((SecurityAccessEnum)accessNames[access, 1]); // Generate cell holding access item name newRow = new TableRow(); TableCell newCell = new TableCell(); newCell.CssClass = "matrix-header"; newCell.Text = accessNames[access, 0].ToString(); newRow.Cells.Add(newCell); // Render the permissions access items int permissionIndex = 0; for (int permission = 0; permission < (tblMatrix.Rows[0].Cells.Count - 1); permission++) { newCell = new TableCell(); newCell.CssClass = "matrix-cell"; int accessEnum = Convert.ToInt32(accessNames[access, 1]); // Check if the currently processed access is applied for permission bool isAllowed = CheckPermissionAccess(accessEnum, permission, tblMatrix.Rows[0].Cells[permission + 1].Text); // Disable column in roles grid if needed if ((currentAccess == SecurityAccessEnum.AuthorizedRoles) && !isAllowed) { gridMatrix.DisableColumn(permissionIndex); } // Insert the radio button for the current permission var radio = new CMSRadioButton { Checked = isAllowed, Enabled = Enable, }; radio.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(this, permission + ";" + accessEnum)); newCell.Controls.Add(radio); newRow.Cells.Add(newCell); permissionIndex++; } tblMatrix.Rows.Add(newRow); } // Get permission matrix for roles of the current site/group mNoRolesAvailable = !gridMatrix.HasData; if (!mNoRolesAvailable) { lblRolesInfo.Visible = true; } } } }
/// <summary> /// Generates the permission matrix for the current group. /// </summary> private void CreateMatrix() { // Get group resource info if (resGroups == null) { resGroups = ResourceInfoProvider.GetResourceInfo("CMS.Groups"); } if (resGroups != null) { group = GroupInfoProvider.GetGroupInfo(GroupID); // Get permissions for the current group resource DataSet permissions = PermissionNameInfoProvider.GetResourcePermissions(resGroups.ResourceId); if (DataHelper.DataSourceIsEmpty(permissions)) { ShowInformation(GetString("general.emptymatrix")); } else { TableRow headerRow = new TableRow(); headerRow.CssClass = "UniGridHead"; TableCell newCell = new TableCell(); TableHeaderCell newHeaderCell = new TableHeaderCell(); newHeaderCell.Text = " "; newHeaderCell.CssClass = "MatrixHeader"; newHeaderCell.Attributes["style"] = "width:30%;"; headerRow.Cells.Add(newHeaderCell); foreach (string permission in allowedPermissions) { DataRow[] drArray = permissions.Tables[0].DefaultView.Table.Select("PermissionName = '" + permission + "'"); if ((drArray != null) && (drArray.Length > 0)) { DataRow dr = drArray[0]; newHeaderCell = new TableHeaderCell(); newHeaderCell.CssClass = "MatrixHeader"; newHeaderCell.Attributes["style"] = "width:18%;text-align:center;white-space:nowrap;"; newHeaderCell.Text = dr["PermissionDisplayName"].ToString(); newHeaderCell.ToolTip = dr["PermissionDescription"].ToString(); newHeaderCell.HorizontalAlign = HorizontalAlign.Center; headerRow.Cells.Add(newHeaderCell); } else { throw new Exception("[Security matrix] Column '" + permission + "' cannot be found."); } } // Insert the empty cell at the end newHeaderCell = new TableHeaderCell(); newHeaderCell.Text = " "; headerRow.Cells.Add(newHeaderCell); tblMatrix.Rows.Add(headerRow); // Render group access permissions object[,] accessNames = new object[5, 2]; accessNames[0, 0] = GetString("security.nobody"); accessNames[0, 1] = SecurityAccessEnum.Nobody; accessNames[1, 0] = GetString("security.allusers"); accessNames[1, 1] = SecurityAccessEnum.AllUsers; accessNames[2, 0] = GetString("security.authenticated"); accessNames[2, 1] = SecurityAccessEnum.AuthenticatedUsers; accessNames[3, 0] = GetString("security.groupmembers"); accessNames[3, 1] = SecurityAccessEnum.GroupMembers; accessNames[4, 0] = GetString("security.authorizedroles"); accessNames[4, 1] = SecurityAccessEnum.AuthorizedRoles; TableRow newRow = null; int rowIndex = 0; for (int access = 0; access <= accessNames.GetUpperBound(0); access++) { SecurityAccessEnum currentAccess = ((SecurityAccessEnum)accessNames[access, 1]); // Generate cell holding access item name newRow = new TableRow(); newRow.CssClass = ((rowIndex % 2 == 0) ? "EvenRow" : "OddRow"); newCell = new TableCell(); newCell.CssClass = "MatrixHeader"; newCell.Text = accessNames[access, 0].ToString(); newCell.Wrap = false; newRow.Cells.Add(newCell); rowIndex++; // Render the permissions access items bool isAllowed = false; int permissionIndex = 0; for (int permission = 0; permission < (tblMatrix.Rows[0].Cells.Count - 2); permission++) { newCell = new TableCell(); newCell.CssClass = "MatrixCell"; newCell.HorizontalAlign = HorizontalAlign.Center; // Check if the currently processed access is applied for permission isAllowed = CheckPermissionAccess(currentAccess, permission, tblMatrix.Rows[0].Cells[permission + 1].Text); // Disable column in roles grid if needed if ((currentAccess == SecurityAccessEnum.AuthorizedRoles) && !isAllowed) { gridMatrix.DisableColumn(permissionIndex); } // Insert the radio button for the current permission string permissionText = tblMatrix.Rows[0].Cells[permission + 1].Text; string elemId = ClientID + "_" + permission + "_" + access; string disabled = null; if (!Enabled) { disabled = "disabled=\"disabled\""; } newCell.Text = "<label style=\"display:none;\" for=\"" + elemId + "\">" + permissionText + "</label><input type=\"radio\" id=\"" + elemId + "\" name=\"" + permissionText + "\" " + disabled + " onclick=\"" + ControlsHelper.GetPostBackEventReference(this, permission.ToString() + ";" + Convert.ToInt32(currentAccess).ToString()) + "\" " + ((isAllowed) ? "checked = \"checked\"" : "") + "/>"; newCell.Wrap = false; newRow.Cells.Add(newCell); permissionIndex++; } newCell = new TableCell(); newCell.Text = " "; newRow.Cells.Add(newCell); // Add the access row to the table tblMatrix.Rows.Add(newRow); } // Get permission matrix for current group resource bool rowIsSeparator = false; // Get permission matrix for the current group resource mNoRolesAvailable = !gridMatrix.HasData; if (!mNoRolesAvailable) { // Security - Role separator newRow = new TableRow(); newCell = new TableCell(); newCell.Text = " "; newCell.Attributes.Add("colspan", Convert.ToString(tblMatrix.Rows[0].Cells.Count)); newRow.Controls.Add(newCell); tblMatrix.Rows.Add(newRow); // Security - Role separator text newRow = new TableRow(); newCell = new TableCell(); newCell.CssClass = "MatrixLabel"; newCell.Text = GetString("SecurityMatrix.RolesAvailability"); newCell.Attributes.Add("colspan", Convert.ToString(tblMatrix.Rows[0].Cells.Count - 1)); newRow.Controls.Add(newCell); tblMatrix.Rows.Add(newRow); } // Add the latest row if present if (newRow != null) { // The row is only role row and at the same time is divider between accesses section and roles section - make border higher if (rowIsSeparator) { rowIsSeparator = false; } if (!mNoRolesAvailable) { newRow.Cells.Add(new TableCell()); tblMatrix.Rows.Add(newRow); } } } } }
/// <summary> /// Indicates the permission acess. /// </summary> /// <param name="currentAccess">Currently processed integer representation of item from SecurityAccessEnum</param> /// <param name="currentPermission">Currently processed integer representation of permission to check</param> private bool CheckPermissionAccess(SecurityAccessEnum currentAccess, int currentPermission, string currentPermissionName) { bool result = false; if (forum != null) { switch (currentPermission) { case 0: // Process 'AccessToForum' permission and check by current access result = (forum.AllowAccess == currentAccess); break; case 1: // Process 'AttachFiles' permission and check by current access result = (forum.AllowAttachFiles == currentAccess); break; case 3: // Process 'Post' permission and check by current access result = (forum.AllowPost == currentAccess); break; case 2: // Process 'MarkAsAnswer' permission and check by current access result = (forum.AllowMarkAsAnswer == currentAccess); break; case 4: // Process 'Reply' permission and check by current access result = (forum.AllowReply == currentAccess); break; case 5: // Process 'Subscribe' permission and check by current access result = (forum.AllowSubscribe == currentAccess); break; } } // Make note about type of permission with access set to 'OnlyAuthorizedRoles' if (result && (currentAccess == SecurityAccessEnum.AuthorizedRoles)) { onlyAuth[currentPermissionName] = true; } return result; }
public void SetMediaLibrarySecurityOption(IMediaLibrary library, SecurityPropertyEnum option, SecurityAccessEnum securityAccess) { MediaLibraryMock mock = (MediaLibraryMock)library; // Get security property name from enum string propName = Enum.GetName(typeof(SecurityPropertyEnum), option); // Set security property value using reflection mock.GetType().GetProperty(propName).SetValue(library, securityAccess); }
/// <summary> /// Generates the permission matrix for the cutrrent widget. /// </summary> private void CreateMatrix() { // Get widget resource info if ((ResWidget != null) && (WidgetInfo != null)) { // Get permissions for the current widget resource DataSet permissions = PermissionNameInfoProvider.GetResourcePermissions(ResWidget.ResourceId); if (DataHelper.DataSourceIsEmpty(permissions)) { lblInfo.Text = GetString("general.emptymatrix"); } else { TableRow headerRow = new TableRow(); headerRow.CssClass = "UniGridHead"; headerRow.HorizontalAlign = HorizontalAlign.Left; TableCell newCell = null; TableHeaderCell newHeaderCell = new TableHeaderCell(); newHeaderCell.Attributes.Add("style", "width:300px; white-space: nowrap;"); headerRow.Cells.Add(newHeaderCell); DataView dv = permissions.Tables[0].DefaultView; dv.Sort = "PermissionName ASC"; // Generate header cells foreach (DataRowView drv in dv) { string permissionName = drv.Row["PermissionName"].ToString(); if (permissionArray.Contains(permissionName.ToLowerCSafe())) { newHeaderCell = new TableHeaderCell(); newHeaderCell.CssClass = "MatrixHeader"; newHeaderCell.Text = HTMLHelper.HTMLEncode(drv.Row["PermissionDisplayName"].ToString()); newHeaderCell.ToolTip = Convert.ToString(drv.Row["PermissionDescription"]); newHeaderCell.Attributes.Add("style", "text-align: center; white-space: nowrap;"); headerRow.Cells.Add(newHeaderCell); } } // Insert the empty cell at the end newHeaderCell = new TableHeaderCell(); newHeaderCell.Text = " "; headerRow.Cells.Add(newHeaderCell); tblMatrix.Rows.AddAt(0, headerRow); // Render widget access permissions object[,] accessNames = new object[3, 2]; //accessNames[0, 0] = GetString("security.allusers"); //accessNames[0, 1] = SecurityAccessEnum.AllUsers; accessNames[0, 0] = GetString("security.authenticated"); accessNames[0, 1] = SecurityAccessEnum.AuthenticatedUsers; accessNames[1, 0] = GetString("security.globaladmin"); accessNames[1, 1] = SecurityAccessEnum.GlobalAdmin; accessNames[2, 0] = GetString("security.authorizedroles"); accessNames[2, 1] = SecurityAccessEnum.AuthorizedRoles; TableRow newRow = null; for (int access = 0; access <= accessNames.GetUpperBound(0); access++) { SecurityAccessEnum currentAccess = ((SecurityAccessEnum)accessNames[access, 1]); // Generate cell holding access item name newRow = new TableRow(); newCell = new TableCell(); newCell.CssClass = "MatrixHeader"; newCell.Text = accessNames[access, 0].ToString(); newCell.Wrap = false; newCell.Width = new Unit(150, UnitType.Pixel); newRow.Cells.Add(newCell); // Render the permissions access items int permissionIndex = 0; for (int permission = 0; permission < (tblMatrix.Rows[0].Cells.Count - 2); permission++) { newCell = new TableCell(); newCell.CssClass = "MatrixCell"; newCell.Attributes.Add("style", "text-align: center; white-space: nowrap;"); int accessEnum = Convert.ToInt32(accessNames[access, 1]); // Check if the currently processed access is applied for permission bool isAllowed = CheckPermissionAccess(accessEnum, permission, tblMatrix.Rows[0].Cells[permission + 1].Text); // Disable column in roles grid if needed if ((currentAccess == SecurityAccessEnum.AuthorizedRoles) && !isAllowed) { gridMatrix.DisableColumn(permissionIndex); } // Insert the radio button for the current permission string permissionText = tblMatrix.Rows[0].Cells[permission + 1].Text; string elemId = ClientID + "_" + permission + "_" + access; newCell.Text = "<label style=\"display:none;\" for=\"" + elemId + "\">" + permissionText + "</label><input type=\"radio\" id=\"" + elemId + "\" name=\"" + permissionText + "\" onclick=\"" + Page.ClientScript.GetPostBackEventReference(this, permission + ";" + accessEnum) + "\" " + ((isAllowed) ? "checked = \"checked\"" : "") + "/>"; newRow.Cells.Add(newCell); permissionIndex++; } // Add the access row to the table newCell = new TableCell(); newRow.Cells.Add(newCell); tblMatrix.Rows.Add(newRow); } // Get permission matrix for roles of the current site/group mNoRolesAvailable = !gridMatrix.HasData; if (!mNoRolesAvailable) { lblRolesInfo.Visible = true; } } } }
/// <inheritdoc/> public void SetMediaLibrarySecurityOption(IMediaLibrary library, SecurityPropertyEnum option, SecurityAccessEnum securityAccess) { // Gets the media library var existingLibrary = GetMediaLibrary(library); if (existingLibrary != null) { // Get security property name from enum string propName = Enum.GetName(typeof(SecurityPropertyEnum), option); // Set security property value using reflection existingLibrary.GetType().GetProperty(propName).SetValue(existingLibrary, securityAccess); // Saves the updated media library to the database MediaLibraryInfoProvider.SetMediaLibraryInfo(existingLibrary); } }