Ejemplo n.º 1
0
    /// <summary>
    /// Adds permission to role. Called when the "Add permission to role" button is pressed.
    /// Expects the CreatePermission method to be run first.
    /// </summary>
    private bool AddPermissionToRole()
    {
        // Get the permission
        PermissionNameInfo permission = PermissionNameInfoProvider.GetPermissionNameInfo("MyNewPermission", "MyNewModule", null);

        // Get the role
        RoleInfo role = RoleInfoProvider.GetRoleInfo("cmsdeskadmin", SiteContext.CurrentSiteID);

        if ((permission != null) && (role != null))
        {
            // Create new role permission object
            RolePermissionInfo newRolePermission = new RolePermissionInfo();

            // Set the properties
            newRolePermission.PermissionID = permission.PermissionId;
            newRolePermission.RoleID       = role.RoleID;

            // Add permission to role
            RolePermissionInfoProvider.SetRolePermissionInfo(newRolePermission);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 2
0
        public HttpResponseMessage GetRolePermissions(int roleId = 0)
        {
            if (roleId == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new { errorMessage = "Invalid roleId" }));
            }

            try
            {
                //the relevant permissions are retrieved
                List <Object> permissions = PermissionNameInfoProvider.GetPermissionNames()
                                            .WhereIn("PermissionID", RolePermissionInfoProvider
                                                     .GetRolePermissions()
                                                     .Column("PermissionID")
                                                     .WhereEquals("RoleID", roleId))
                                            .Select(
                    row => new
                {             //puts the relevant information into a new object to represent the permission
                    PermissionId          = row.PermissionId,
                    PermissionName        = row.PermissionName,
                    PermissionDisplayName = row.PermissionDisplayName,
                    PermissionDescription = row.PermissionDescription
                }
                    )
                                            .OrderBy(role => role.PermissionDisplayName)
                                            .ToList <Object>();
                //everything is OK, the permissions are also returned
                return(Request.CreateResponse(HttpStatusCode.OK, new { permissionList = permissions }));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.ServiceUnavailable, new { errorMessage = e.Message }));
            }
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Adds role permission to media library. Called when the "Add role permission to library " button is pressed.
    /// Expects the CreateMediaLibrary method to be run first.
    /// </summary>
    private bool AddRolePermissionToLibrary()
    {
        // Get the media library
        MediaLibraryInfo mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo("MyNewLibrary", SiteContext.CurrentSiteName);

        // Get the role
        RoleInfo libraryRole = RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", SiteContext.CurrentSiteID);

        // Get the permission
        PermissionNameInfo libraryPermission = PermissionNameInfoProvider.GetPermissionNameInfo("FileCreate", "CMS.MediaLibrary", null);

        if ((mediaLibrary != null) && (libraryRole != null) && (libraryPermission != null))
        {
            // Create a new media library role permision info
            MediaLibraryRolePermissionInfo rolePermission = new MediaLibraryRolePermissionInfo();

            // Set the values
            rolePermission.LibraryID    = mediaLibrary.LibraryID;
            rolePermission.RoleID       = libraryRole.RoleID;
            rolePermission.PermissionID = libraryPermission.PermissionId;

            // Add role permission to media library
            MediaLibraryRolePermissionInfoProvider.SetMediaLibraryRolePermissionInfo(rolePermission);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 4
0
    public static bool DeletePermission(string permissionName, string resourceName)
    {
        PermissionNameInfo deletePermission = PermissionNameInfoProvider.GetPermissionNameInfo(permissionName, resourceName, null);

        PermissionNameInfoProvider.DeletePermissionInfo(deletePermission);
        return(deletePermission != null);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Gets and bulk updates permissions. Called when the "Get and bulk update permissions" button is pressed.
    /// Expects the CreatePermission method to be run first.
    /// </summary>
    private bool GetAndBulkUpdatePermissions()
    {
        // Prepare the parameters
        string where = "PermissionName LIKE N'MyNewPermission%'";

        // Get the data
        DataSet permissions = PermissionNameInfoProvider.GetPermissionNames(where, null, 0, null);

        if (!DataHelper.DataSourceIsEmpty(permissions))
        {
            // Loop through the individual items
            foreach (DataRow permissionDr in permissions.Tables[0].Rows)
            {
                // Create object from DataRow
                PermissionNameInfo modifyPermission = new PermissionNameInfo(permissionDr);

                // Update the properties
                modifyPermission.PermissionDisplayName = modifyPermission.PermissionDisplayName.ToUpper();

                // Save the changes
                PermissionNameInfoProvider.SetPermissionInfo(modifyPermission);
            }

            return(true);
        }

        return(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        mPermissionId    = QueryHelper.GetInteger("permissionid", 0);
        mResourceId      = QueryHelper.GetInteger("moduleid", 0);
        mHideBreadcrumbs = QueryHelper.GetBoolean("hidebreadcrumbs", false);

        string[,] breadcrumbs = new string[2, 3];

        if (mPermissionId > 0)
        {
            mCurrentPermission = PermissionNameInfoProvider.GetPermissionNameInfo(mPermissionId);
            EditedObject       = mCurrentPermission;

            if (!RequestHelper.IsPostBack())
            {
                if (mCurrentPermission != null)
                {
                    tbPermissionCodeName.Text            = mCurrentPermission.PermissionName;
                    tbPermissionDisplayName.Text         = mCurrentPermission.PermissionDisplayName;
                    txtPermissionDescription.Text        = mCurrentPermission.PermissionDescription;
                    chkPermissionDisplayInMatrix.Checked = mCurrentPermission.PermissionDisplayInMatrix;
                    chkGlobalAdmin.Checked = mCurrentPermission.PermissionEditableByGlobalAdmin;
                }

                // shows that the permission was created or updated successfully
                if (QueryHelper.GetBoolean("saved", false))
                {
                    // Show message
                    ShowChangesSaved();
                }
            }

            if (mCurrentPermission != null)
            {
                mPermissionName = mCurrentPermission.PermissionDisplayName;
            }
        }
        else
        {
            mPermissionName = GetString("Module_Edit_PermissionName_Edit.NewPermission");
        }

        if (!mHideBreadcrumbs)
        {
            breadcrumbs[0, 0] = GetString("Administration-Module_Edit.PermissionNames");
            breadcrumbs[0, 1] = "~/CMSModules/Modules/Pages/Development/Module_Edit_PermissionNames.aspx?hidebreadcrumbs=" + (mHideBreadcrumbs ? "1" : "0") + "&moduleID=" + mResourceId;
            breadcrumbs[0, 2] = "";
            breadcrumbs[1, 0] = mPermissionName;
            breadcrumbs[1, 1] = "";
            breadcrumbs[1, 2] = "";
            CurrentMaster.Title.Breadcrumbs = breadcrumbs;
        }

        CurrentMaster.Title.HelpTopicName = "resource_permission_new";

        rfvPermissionDisplayName.ErrorMessage = GetString("Administration-Module_Edit_PermissionName_Edit.ErrorEmptyPermissionDisplayName");
        rfvPermissionCodeName.ErrorMessage    = GetString("Administration-Module_Edit_PermissionName_Edit.ErrorEmptyPermissionCodeName");
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Deletes permission. Called when the "Delete permission" button is pressed.
    /// Expects the CreatePermission method to be run first.
    /// </summary>
    private bool DeletePermission()
    {
        // Get the permission
        PermissionNameInfo deletePermission = PermissionNameInfoProvider.GetPermissionNameInfo("MyNewPermission", "MyNewModule", null);

        // Delete the permission
        PermissionNameInfoProvider.DeletePermissionInfo(deletePermission);

        return(deletePermission != null);
    }
    protected bool gridMatrix_CheckPermissions(object permId)
    {
        int permissionId = ValidationHelper.GetInteger(permId, 0);

        // Check how the permission can be edited
        PermissionNameInfo pni = PermissionNameInfoProvider.GetPermissionNameInfo(permissionId);

        if (pni != null)
        {
            return(currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin) || !pni.PermissionEditableByGlobalAdmin);
        }

        return(true);
    }
Ejemplo n.º 9
0
    public static bool CreatePermission(string displayName, string Name, string resourceName)
    {
        ResourceInfo module = ResourceInfoProvider.GetResourceInfo(resourceName);

        if (module != null)
        {
            PermissionNameInfo newPermission = new PermissionNameInfo();
            newPermission.PermissionDisplayName = displayName;
            newPermission.PermissionName        = Name;
            newPermission.ResourceId            = module.ResourceId;
            PermissionNameInfoProvider.SetPermissionInfo(newPermission);
            return(true);
        }
        return(false);
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Removes authorized role to project. Called when the "Remove authorized role" button is pressed.
    /// Expects the CreateProject and AddAuthorizedRole methods to be run first.
    /// </summary>
    private bool RemoveAuthorizedRole()
    {
        // Get the project
        ProjectInfo        project    = ProjectInfoProvider.GetProjectInfo("MyNewProject", SiteContext.CurrentSiteID, 0);
        RoleInfo           role       = RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", SiteContext.CurrentSiteID);
        PermissionNameInfo permission = PermissionNameInfoProvider.GetPermissionNameInfo("AccessToProject", "ProjectManagement", null);

        if ((project != null) && (role != null) && (permission != null))
        {
            // Remove relationship
            ProjectRolePermissionInfoProvider.RemoveRelationship(project.ProjectID, role.RoleID, permission.PermissionId);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Remove widget from role. Called when the "Remove widget to role" button is pressed.
    /// Expects the CreateWidget method to be run first.
    /// </summary>
    private bool RemoveWidgetFromRole()
    {
        // Get role, widget and permission object
        RoleInfo           role       = RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", SiteContext.CurrentSiteID);
        WidgetInfo         widget     = WidgetInfoProvider.GetWidgetInfo("MyNewWidget");
        PermissionNameInfo permission = PermissionNameInfoProvider.GetPermissionNameInfo("AllowedFor", "Widgets", null);

        // If all exist
        if ((role != null) && (widget != null) && (permission != null))
        {
            // Add widget to role
            WidgetRoleInfoProvider.RemoveRoleFromWidget(role.RoleID, widget.WidgetID, permission.PermissionId);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Gets and updates permission. Called when the "Get and update permission" button is pressed.
    /// Expects the CreatePermission method to be run first.
    /// </summary>
    private bool GetAndUpdatePermission()
    {
        // Get the permission
        PermissionNameInfo updatePermission = PermissionNameInfoProvider.GetPermissionNameInfo("MyNewPermission", "MyNewModule", null);

        if (updatePermission != null)
        {
            // Update the properties
            updatePermission.PermissionDisplayName = updatePermission.PermissionDisplayName.ToLower();

            // Save the changes
            PermissionNameInfoProvider.SetPermissionInfo(updatePermission);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 13
0
 /// <summary>
 /// Handles the UniGrid's OnAction event.
 /// </summary>
 /// <param name="actionName">Name of item (button) that threw event</param>
 /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
 protected void UniGridPermissionList_OnAction(string actionName, object actionArgument)
 {
     if (actionName == "edit")
     {
         URLHelper.Redirect(string.Format(@"Module_Edit_PermissionName_Edit_Frameset.aspx?moduleId={0}&permissionId={1}", this.mModuleId, actionArgument));
     }
     else if (actionName == "delete")
     {
         PermissionNameInfoProvider.DeletePermissionInfo(ValidationHelper.GetInteger(actionArgument, 0));
     }
     else if (actionName == "moveup")
     {
         PermissionNameInfoProvider.MovePermissionUp(ValidationHelper.GetInteger(actionArgument, 0));
     }
     else if (actionName == "movedown")
     {
         PermissionNameInfoProvider.MovePermissionDown(ValidationHelper.GetInteger(actionArgument, 0));
     }
 }
Ejemplo n.º 14
0
    /// <summary>
    /// Removes permission from role. Called when the "Remove permission from role" button is pressed.
    /// Expects the AddPermissionToRole method to be run first.
    /// </summary>
    private bool RemovePermissionFromRole()
    {
        // Get the permission
        PermissionNameInfo permission = PermissionNameInfoProvider.GetPermissionNameInfo("MyNewPermission", "MyNewModule", null);

        // Get the role
        RoleInfo role = RoleInfoProvider.GetRoleInfo("cmsdeskadmin", SiteContext.CurrentSiteID);

        if ((permission != null) && (role != null))
        {
            // Get the role permission
            RolePermissionInfo deleteRolePermission = RolePermissionInfoProvider.GetRolePermissionInfo(role.RoleID, permission.PermissionId);

            // Remove permission from role
            RolePermissionInfoProvider.DeleteRolePermissionInfo(deleteRolePermission);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Removes role permission from media library. Called when the "Remove role permission from library" button is pressed.
    /// Expects the AddRolePermissionToLibrary method to be run first.
    /// </summary>
    private bool RemoveRolePermissionFromLibrary()
    {
        // Get the media library
        MediaLibraryInfo mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo("MyNewLibrary", SiteContext.CurrentSiteName);

        // Get the role
        RoleInfo libraryRole = RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", SiteContext.CurrentSiteID);

        // Get the permission
        PermissionNameInfo libraryPermission = PermissionNameInfoProvider.GetPermissionNameInfo("FileCreate", "CMS.MediaLibrary", null);

        if ((mediaLibrary != null) && (libraryRole != null) && (libraryPermission != null))
        {
            // Get media library role permission info
            MediaLibraryRolePermissionInfo rolePermission = MediaLibraryRolePermissionInfoProvider.GetMediaLibraryRolePermissionInfo(mediaLibrary.LibraryID, libraryRole.RoleID, libraryPermission.PermissionId);

            // Remove role permission from media library
            MediaLibraryRolePermissionInfoProvider.DeleteMediaLibraryRolePermissionInfo(rolePermission);

            return(rolePermission != null);
        }

        return(false);
    }
Ejemplo n.º 16
0
 public HttpResponseMessage GetAllPermissions()
 {
     try
     {
         List <Object> permissions = PermissionNameInfoProvider.GetPermissionNames()
                                     .Select( //the relevant permission information are retrieved into a new object
             row => new
         {
             PermissionId          = row.PermissionId,
             PermissionName        = row.PermissionName,
             PermissionDisplayName = row.PermissionDisplayName,
             PermissionDescription = row.PermissionDescription
         }
             )
                                     .OrderBy(role => role.PermissionDisplayName)
                                     .ToList <Object>();
         //everything is OK, the permissions are also returned
         return(Request.CreateResponse(HttpStatusCode.OK, new { permissionList = permissions }));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.ServiceUnavailable, new { errorMessage = e.Message }));
     }
 }
    /// <summary>
    /// Gets breadcrumbs.
    /// </summary>
    /// <returns>Two dimensional string array for breadcrumbs.</returns>
    private string[,] GetTitleTabs()
    {
        string[,] pageTitleTabs = new string[2, 3];

        string permName = "";

        // Get current permission display name
        PermissionNameInfo permInfo = PermissionNameInfoProvider.GetPermissionNameInfo(this.mPermissionId);

        if (permInfo != null)
        {
            permName = permInfo.PermissionDisplayName;
        }

        pageTitleTabs[0, 0] = GetString("Administration-Module_Edit.PermissionNames");
        pageTitleTabs[0, 1] = "~/CMSModules/Modules/Pages/Development/Module_Edit_PermissionNames.aspx?moduleId=" + this.mModuleId;
        pageTitleTabs[0, 2] = "content";

        pageTitleTabs[1, 0] = ResHelper.LocalizeString(permName);
        pageTitleTabs[1, 1] = "";
        pageTitleTabs[1, 2] = "";

        return(pageTitleTabs);
    }
Ejemplo n.º 18
0
    /// <summary>
    /// Creates permission. Called when the "Create permission" button is pressed.
    /// Expects the CreateModule method to be run first.
    /// </summary>
    private bool CreatePermission()
    {
        // Get the resource
        ResourceInfo module = ResourceInfoProvider.GetResourceInfo("MyNewModule");

        if (module != null)
        {
            // Create new permission object
            PermissionNameInfo newPermission = new PermissionNameInfo();

            // Set the properties
            newPermission.PermissionDisplayName     = "My new permission";
            newPermission.PermissionName            = "MyNewPermission";
            newPermission.ResourceId                = module.ResourceId;
            newPermission.PermissionDisplayInMatrix = true;

            // Save the permission
            PermissionNameInfoProvider.SetPermissionInfo(newPermission);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 19
0
    /// <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;
            }
        }
    }
Ejemplo n.º 20
0
    /// <summary>
    /// PreRender action on which security settings are set.
    /// </summary>
    private void Page_PreRender(object sender, EventArgs e)
    {
        if ((Form == null) || !mDocumentSaved)
        {
            return;
        }

        TreeNode editedNode = Form.EditedObject as TreeNode;

        // Create or rebuild department content index
        CreateDepartmentContentSearchIndex(editedNode);

        if ((editedNode == null) || !editedNode.NodeIsACLOwner)
        {
            return;
        }

        ForumInfo        fi = ForumInfoProvider.GetForumInfo("Default_department_" + editedNode.NodeGUID, SiteContext.CurrentSiteID);
        MediaLibraryInfo mi = MediaLibraryInfoProvider.GetMediaLibraryInfo("Department_" + editedNode.NodeGUID, SiteContext.CurrentSiteName);

        // Check if forum of media library exists
        if ((fi == null) && (mi == null))
        {
            return;
        }

        // Get allowed roles ID
        int     aclID     = ValidationHelper.GetInteger(editedNode.GetValue("NodeACLID"), 0);
        DataSet listRoles = AclItemInfoProvider.GetAllowedRoles(aclID, NodePermissionsEnum.Read, "RoleID");
        string  roleIDs   = null;

        if (!DataHelper.DataSourceIsEmpty(listRoles))
        {
            IList <string> roles = DataHelper.GetStringValues(listRoles.Tables[0], "RoleID");
            roleIDs = TextHelper.Join(";", roles);
        }

        // Set permissions for forum
        if (fi != null)
        {
            // Get resource object
            ResourceInfo resForums = ResourceInfoProvider.GetResourceInfo("CMS.Forums");

            // Get permissions IDs
            DataSet dsForumPerm      = PermissionNameInfoProvider.GetPermissionNames("ResourceID = " + resForums.ResourceID + " AND (PermissionName != '" + CMSAdminControl.PERMISSION_READ + "' AND PermissionName != '" + CMSAdminControl.PERMISSION_MODIFY + "')", null, 0, "PermissionID");
            string  forumPermissions = null;
            if (!DataHelper.DataSourceIsEmpty(dsForumPerm))
            {
                foreach (DataRow drForumPerm in dsForumPerm.Tables[0].Rows)
                {
                    forumPermissions += drForumPerm["PermissionID"] + ";";
                }
                forumPermissions = forumPermissions.TrimEnd(';');
            }

            // Delete old permissions apart attach file permission
            ForumRoleInfoProvider.DeleteAllRoles("ForumID = " + fi.ForumID + " AND PermissionID IN (" + forumPermissions.Replace(";", ", ") + ")");

            // Set forum permissions
            ForumRoleInfoProvider.SetPermissions(fi.ForumID, roleIDs, forumPermissions);

            // Log staging task
            SynchronizationHelper.LogObjectChange(fi, TaskTypeEnum.UpdateObject);
        }

        // Set permissions for media library
        if (mi == null)
        {
            return;
        }

        // Get resource object
        ResourceInfo resMediaLibs = ResourceInfoProvider.GetResourceInfo("CMS.MediaLibrary");

        // Get permissions IDs
        DataSet dsMediaLibPerm      = PermissionNameInfoProvider.GetPermissionNames("ResourceID = " + resMediaLibs.ResourceID + " AND (PermissionName = 'LibraryAccess' OR PermissionName = 'FileCreate')", null, 0, "PermissionID");
        string  mediaLibPermissions = null;

        if (!DataHelper.DataSourceIsEmpty(dsMediaLibPerm))
        {
            foreach (DataRow drMediaLibPerm in dsMediaLibPerm.Tables[0].Rows)
            {
                mediaLibPermissions += drMediaLibPerm["PermissionID"] + ";";
            }
            mediaLibPermissions = mediaLibPermissions.TrimEnd(';');
        }

        // Delete old permissions only for Create file and See library content permissions
        MediaLibraryRolePermissionInfoProvider.DeleteAllRoles("LibraryID = " + mi.LibraryID + " AND PermissionID IN (" + mediaLibPermissions.Replace(";", ", ") + ")");

        // Set media library permissions
        MediaLibraryRolePermissionInfoProvider.SetPermissions(mi.LibraryID, roleIDs, mediaLibPermissions);

        // Log staging task
        SynchronizationHelper.LogObjectChange(mi, TaskTypeEnum.UpdateObject);
    }
Ejemplo n.º 21
0
    /// <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;
                }
            }
        }
    }
Ejemplo n.º 22
0
    /// <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 = "&nbsp;";
                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 = "&nbsp;";
                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 = "&nbsp;";
                        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 = "&nbsp;";
                    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 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>
    /// Handles btnOK's OnClick event - Update or save permission info.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Finds whether required fields are not empty
        string result = new Validator().NotEmpty(tbPermissionDisplayName.Text.Trim(), GetString("Administration-Module_Edit_PermissionName_Edit.ErrorEmptyPermissionDisplayName")).NotEmpty(tbPermissionCodeName.Text.Trim(), GetString("Administration-Module_Edit_PermissionName_Edit.ErrorEmptyPermissionCodeName"))
                        .IsCodeName(tbPermissionCodeName.Text.Trim(), GetString("general.invalidcodename")).Result;

        if (result == "")
        {
            int resourceId = QueryHelper.GetInteger("moduleid", 0);
            if ((resourceId <= 0) && (mCurrentPermission != null))
            {
                resourceId = mCurrentPermission.ResourceId;
            }

            string resourceName = "";

            ResourceInfo ri = ResourceInfoProvider.GetResourceInfo(resourceId);
            if (ri != null)
            {
                resourceName = ri.ResourceName;
            }

            PermissionNameInfo pni = PermissionNameInfoProvider.GetPermissionNameInfo(tbPermissionCodeName.Text.Trim(), resourceName, null);

            if ((pni == null) || (pni.PermissionId == mPermissionId))
            {
                if (pni == null)
                {
                    pni = PermissionNameInfoProvider.GetPermissionNameInfo(mPermissionId);
                    if (pni == null)
                    {
                        pni = new PermissionNameInfo();
                    }
                }

                pni.PermissionName            = tbPermissionCodeName.Text.Trim();
                pni.PermissionDisplayName     = tbPermissionDisplayName.Text.Trim();
                pni.PermissionDescription     = txtPermissionDescription.Text.Trim();
                pni.PermissionDisplayInMatrix = chkPermissionDisplayInMatrix.Checked;
                pni.ClassId    = 0;
                pni.ResourceId = resourceId;
                pni.PermissionEditableByGlobalAdmin = chkGlobalAdmin.Checked;

                if (pni.PermissionOrder == 0)
                {
                    pni.PermissionOrder = PermissionNameInfoProvider.GetLastPermissionOrder(0, resourceId) + 1;
                }

                // Update or save permission info
                PermissionNameInfoProvider.SetPermissionInfo(pni);

                // Redirect to edit page if editing existing permission
                if (mPermissionId > 0)
                {
                    URLHelper.Redirect("Module_Edit_PermissionName_Edit.aspx?moduleID=" + pni.ResourceId + "&permissionID=" + pni.PermissionId + "&saved=1&hidebreadcrumbs=" + (mHideBreadcrumbs ? "1" : "0"));
                }
                // Redirect to whole frameset if creating new
                else
                {
                    URLHelper.Redirect(string.Format(@"Module_Edit_PermissionName_Edit_Frameset.aspx?moduleId={0}&permissionId={1}&saved=1", pni.ResourceId, pni.PermissionId));
                }
            }
            else
            {
                // Show error message
                ShowError(GetString("Administration-Module_Edit_PermissionName_Edit.UniqueCodeName"));
            }
        }
        else
        {
            // Show error message
            ShowError(result);
        }
    }
Ejemplo n.º 25
0
    /// <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                = "&nbsp;";
                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 = "&nbsp;";
                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 = "&nbsp;";
                    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 = "&nbsp;";
                    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);
                    }
                }
            }
        }
    }
