예제 #1
0
    /// <summary>
    /// Creates role UI element. Called when the "Add element to role" button is pressed.
    /// Expects the CreateUIElement method to be run first.
    /// </summary>
    private bool AddUIElementToRole()
    {
        // Get the role
        RoleInfo role = RoleInfoProvider.GetRoleInfo("cmsdeskadmin", SiteContext.CurrentSiteID);

        // Get the UI element
        UIElementInfo element = UIElementInfoProvider.GetUIElementInfo("MyNewModule", "MyNewElement");

        if ((role != null) && (element != null))
        {
            // Create new role UI element object
            RoleUIElementInfo newRoleElement = new RoleUIElementInfo();

            // Set the properties
            newRoleElement.RoleID    = role.RoleID;
            newRoleElement.ElementID = element.ElementID;

            // Save the role UI element
            RoleUIElementInfoProvider.SetRoleUIElementInfo(newRoleElement);

            return(true);
        }

        return(false);
    }
예제 #2
0
    /// <summary>
    /// Recursivelly select or deselect all child elements.
    /// </summary>
    /// <param name="select">Determines the type of action</param>
    /// <param name="parentId">ID of the parent UIElement</param>
    /// <param name="excludeRoot">Indicates whether to exclude root element from selection/deselection</param>
    private void SelectDeselectAll(bool select, int parentId, bool excludeRoot)
    {
        // Check manage permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY))
        {
            RedirectToAccessDenied("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY);
        }

        // Get the children and select them
        string where = (ModuleID > 0) ?
                       String.Format(@"(ElementResourceID = {0} OR EXISTS (SELECT ElementID FROM CMS_UIElement AS x WHERE x.ElementIDPath like CMS_UIElement.ElementIDPath+ '%' AND x.ElementResourceID = {0})) AND
                            ElementIDPath LIKE (SELECT TOP 1 ElementIDPath FROM CMS_UIElement WHERE ElementID = {1}) + '%' ", ModuleID, parentId) :
                       "ElementIDPath LIKE (SELECT TOP 1 ElementIDPath FROM CMS_UIElement WHERE ElementID = " + parentId + ") + '%' ";
        if (excludeRoot)
        {
            where += " AND NOT ElementID = " + parentId;
        }
        if (!String.IsNullOrEmpty(GroupPreffix))
        {
            where += " AND ElementName NOT LIKE '" + SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(GroupPreffix)) + "%'";
        }

        using (CMSActionContext context = new CMSActionContext())
        {
            // Many updates caused deadlocks with CMS_Role table, disable touch parent of the role
            context.TouchParent = false;

            DataSet ds = UIElementInfoProvider.GetUIElements(where, null, 0, "ElementID");
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int id = ValidationHelper.GetInteger(dr["ElementID"], 0);
                    if (select)
                    {
                        RoleUIElementInfoProvider.AddRoleUIElementInfo(RoleID, id);
                    }
                    else
                    {
                        RoleUIElementInfoProvider.DeleteRoleUIElementInfo(RoleID, id);
                    }
                }
            }

            // Explicitly touch the role only once
            var role = RoleInfoProvider.GetRoleInfo(RoleID);
            if (role != null)
            {
                role.Update();
            }
        }
    }
    /// <summary>
    /// Recursivelly select or deselect all child elements.
    /// </summary>
    /// <param name="select">Determines the type of action</param>
    /// <param name="parentId">ID of the parent UIElement</param>
    /// <param name="excludeRoot">Indicates whether to exclude root element from selection/deselection</param>
    private void SelectDeselectAll(bool select, int parentId, bool excludeRoot)
    {
        // Check manage permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY))
        {
            RedirectToAccessDenied("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY);
        }

        // Get the children and select them (do not use module as filter if all elements should be visible)
        string where = ((ModuleID > 0) && !ShowAllElementsFromModuleSection) ?
                       String.Format(@"(ElementResourceID = {0} OR EXISTS (SELECT ElementID FROM CMS_UIElement AS x WHERE x.ElementIDPath LIKE CMS_UIElement.ElementIDPath+ '%' AND x.ElementResourceID = {0})) AND
                            ElementIDPath LIKE (SELECT TOP 1 ElementIDPath FROM CMS_UIElement WHERE ElementID = {1}) + '%' ", ModuleID, parentId) :
                       "ElementIDPath LIKE (SELECT TOP 1 ElementIDPath FROM CMS_UIElement WHERE ElementID = " + parentId + ") + '%' ";
        if (excludeRoot)
        {
            where += " AND NOT ElementID = " + parentId;
        }
        if (!String.IsNullOrEmpty(GroupPreffix))
        {
            where += " AND ElementName NOT LIKE '" + SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(GroupPreffix)) + "%'";
        }

        using (CMSActionContext context = new CMSActionContext())
        {
            // Many updates caused deadlocks with CMS_Role table, disable touch parent of the role
            context.TouchParent = false;

            var elementIds = UIElementInfoProvider.GetUIElements()
                             .Where(where)
                             .Columns("ElementID")
                             .GetListResult <int>();

            foreach (var id in elementIds)
            {
                if (select)
                {
                    RoleUIElementInfoProvider.AddRoleUIElementInfo(RoleID, id);
                }
                else
                {
                    RoleUIElementInfoProvider.DeleteRoleUIElementInfo(RoleID, id);
                }
            }

            // Explicitly touch the role only once
            RoleInfoProvider.GetRoleInfo(RoleID)
            ?.Update();
        }
    }
    public void RaiseCallbackEvent(string eventArgument)
    {
        // Check manage permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY))
        {
            return;
        }

        string[] test = eventArgument.Split(';');
        if ((test.Length == 2) || (test.Length == 3))
        {
            if (test.Length == 3)
            {
                bool excludeRoot = !ValidationHelper.GetBoolean(test[2], false);
                if (test[0] == "s")
                {
                    int id = ValidationHelper.GetInteger(test[1], 0);
                    SelectDeselectAll(true, id, excludeRoot);
                }
                else if (test[0] == "d")
                {
                    // Deselect all action
                    int id = ValidationHelper.GetInteger(test[1], 0);
                    SelectDeselectAll(false, id, excludeRoot);
                }
            }
            else if (test.Length == 2)
            {
                // Basic checkbox click
                int  id  = ValidationHelper.GetInteger(test[0], 0);
                bool chk = ValidationHelper.GetBoolean(test[1], false);

                if (chk)
                {
                    RoleUIElementInfoProvider.AddRoleUIElementInfo(this.RoleID, id);
                }
                else
                {
                    RoleUIElementInfoProvider.DeleteRoleUIElementInfo(this.RoleID, id);
                }
            }

            // Invalidate all users
            UserInfo.TYPEINFO.InvalidateAllObjects();
        }
    }
예제 #5
0
    protected void gridMatrix_OnItemChanged(object sender, int rowItemId, int colItemId, bool newState)
    {
        if (newState)
        {
            RoleUIElementInfoProvider.AddRoleUIElementInfo(rowItemId, colItemId);
        }
        else
        {
            RoleUIElementInfoProvider.DeleteRoleUIElementInfo(rowItemId, colItemId);
        }

        // Invalidate all users
        UserInfo.TYPEINFO.InvalidateAllObjects();

        // Update content before rows
        gridMatrix.ContentBeforeRows = GetBeforeRowsContent();
    }
예제 #6
0
    /// <summary>
    /// Copies role binding from parent UI element.
    /// </summary>
    /// <param name="element">Element which are permissions copied to</param>
    private void CopyFromParent(UIElementInfo element)
    {
        using (var tr = new CMSTransactionScope())
        {
            if (element != null)
            {
                // Delete existing bindings
                DataSet elemRoles = RoleUIElementInfoProvider.GetRoleUIElements("ElementID = " + element.ElementID, null);
                if (!DataHelper.DataSourceIsEmpty(elemRoles))
                {
                    foreach (DataRow dr in elemRoles.Tables[0].Rows)
                    {
                        // Get role id
                        int roleId = ValidationHelper.GetInteger(dr["RoleID"], 0);
                        // Remove binding
                        RoleUIElementInfoProvider.DeleteRoleUIElementInfo(roleId, element.ElementID);
                    }
                }

                // Add same bindings as parent has
                int parentElemId = element.ElementParentID;

                DataSet parentRoles = RoleUIElementInfoProvider.GetRoleUIElements("ElementID = " + parentElemId, null);
                if (!DataHelper.DataSourceIsEmpty(parentRoles))
                {
                    foreach (DataRow dr in parentRoles.Tables[0].Rows)
                    {
                        // Get role id
                        int roleId = ValidationHelper.GetInteger(dr["RoleID"], 0);
                        // Create binding
                        RoleUIElementInfoProvider.AddRoleUIElementInfo(roleId, element.ElementID);
                    }
                }
            }

            // Commit transaction
            tr.Commit();
        }

        // Invalidate all users
        UserInfo.TYPEINFO.InvalidateAllObjects();

        // Clear hashtables with users
        UserInfoProvider.Clear(true);
    }
예제 #7
0
    /// <summary>
    /// Removes UI element from role. Called when the "Remove element from role" button is pressed.
    /// Expects the AddUIElementToRole method to be run first.
    /// </summary>
    private bool RemoveUIElementFromRole()
    {
        // Get the role
        RoleInfo role = RoleInfoProvider.GetRoleInfo("cmsdeskadmin", SiteContext.CurrentSiteID);

        // Get the UI element
        UIElementInfo element = UIElementInfoProvider.GetUIElementInfo("MyNewModule", "MyNewElement");

        if ((role != null) && (element != null))
        {
            // Get the role UI element
            RoleUIElementInfo deleteElement = RoleUIElementInfoProvider.GetRoleUIElementInfo(role.RoleID, element.ElementID);

            // Delete the role UI element
            RoleUIElementInfoProvider.DeleteRoleUIElementInfo(deleteElement);

            return(deleteElement != null);
        }

        return(false);
    }
예제 #8
0
    protected void gridMatrix_OnItemChanged(object sender, int rowItemId, int colItemId, bool newState)
    {
        if (newState)
        {
            RoleUIElementInfoProvider.AddRoleUIElementInfo(rowItemId, colItemId);
        }
        else
        {
            RoleUIElementInfoProvider.DeleteRoleUIElementInfo(rowItemId, colItemId);
        }

        // Invalidate all users
        UserInfo.TYPEINFO.InvalidateAllObjects();

        // Forget old user
        mCurrentUser = null;

        // Clear hashtables with users
        UserInfoProvider.Clear(true);

        // Update content before rows
        GenerateBeforeRowsContent();
    }
    /// <summary>
    /// Recursivelly select or deselect all child elements.
    /// </summary>
    /// <param name="select">Determines the type of action</param>
    /// <param name="parentId">ID of the parent UIElement</param>
    /// <param name="excludeRoot">Indicates whether to exclude root element from selection/deselection</param>
    private void SelectDeselectAll(bool select, int parentId, bool excludeRoot)
    {
        // Check manage permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY))
        {
            RedirectToAccessDenied("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY);
        }

        // Get the children and select them
        string where = "ElementIDPath LIKE (SELECT TOP 1 ElementIDPath FROM CMS_UIElement WHERE ElementID = " + parentId + ") + '%' ";
        if (excludeRoot)
        {
            where += " AND NOT ElementID = " + parentId;
        }
        if (!String.IsNullOrEmpty(this.GroupPreffix))
        {
            where += " AND ElementName NOT LIKE '" + SqlHelperClass.GetSafeQueryString(this.GroupPreffix, false) + "%'";
        }
        DataSet ds = UIElementInfoProvider.GetUIElements(where, null, 0, "ElementID");

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                int id = ValidationHelper.GetInteger(dr["ElementID"], 0);
                if (select)
                {
                    RoleUIElementInfoProvider.AddRoleUIElementInfo(this.RoleID, id);
                }
                else
                {
                    RoleUIElementInfoProvider.DeleteRoleUIElementInfo(this.RoleID, id);
                }
            }
        }
    }