Exemplo n.º 1
0
    /// <summary>
    /// Expects the "CreateDocumentStructure" method to be run first.
    /// </summary>
    private bool SetUserPermissions()
    {
        // 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 user
            UserInfo user = UserInfoProvider.GetUserInfo("Andy");

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

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

                // Set user permissions
                acl.SetUserPermissions(node, allowed, denied, user);

                return(true);
            }
        }

        return(false);
    }
        internal static Boolean cloneNode(TreeProvider tp, CMS.DocumentEngine.TreeNode nodeToClone, CMS.DocumentEngine.TreeNode destinationNode, string action)
        {
            if (action == null) action = "0";
            bool includeChildNodes = (action == "1" || action == "3");
            bool includeAssociations = (action == "2" || action == "3");
            if ((tp != null) && (nodeToClone != null) && (destinationNode != null))
            {
                CMS.DocumentEngine.TreeNode newTreeNode = DocumentHelper.CopyDocument(nodeToClone, destinationNode.NodeID, false, tp);
                
                if (newTreeNode != null)
                {                    
                    //Remove Average Rating and Review count from the New Document
                    //US15667
                    if (IsShared == "true")
                    {
                        int allowUser = Convert.ToInt32(Math.Pow(2, Convert.ToInt32(NodePermissionsEnum.Delete))) + Convert.ToInt32(Math.Pow(2, Convert.ToInt32(NodePermissionsEnum.Read)));
                        int deniedUser = Convert.ToInt32(Math.Pow(2, Convert.ToInt32(NodePermissionsEnum.Modify))) + Convert.ToInt32(Math.Pow(2, Convert.ToInt32(NodePermissionsEnum.ModifyPermissions)));
                        AclProvider aclUser = new AclProvider(tp);
                        aclUser.SetUserPermissions(newTreeNode, allowUser, deniedUser, theSharedUserRoles);
                    }

                    UpdateRatingAvgNCountsInKenticoDB(newTreeNode.NodeID);
                    
                    //Copy the parent node associations
                    if (includeAssociations)
                        CopyDocumentPlanAssociationDetails(nodeToClone.NodeID, newTreeNode.NodeID);

                    if (includeChildNodes)
                    {
                        DataSet nodeToClone_DS = tp.SelectNodes(CMSContext.CurrentSiteName, nodeToClone.NodeAliasPath + "/%", "en-us", false, null, null, null, 1);
                        if (nodeToClone_DS != null && nodeToClone_DS.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow row in nodeToClone_DS.Tables[0].Rows)
                            {
                                int src = (int) row["NodeId"];
                                CMS.DocumentEngine.TreeNode childNode = DocumentHelper.GetDocument(src, "en-us", tp);
                                if (childNode["ExpirationDate"] != null)
                                {
                                    DateTime expirationDate = Convert.ToDateTime(childNode["ExpirationDate"]);
                                    if (expirationDate.Date < DateTime.Today) continue;
                                }
                                
                                cloneNode(tp, childNode, newTreeNode, action);                                
                            }
                        }
                        }
                    }

                return true;
            }
            return false;
        }
Exemplo n.º 3
0
    /// <summary>
    /// Expects the "CreateDocumentStructure" method to be run first.
    /// </summary>
    private bool SetUserPermissions()
    {
        // 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 user
            UserInfo user = UserInfoProvider.GetUserInfo("Andy");

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

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

                // Set user permissions
                acl.SetUserPermissions(node, allowed, denied, user);

                return true;
            }
        }

        return false;
    }
Exemplo n.º 4
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();
    }