Esempio n. 1
0
    /// <summary>
    /// After node created, solver role permissions.
    /// </summary>
    private void AddRoles(object sender, EventArgs e)
    {
        var    tree    = new TreeProvider(MembershipContext.AuthenticatedUser);
        string roleIds = ";" + usRoles.Value + ";";

        // Check if ACL should inherit from parent
        if (InheritParentPermissions)
        {
            AclInfoProvider.EnsureOwnAcl(EditedNode);
        }
        else
        {
            // If node has already own ACL don't leave permissions, otherwise break inheritance
            if (!EditedNode.NodeIsACLOwner)
            {
                AclInfoProvider.BreakInheritance(EditedNode, false);
                var breakInheritanceNode = tree.SelectSingleNode(EditedNode.NodeID);
                DocumentSynchronizationHelper.LogDocumentChange(breakInheritanceNode, TaskTypeEnum.BreakACLInheritance, tree, SynchronizationInfoProvider.ENABLED_SERVERS, null, tree.AllowAsyncActions);
            }
        }

        // Get original ACLItems
        DataSet ds = AclItemInfoProvider.GetACLItemsAndOperators(EditedNode.NodeID)
                     .WhereStartsWith("Operator", "R")
                     .WhereEquals("ACLID", EditedNode.NodeACLID)
                     .Columns("Operator", "Allowed", "Denied");

        // Change original values
        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string op        = DataHelper.GetNotEmpty(dr["Operator"], "R");
                int    allowed   = ValidationHelper.GetInteger(dr["Allowed"], 0);
                int    denied    = ValidationHelper.GetInteger(dr["Denied"], 0);
                int    aclRoleId = ValidationHelper.GetInteger(op.Substring(1), 0);

                if (aclRoleId != 0)
                {
                    // Check if read permission should be set or removed
                    if (roleIds.Contains(";" + aclRoleId + ";"))
                    {
                        // Remove role from processed role and adjust permissions in database
                        roleIds  = roleIds.Replace(";" + aclRoleId + ";", ";");
                        allowed |= 1;
                    }
                    else
                    {
                        allowed &= 126;
                    }

                    RoleInfo ri = RoleInfoProvider.GetRoleInfo(aclRoleId);
                    AclItemInfoProvider.SetRolePermissions(EditedNode, allowed, denied, ri);
                }
            }
        }


        if (roleIds.Trim(';') != "")
        {
            // Create ACL items for new roles
            string[] roles = roleIds.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string role in roles)
            {
                RoleInfo ri = RoleInfoProvider.GetRoleInfo(int.Parse(role));
                AclItemInfoProvider.SetRolePermissions(EditedNode, 1, 0, ri);
            }
        }

        var node = tree.SelectSingleNode(EditedNode.NodeID);

        DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree);
    }
Esempio n. 2
0
    /// <summary>
    /// After node created, solver role permissions.
    /// </summary>
    private void AddRoles(object sender, EventArgs e)
    {
        string roleIds = ";" + usRoles.Value + ";";

        // Check if ACL should inherit from parent
        if (InheritParentPermissions)
        {
            AclInfoProvider.EnsureOwnAcl(EditedNode);
        }
        else
        {
            // If node has already own ACL don't leave permissions, otherwise break inheritance
            if (!AclInfoProvider.HasOwnAcl(EditedNode))
            {
                AclInfoProvider.BreakInherintance(EditedNode, false);
            }
        }

        int aclId = ValidationHelper.GetInteger(EditedNode.GetValue("NodeACLID"), 0);

        // Get original ACLItems
        DataSet ds = AclItemInfoProvider.GetAclItems(EditedNode.NodeID, "Operator LIKE N'R%' AND ACLID = " + aclId, null, 0, "Operator, Allowed, Denied");

        // Change original values
        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string op        = DataHelper.GetNotEmpty(dr["Operator"], "R");
                int    allowed   = ValidationHelper.GetInteger(dr["Allowed"], 0);
                int    denied    = ValidationHelper.GetInteger(dr["Denied"], 0);
                int    aclRoleId = ValidationHelper.GetInteger(op.Substring(1), 0);

                if (aclRoleId != 0)
                {
                    // Check if read permission should be set or removed
                    if (roleIds.Contains(";" + aclRoleId + ";"))
                    {
                        // Remove role from processed role and adjust permissions in database
                        roleIds  = roleIds.Replace(";" + aclRoleId + ";", ";");
                        allowed |= 1;
                    }
                    else
                    {
                        allowed &= 126;
                    }

                    RoleInfo ri = RoleInfoProvider.GetRoleInfo(aclRoleId);
                    AclItemInfoProvider.SetRolePermissions(EditedNode, allowed, denied, ri);
                }
            }
        }

        // Create ACL items for new roles
        if (roleIds.Trim(';') != "")
        {
            // Process rest of the roles
            string[] roles = roleIds.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string role in roles)
            {
                RoleInfo ri = RoleInfoProvider.GetRoleInfo(int.Parse(role));
                AclItemInfoProvider.SetRolePermissions(EditedNode, 1, 0, ri);
            }
        }
    }