Example #1
0
    /// <summary>
    /// Expects the "CreateDocumentStructure" method to be run first.
    /// </summary>
    private bool SetRolePermissions()
    {
        // Create an instance of the Tree provider
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Get default culture code
        string culture = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSDefaultCultureCode");

        // Get the API Example document
        TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example", culture);

        if (node != null)
        {
            // Get the role ID
            RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", CMSContext.CurrentSiteName);

            if (role != null)
            {
                // Prepare allowed / denied permissions
                int allowed = 0;
                int denied  = 0;
                allowed += Convert.ToInt32(Math.Pow(2, Convert.ToInt32(NodePermissionsEnum.Modify)));

                // Create an instance of ACL provider
                AclProvider acl = new AclProvider(tree);

                // Set role permissions
                acl.SetRolePermissions(node, allowed, denied, role.RoleID);

                return(true);
            }
        }

        return(false);
    }
Example #2
0
    /// <summary>
    /// Expects the "CreateDocumentStructure" method to be run first.
    /// </summary>
    private bool SetRolePermissions()
    {
        // Create an instance of the Tree provider
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Get default culture code
        string culture = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSDefaultCultureCode");

        // Get the API Example document
        TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example", culture);

        if (node != null)
        {
            // Get the role ID
            RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSEditor", CMSContext.CurrentSiteName);

            if (role != null)
            {
                // Prepare allowed / denied permissions
                int allowed = 0;
                int denied = 0;
                allowed += Convert.ToInt32(Math.Pow(2, Convert.ToInt32(NodePermissionsEnum.Modify)));

                // Create an instance of ACL provider
                AclProvider acl = new AclProvider(tree);

                // Set role permissions
                acl.SetRolePermissions(node, allowed, denied, role.RoleID);

                return true;
            }
        }

        return false;
    }
Example #3
0
    public void Save()
    {
        CheckPermissions(true);

        int    allowed    = 0;
        int    denied     = 0;
        string operatorID = null;

        if (lstOperators.SelectedItem == null)
        {
            return;
        }
        else
        {
            operatorID = lstOperators.SelectedValue;
            allowed   += GetCheckBoxValue(chkReadAllow, NodePermissionsEnum.Read);
            allowed   += GetCheckBoxValue(chkModifyAllow, NodePermissionsEnum.Modify);
            allowed   += GetCheckBoxValue(chkCreateAllow, NodePermissionsEnum.Create);
            allowed   += GetCheckBoxValue(chkDeleteAllow, NodePermissionsEnum.Delete);
            allowed   += GetCheckBoxValue(chkDestroyAllow, NodePermissionsEnum.Destroy);
            allowed   += GetCheckBoxValue(chkExploreTreeAllow, NodePermissionsEnum.ExploreTree);
            allowed   += GetCheckBoxValue(chkManagePermissionsAllow, NodePermissionsEnum.ModifyPermissions);
            denied    += GetCheckBoxValue(chkReadDeny, NodePermissionsEnum.Read);
            denied    += GetCheckBoxValue(chkModifyDeny, NodePermissionsEnum.Modify);
            denied    += GetCheckBoxValue(chkCreateDeny, NodePermissionsEnum.Create);
            denied    += GetCheckBoxValue(chkDeleteDeny, NodePermissionsEnum.Delete);
            denied    += GetCheckBoxValue(chkDestroyDeny, NodePermissionsEnum.Destroy);
            denied    += GetCheckBoxValue(chkExploreTreeDeny, NodePermissionsEnum.ExploreTree);
            denied    += GetCheckBoxValue(chkManagePermissionsDeny, NodePermissionsEnum.ModifyPermissions);

            string message      = null;
            string operatorName = lstOperators.SelectedItem.Text;
            if (operatorID.StartsWith("U"))
            {
                int      userId = int.Parse(operatorID.Substring(1));
                UserInfo ui     = UserInfoProvider.GetUserInfo(userId);
                AclProvider.SetUserPermissions(Node, allowed, denied, ui);
                message = "security.documentuserpermissionschange";
            }
            else
            {
                AclProvider.SetRolePermissions(Node, allowed, denied, int.Parse(operatorID.Substring(1)));
                message = "security.documentrolepermissionschange";
            }
            lblInfo.Text = GetString("general.changessaved");
            // Log synchronization task and flush cache
            DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, Node.TreeProvider);
            CacheHelper.TouchKeys(TreeProvider.GetDependencyCacheKeys(Node, Node.NodeSiteName));

            // Insert information about this event to eventlog.
            if (Tree.LogEvents)
            {
                EventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DOCPERMISSIONSMODIFIED", Tree.UserInfo.UserID, Tree.UserInfo.UserName, Node.NodeID, DocumentName, ipAddress, string.Format(ResHelper.GetAPIString(message, "Permissions of the operator '{0}' have been modified for the document."), operatorName), Node.NodeSiteID, eventUrl);
            }
        }

        if (Node != null)
        {
            // Invalidate permission data in current request
            TreeSecurityProvider.InvalidateTreeNodeAuthorizationResults(CMSContext.CurrentUser, NodeID, Node.DocumentCulture);
            AclProvider.InvalidateACLItems(CMSContext.CurrentUser.UserID, Node);
        }
        CheckPermissions(false, true);
        pnlUpdate.Update();
    }