Ejemplo n.º 26
0
    /// <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                = "&nbsp;";
                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 = "&nbsp;";
                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 = "&nbsp;";
                        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 = "&nbsp;";
                    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>
    /// PreRender action on which security settings are set.
    /// </summary>
    private void Page_PreRender(object sender, EventArgs e)
    {
        if ((Form == null) || !mDocumentSaved)
        {
            return;
        }

        TreeNode editedNode = Form.EditedObject as TreeNode;

        // Create or rebuild department content index
        CreateDepartmentContentSearchIndex(editedNode);

        if ((editedNode == null) || !editedNode.NodeIsACLOwner)
        {
            return;
        }

        ForumInfo        fi = ForumInfoProvider.GetForumInfo("Default_department_" + editedNode.NodeGUID, SiteContext.CurrentSiteID);
        MediaLibraryInfo mi = MediaLibraryInfoProvider.GetMediaLibraryInfo("Department_" + editedNode.NodeGUID, SiteContext.CurrentSiteName);

        // Check if forum of media library exists
        if ((fi == null) && (mi == null))
        {
            return;
        }

        // Get allowed roles ID
        int         aclID     = ValidationHelper.GetInteger(editedNode.GetValue("NodeACLID"), 0);
        DataSet     listRoles = AclItemInfoProvider.GetAllowedRoles(aclID, NodePermissionsEnum.Read, "RoleID");
        IList <int> roleIds   = null;


        if (!DataHelper.DataSourceIsEmpty(listRoles))
        {
            roleIds = DataHelper.GetIntegerValues(listRoles.Tables[0], "RoleID") as List <int>;
        }

        // Set permissions for forum
        if (fi != null)
        {
            // Get resource object
            ResourceInfo resForums = ResourceInfoProvider.GetResourceInfo("CMS.Forums");

            // Get permissions IDs
            var forumPermissions = PermissionNameInfoProvider.GetPermissionNames()
                                   .Column("PermissionID")
                                   .WhereEquals("ResourceID", resForums.ResourceID)
                                   .WhereNotEquals("PermissionName", CMSAdminControl.PERMISSION_READ)
                                   .WhereNotEquals("PermissionName", CMSAdminControl.PERMISSION_MODIFY);

            // Delete old permissions apart attach file permission
            ForumRoleInfoProvider.DeleteAllRoles(new WhereCondition().WhereEquals("ForumID", fi.ForumID).WhereIn("PermissionID", forumPermissions));

            // Set forum permissions
            ForumRoleInfoProvider.SetPermissions(fi.ForumID, roleIds, forumPermissions.Select(p => p.PermissionId).ToArray());

            // Log staging task
            SynchronizationHelper.LogObjectChange(fi, TaskTypeEnum.UpdateObject);
        }

        // Set permissions for media library
        if (mi == null)
        {
            return;
        }

        // Get resource object
        ResourceInfo resMediaLibs = ResourceInfoProvider.GetResourceInfo("CMS.MediaLibrary");

        // Get permissions IDs
        var where = new WhereCondition()
                    .WhereEquals("ResourceID", resMediaLibs.ResourceID)
                    .And()
                    .Where(new WhereCondition()
                           .WhereEquals("PermissionName", "LibraryAccess")
                           .Or()
                           .WhereEquals("PermissionName", "FileCreate"));

        DataSet     dsMediaLibPerm         = PermissionNameInfoProvider.GetPermissionNames().Where(where).Column("PermissionID");
        IList <int> mediaLibPermissionsIds = null;

        if (!DataHelper.DataSourceIsEmpty(dsMediaLibPerm))
        {
            mediaLibPermissionsIds = DataHelper.GetIntegerValues(dsMediaLibPerm.Tables[0], "PermissionID");
        }

        var deleteWhere = new WhereCondition()
                          .WhereEquals("LibraryID", mi.LibraryID)
                          .WhereIn("PermissionID", mediaLibPermissionsIds);

        // Delete old permissions only for Create file and See library content permissions
        MediaLibraryRolePermissionInfoProvider.DeleteAllRoles(deleteWhere.ToString(true));

        MediaLibraryRolePermissionInfoProvider.SetPermissions(mi.LibraryID, roleIds, mediaLibPermissionsIds);

        // Log staging task;
        SynchronizationHelper.LogObjectChange(mi, TaskTypeEnum.UpdateObject);
    }
Ejemplo n.º 28
0
    /// <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 = "&#160;";
                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;
                }
            }
        }
    }