Example #1
0
    public void DeleteUserRole(UserInfo user)
    {
        try
        {
            // Get role and user objects
            // RoleInfo role = RoleInfoProvider.GetRoleInfo(roleName.ToString(), CMS.SiteProvider.SiteContext.CurrentSiteID);
            //  UserInfo user = UserInfoProvider.GetUserInfo("MyNewUser");
            DataTable dt = UserInfoProvider.GetUserRoles(user);

            if (dt.Rows.Count > 0 && dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["RoleName"].ToString().ToLower().Contains("sso_"))
                    {
                        UserRoleInfo deleteRole = UserRoleInfoProvider.GetUserRoleInfo(user.UserID, Convert.ToInt32(dr["RoleID"]));
                        // Delete the user role
                        UserRoleInfoProvider.DeleteUserRoleInfo(deleteRole);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("Issue while DeleteUserRole", "Get", ex);
        }
    }
Example #2
0
        public void RemoveFromRoleAsync_UserIsNotInRole_DoesNotThrow()
        {
            var user = new User(mMembershipFakeFactory.UserEnabledWithEmail);

            CMSAssert.All(
                () => Assert.IsNull(UserRoleInfoProvider.GetUserRoleInfo(user.Id, mMembershipFakeFactory.AdminRole.RoleID)),
                () => Assert.DoesNotThrow(() => mUserStore.RemoveFromRoleAsync(user, MembershipFakeFactory.ROLE_ADMIN).Wait()));
        }
Example #3
0
        public async Task AddToRoleAsync_UserIsNotInRole_UserRoleInfoCreated()
        {
            var user = new User(mMembershipFakeFactory.UserEnabledWithEmail);
            await mUserStore.AddToRoleAsync(user, MembershipFakeFactory.ROLE_MEMBER);

            CMSAssert.All(
                () => Assert.AreEqual(1, UserRoleInfoProvider.GetUserRoles().Count),
                () => Assert.IsNotNull(UserRoleInfoProvider.GetUserRoleInfo(user.Id, mMembershipFakeFactory.MemberRole.RoleID)));
        }
Example #4
0
        public void AddToRoleAsync_UserIsInRole_DoesNotThrow()
        {
            var user = new User(mMembershipFakeFactory.UserEnabledWithEmail);
            var role = mMembershipFakeFactory.AdminRole;

            UserRoleInfoProvider.AddUserToRole(mMembershipFakeFactory.UserEnabledWithEmail, role);

            CMSAssert.All(
                () => Assert.IsNotNull(UserRoleInfoProvider.GetUserRoleInfo(user.Id, role.RoleID)),
                () => Assert.DoesNotThrow(() => mUserStore.AddToRoleAsync(user, role.RoleName).Wait()));
        }
Example #5
0
        public async Task RemoveFromRoleAsync_UserIsInRole_UserRoleInfoDeletedUserAndRoleExists()
        {
            var role = mMembershipFakeFactory.AdminRole;
            var user = new User(mMembershipFakeFactory.UserEnabledWithEmail);

            UserRoleInfoProvider.AddUserToRole(mMembershipFakeFactory.UserEnabledWithEmail, mMembershipFakeFactory.AdminRole);

            await mUserStore.RemoveFromRoleAsync(user, role.RoleName);

            CMSAssert.All(
                () => Assert.AreEqual(0, UserRoleInfoProvider.GetUserRoles().Count),
                () => Assert.IsNull(UserRoleInfoProvider.GetUserRoleInfo(user.Id, role.RoleID)),
                () => Assert.IsNotNull(RoleInfoProvider.GetRoleInfo(role.RoleID)),
                () => Assert.IsNotNull(UserInfoProvider.GetUserInfo(user.Id)));
        }
    /// <summary>
    /// Deletes user role. Called when the "Delete role" button is pressed.
    /// Expects the CreateUserRole method to be run first.
    /// </summary>
    private bool DeleteUserRole()
    {
        // Get role and user objects
        RoleInfo role = RoleInfoProvider.GetRoleInfo("MyNewRole", CMSContext.CurrentSiteID);
        UserInfo user = UserInfoProvider.GetUserInfo("MyNewUser");

        if ((role != null) && (user != null))
        {
            // Get the user role
            UserRoleInfo deleteRole = UserRoleInfoProvider.GetUserRoleInfo(user.UserID, role.RoleID);

            // Delete the user role
            UserRoleInfoProvider.DeleteUserRoleInfo(deleteRole);

            return(true);
        }

        return(false);
    }
        public void SetUserRole(int UserID, string RoleName, string SiteName, bool RoleToggle)
        {
            var Role = _Helper.GetRole(RoleName, SiteName, new string[] { "RoleID" });

            if (RoleToggle)
            {
                if (UserRoleInfoProvider.GetUserRoleInfo(UserID, Role.RoleID) == null)
                {
                    UserRoleInfoProvider.AddUserToRole(UserID, Role.RoleID);
                }
            }
            else
            {
                var ExistingUserRole = UserRoleInfoProvider.GetUserRoleInfo(UserID, Role.RoleID);
                if (ExistingUserRole != null)
                {
                    ExistingUserRole.Delete();
                }
            }
        }
    /// <summary>
    /// Saves roles of specified user.
    /// </summary>
    private void SaveRoles(int userID)
    {
        // Load user's roles
        if (!currentRolesLoaded)
        {
            LoadCurrentRoles();
        }

        // Remove old items
        string newValues = ValidationHelper.GetString(usRoles.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, currentValues);

        if (!String.IsNullOrEmpty(items))
        {
            var newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            // Removes relationship between user and role
            foreach (string item in newItems)
            {
                int roleID = ValidationHelper.GetInteger(item, 0);

                var uri = UserRoleInfoProvider.GetUserRoleInfo(userID, roleID);
                UserRoleInfoProvider.DeleteUserRoleInfo(uri);
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            var newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            // Add relationship between user and role
            foreach (string item in newItems)
            {
                int roleID = ValidationHelper.GetInteger(item, 0);
                UserRoleInfoProvider.AddUserToRole(userID, roleID);
            }
        }
    }
Example #9
0
    /// <summary>
    /// Page_load event.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions and UI elements
        var user = MembershipContext.AuthenticatedUser;

        if (user != null)
        {
            if (!user.IsAuthorizedPerUIElement("CMS.Users", "CmsDesk.Roles"))
            {
                RedirectToUIElementAccessDenied("CMS.Users", "CmsDesk.Roles");
            }

            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Roles", "Read"))
            {
                RedirectToAccessDenied("CMS.Roles", "Read");
            }
        }

        ScriptHelper.RegisterJQuery(Page);

        // Get user id and site Id from query
        mUserId = QueryHelper.GetInteger("userid", 0);

        // Show content placeholder where site selector can be shown
        CurrentMaster.DisplaySiteSelectorPanel = true;

        if ((SiteID > 0) && !MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))
        {
            plcSites.Visible = false;
            CurrentMaster.DisplaySiteSelectorPanel = false;
        }

        if (mUserId > 0)
        {
            // Check that only global administrator can edit global administrator's accounts
            mUserInfo = UserInfoProvider.GetUserInfo(mUserId);
            CheckUserAvaibleOnSite(mUserInfo);
            EditedObject = mUserInfo;

            if (!CheckGlobalAdminEdit(mUserInfo))
            {
                plcTable.Visible = false;
                ShowError(GetString("Administration-User_List.ErrorGlobalAdmin"));
                return;
            }

            // Set site selector
            siteSelector.DropDownSingleSelect.AutoPostBack = true;
            siteSelector.AllowAll   = false;
            siteSelector.AllowEmpty = false;

            // Global roles only for global admin
            if (MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin))
            {
                siteSelector.AllowGlobal = true;
            }

            // Only sites assigned to user
            siteSelector.UserId           = mUserId;
            siteSelector.OnlyRunningSites = false;
            siteSelector.UniSelector.OnSelectionChanged += UniSelector_OnSelectionChanged;

            if (!RequestHelper.IsPostBack())
            {
                mSiteId = SiteContext.CurrentSiteID;

                // If user is member of current site
                if (UserSiteInfoProvider.GetUserSiteInfo(mUserId, mSiteId) != null)
                {
                    // Force uniselector to preselect current site
                    siteSelector.Value = mSiteId;
                }

                // Force to load data
                siteSelector.Reload(true);
            }

            // Get truly selected item
            mSiteId = ValidationHelper.GetInteger(siteSelector.Value, 0);
        }

        usRoles.OnSelectionChanged += usRoles_OnSelectionChanged;
        string siteIDWhere = (mSiteId <= 0) ? " SiteID IS NULL " : " SiteID =" + mSiteId;

        usRoles.WhereCondition = siteIDWhere + " AND RoleGroupID IS NULL";

        usRoles.SelectItemPageUrl     = "~/CMSModules/Membership/Pages/Users/User_Edit_Add_Item_Dialog.aspx";
        usRoles.ListingWhereCondition = siteIDWhere + " AND RoleGroupID IS NULL AND UserID=" + mUserId;
        usRoles.ReturnColumnName      = "RoleID";
        usRoles.DynamicColumnName     = false;
        usRoles.GridName               = "User_Role_List.xml";
        usRoles.AdditionalColumns      = "ValidTo";
        usRoles.OnAdditionalDataBound += usMemberships_OnAdditionalDataBound;
        usRoles.DialogWindowHeight     = 760;

        // Exclude generic roles
        string    genericWhere = String.Empty;
        ArrayList genericRoles = RoleInfoProvider.GetGenericRoles();

        if (genericRoles.Count != 0)
        {
            foreach (string role in genericRoles)
            {
                genericWhere += "'" + SqlHelper.EscapeQuotes(role) + "',";
            }

            genericWhere            = genericWhere.TrimEnd(',');
            usRoles.WhereCondition += " AND ( RoleName NOT IN (" + genericWhere + ") )";
        }

        // Get the active roles for this site
        var roleIds = new IDQuery <RoleInfo>().Where(siteIDWhere).Column("RoleID");
        var data    = UserRoleInfoProvider.GetUserRoles().WhereEquals("UserID", mUserId).And().WhereIn("RoleID", roleIds).Columns("RoleID").TypedResult;

        if (data.Any())
        {
            mCurrentValues = TextHelper.Join(";", data.Select(i => i.RoleID));
        }

        // If not postback or site selection changed
        if (!RequestHelper.IsPostBack() || (mSiteId != Convert.ToInt32(ViewState["rolesOldSiteId"])))
        {
            // Set values
            usRoles.Value = mCurrentValues;
        }

        // Store selected site id
        ViewState["rolesOldSiteId"] = mSiteId;

        string script = "function setNewDateTime(date) {$cmsj('#" + hdnDate.ClientID + "').val(date);}";

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "key", ScriptHelper.GetScript(script));

        string eventTarget   = Request[postEventSourceID];
        string eventArgument = Request[postEventArgumentID];

        if (eventTarget == ucCalendar.DateTimeTextBox.UniqueID)
        {
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Users", "ManageUserRoles"))
            {
                RedirectToAccessDenied("CMS.Users", "Manage user roles");
            }

            int id = ValidationHelper.GetInteger(hdnDate.Value, 0);
            if (id != 0)
            {
                DateTime     dt  = ValidationHelper.GetDateTime(eventArgument, DateTimeHelper.ZERO_TIME);
                UserRoleInfo uri = UserRoleInfoProvider.GetUserRoleInfo(mUserId, id);
                if (uri != null)
                {
                    uri.ValidTo = dt;
                    UserRoleInfoProvider.SetUserRoleInfo(uri);

                    // Invalidate user
                    UserInfoProvider.InvalidateUser(mUserId);

                    ShowChangesSaved();
                }
            }
        }
    }
Example #10
0
    /// <summary>
    /// Saves data.
    /// </summary>
    private void SaveData()
    {
        // Check "modify" permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Users", "ManageUserRoles"))
        {
            RedirectToAccessDenied("CMS.Users", "Manage user roles");
        }

        bool   saved  = false;
        string result = ValidateGlobalAndDeskAdmin();

        if (result != String.Empty)
        {
            ShowError(result);
            return;
        }

        string selectorValues = ValidationHelper.GetString(usRoles.Value, null);

        // Remove old items
        string items = DataHelper.GetNewItemsInList(selectorValues, mCurrentValues);

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems.Any())
            {
                // Remove all old items from site
                foreach (string item in newItems)
                {
                    int roleID = ValidationHelper.GetInteger(item, 0);

                    var uri = UserRoleInfoProvider.GetUserRoleInfo(mUserId, roleID);
                    UserRoleInfoProvider.DeleteUserRoleInfo(uri);
                }

                saved = true;
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(mCurrentValues, selectorValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems.Any())
            {
                DateTime dt = ValidationHelper.GetDateTime(hdnDate.Value, DateTimeHelper.ZERO_TIME);

                // Add all new items to site
                foreach (string item in newItems)
                {
                    int roleID = ValidationHelper.GetInteger(item, 0);
                    UserRoleInfoProvider.AddUserToRole(mUserId, roleID, dt);
                }

                saved = true;
            }
        }

        if (saved)
        {
            ShowChangesSaved();
            usRoles.Reload(true);
        }
    }
Example #11
0
    private void SaveUsers()
    {
        if (!CheckPermissions("cms.roles", PERMISSION_MODIFY))
        {
            return;
        }

        bool falseValues = false;
        bool saved       = false;

        // Remove old items
        string        newValues    = ValidationHelper.GetString(usUsers.Value, null);
        string        items        = DataHelper.GetNewItemsInList(newValues, currentValues);
        StringBuilder errorMessage = new StringBuilder();

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to user
                foreach (string item in newItems)
                {
                    int userId = ValidationHelper.GetInteger(item, 0);

                    // Check permissions
                    string result = ValidateGlobalAndDeskAdmin(userId);
                    if (result != String.Empty)
                    {
                        errorMessage.Append(result);
                        falseValues = true;
                        continue;
                    }
                    else
                    {
                        var uri = UserRoleInfoProvider.GetUserRoleInfo(userId, RoleID);
                        UserRoleInfoProvider.DeleteUserRoleInfo(uri);

                        saved = true;
                    }
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to user
                foreach (string item in newItems)
                {
                    int userId = ValidationHelper.GetInteger(item, 0);

                    // Check permissions
                    string result = ValidateGlobalAndDeskAdmin(userId);
                    if (result != String.Empty)
                    {
                        errorMessage.Append(result);
                        falseValues = true;
                        continue;
                    }
                    else
                    {
                        UserRoleInfoProvider.AddUserToRole(userId, RoleID);
                        saved = true;
                    }
                }
            }
        }
        if (errorMessage.Length > 0)
        {
            ShowError(errorMessage.ToString());
        }

        if (falseValues)
        {
            currentValues = GetRoleUsers();
            usUsers.Value = currentValues;
            usUsers.Reload();
        }

        if (saved)
        {
            ShowChangesSaved();
        }
    }
Example #12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions
        var user = MembershipContext.AuthenticatedUser;

        if (user != null)
        {
            if (!user.IsAuthorizedPerUIElement("CMS.Roles", "Users"))
            {
                RedirectToUIElementAccessDenied("CMS.Roles", "Users");
            }

            // Check "read" permissions
            if (!user.IsAuthorizedPerResource("CMS.Users", "Read"))
            {
                RedirectToAccessDenied("CMS.Users", "Read");
            }
        }

        usUsers.AdditionalColumns = "UserID,ValidTo";
        usUsers.GridName          = "~/CMSModules/Membership/Pages/Users/UsersValidTo.xml";
        roleID                     = QueryHelper.GetInteger("roleid", 0);
        usUsers.IsLiveSite         = false;
        usUsers.DialogWindowHeight = 760;

        // Show only user belonging to role's site
        RoleInfo ri = RoleInfoProvider.GetRoleInfo(roleID);

        if (ri != null)
        {
            usUsers.WhereCondition        = (ri.SiteID > 0) ? "UserID IN (SELECT UserID FROM CMS_UserSite WHERE SiteID = " + ri.SiteID + ")" : String.Empty;
            usUsers.ListingWhereCondition = "RoleID = " + ri.RoleID;
        }

        usUsers.DynamicColumnName = false;
        usUsers.SelectItemPageUrl = "~/CMSModules/Membership/Pages/Users/User_Edit_Add_Item_Dialog.aspx";

        currentValues = GetRoleUsers();
        if (!RequestHelper.IsPostBack())
        {
            usUsers.Value = currentValues;
        }

        usUsers.OnSelectionChanged    += UniSelector_OnSelectionChanged;
        usUsers.OnAdditionalDataBound += usUsers_OnAdditionalDataBound;

        string script = "function setNewDateTime(date) {$cmsj('#" + hdnDate.ClientID + "').val(date);}";

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "key", ScriptHelper.GetScript(script));

        string eventTarget   = Request[postEventSourceID];
        string eventArgument = Request[postEventArgumentID];

        if (eventTarget == ucCalendar.DateTimeTextBox.UniqueID)
        {
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Users", "ManageUserRoles"))
            {
                RedirectToAccessDenied("CMS.Users", "ManageUserRoles");
            }

            int id = ValidationHelper.GetInteger(hdnDate.Value, 0);
            if (id != 0)
            {
                DateTime     dt  = ValidationHelper.GetDateTime(eventArgument, DateTimeHelper.ZERO_TIME);
                UserRoleInfo uri = UserRoleInfoProvider.GetUserRoleInfo(id, ri.RoleID);
                if (uri != null)
                {
                    uri.ValidTo = dt;
                    UserRoleInfoProvider.SetUserRoleInfo(uri);

                    // Invalidate user
                    UserInfo.TYPEINFO.ObjectInvalidated(id);

                    ShowChangesSaved();
                }
            }
        }
    }
Example #13
0
    private void SaveUsers()
    {
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Users", "ManageUserRoles"))
        {
            RedirectToAccessDenied("CMS.Users", "ManageUserRoles");
        }

        bool          falseValues = false;
        bool          saved       = false;
        StringBuilder errors      = new StringBuilder();

        // Remove old items
        string newValues = ValidationHelper.GetString(usUsers.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, currentValues);

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to user
                foreach (string item in newItems)
                {
                    int userId = ValidationHelper.GetInteger(item, 0);

                    // Check permissions
                    string result = ValidateGlobalAndDeskAdmin(userId);
                    if (result != String.Empty)
                    {
                        errors.AppendLine(result);
                        falseValues = true;
                        continue;
                    }
                    else
                    {
                        var uri = UserRoleInfoProvider.GetUserRoleInfo(userId, roleID);
                        UserRoleInfoProvider.DeleteUserRoleInfo(uri);

                        saved = true;
                    }
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                DateTime dt = ValidationHelper.GetDateTime(hdnDate.Value, DateTimeHelper.ZERO_TIME);

                // Add all new items to user
                foreach (string item in newItems)
                {
                    int userId = ValidationHelper.GetInteger(item, 0);

                    // Check permissions
                    string result = ValidateGlobalAndDeskAdmin(userId);
                    if (result != String.Empty)
                    {
                        errors.AppendLine(result);
                        falseValues = true;
                        continue;
                    }
                    else
                    {
                        UserRoleInfoProvider.AddUserToRole(userId, roleID, dt);
                        saved = true;
                    }
                }
            }
        }

        if (errors.Length > 0)
        {
            ShowError(GetString("general.saveerror"), errors.ToString(), null);
        }

        if (falseValues)
        {
            currentValues = GetRoleUsers();
            usUsers.Value = currentValues;
        }

        if (saved)
        {
            ShowChangesSaved();
        }

        usUsers.Reload(true);
    }
Example #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions
        CurrentUserInfo user = CMSContext.CurrentUser;

        if (user != null)
        {
            if (!user.IsAuthorizedPerUIElement("CMS.Administration", "Users"))
            {
                RedirectToCMSDeskUIElementAccessDenied("CMS.Administration", "Users");
            }

            // Check "read" permissions
            if (!user.IsAuthorizedPerResource("CMS.Users", "Read"))
            {
                RedirectToAccessDenied("CMS.Users", "Read");
            }
        }

        lblAvialable.Text = GetString("roleusers.available");

        usUsers.AdditionalColumns = "UserID,ValidTo";
        usUsers.GridName          = "~/CMSModules/Membership/Pages/Users/UsersValidTo.xml";
        roleID             = QueryHelper.GetInteger("roleid", 0);
        usUsers.IsLiveSite = false;

        // Show only user belonging to role's site
        RoleInfo ri = RoleInfoProvider.GetRoleInfo(roleID);

        if (ri != null)
        {
            usUsers.WhereCondition        = (ri.SiteID > 0) ? "UserID IN (SELECT UserID FROM CMS_UserSite WHERE SiteID = " + ri.SiteID + ")" : String.Empty;;;
            usUsers.ListingWhereCondition = "RoleID = " + ri.RoleID;
        }

        usUsers.DynamicColumnName = false;
        usUsers.SelectItemPageUrl = "~/CMSModules/Membership/Pages/Users/User_Edit_Add_Item_Dialog.aspx";

        currentValues = GetRoleUsers();
        if (!RequestHelper.IsPostBack())
        {
            usUsers.Value = currentValues;
        }

        if (!String.IsNullOrEmpty(currentValues))
        {
            usUsers.WhereCondition = SqlHelperClass.AddWhereCondition(usUsers.WhereCondition, "UserID NOT IN (" + currentValues.Replace(';', ',') + ")");
        }

        usUsers.OnSelectionChanged    += UniSelector_OnSelectionChanged;
        usUsers.OnAdditionalDataBound += new CMSAdminControls_UI_UniSelector_UniSelector.AdditionalDataBoundEventHandler(usUsers_OnAdditionalDataBound);

        string script = "function setNewDateTime(date) {$j('#" + hdnDate.ClientID + "').val(date);}";

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "key", ScriptHelper.GetScript(script));

        string eventTarget   = Request["__EVENTTARGET"];
        string eventArgument = Request["__EVENTARGUMENT"];

        if (eventTarget == ucCalendar.DateTimeTextBox.UniqueID)
        {
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Users", "ManageUserRoles"))
            {
                RedirectToCMSDeskAccessDenied("CMS.Users", "ManageUserRoles");
            }

            int id = ValidationHelper.GetInteger(hdnDate.Value, 0);
            if (id != 0)
            {
                DateTime     dt  = ValidationHelper.GetDateTime(eventArgument, DateTimeHelper.ZERO_TIME);
                UserRoleInfo uri = UserRoleInfoProvider.GetUserRoleInfo(id, ri.RoleID);
                if (uri != null)
                {
                    uri.ValidTo = dt;
                    UserRoleInfoProvider.SetUserRoleInfo(uri);

                    // Invalidate user
                    UserInfo.TYPEINFO.ObjectInvalidated(id);

                    this.lblInfo.Visible = true;
                    this.lblInfo.Text    = GetString("General.ChangesSaved");
                }
            }
        }
    }
Example #15
0
    /// <summary>
    /// Page_load event.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions and UI elements
        CurrentUserInfo user = CMSContext.CurrentUser;

        if (user != null)
        {
            if (!user.IsAuthorizedPerUIElement("CMS.Administration", "Roles"))
            {
                RedirectToCMSDeskUIElementAccessDenied("CMS.Administration", "Roles");
            }

            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Roles", "Read"))
            {
                RedirectToAccessDenied("CMS.Roles", "Read");
            }
        }

        ScriptHelper.RegisterJQuery(Page);

        // Get user id and site Id from query
        userId = QueryHelper.GetInteger("userid", 0);

        // Show contentplaceholder where site selector can be shown
        CurrentMaster.DisplaySiteSelectorPanel = true;

        if ((SiteID > 0) && !CMSContext.CurrentUser.IsGlobalAdministrator)
        {
            plcSites.Visible = false;
            CurrentMaster.DisplaySiteSelectorPanel = false;
        }

        if (userId > 0)
        {
            // Check that only global administrator can edit global administrator's accouns
            ui = UserInfoProvider.GetUserInfo(userId);
            CheckUserAvaibleOnSite(ui);
            EditedObject = ui;

            if (!CheckGlobalAdminEdit(ui))
            {
                plcTable.Visible = false;
                ShowError(GetString("Administration-User_List.ErrorGlobalAdmin"));
                return;
            }


            // Set site selector
            siteSelector.DropDownSingleSelect.AutoPostBack = true;
            siteSelector.AllowAll   = false;
            siteSelector.AllowEmpty = false;

            // Global roles only for global admin
            if (CMSContext.CurrentUser.UserSiteManagerAdmin)
            {
                siteSelector.AllowGlobal = true;
            }

            // Only sites assigned to user
            siteSelector.UserId           = userId;
            siteSelector.OnlyRunningSites = false;
            siteSelector.UniSelector.OnSelectionChanged += new EventHandler(UniSelector_OnSelectionChanged);

            if (!RequestHelper.IsPostBack())
            {
                siteId = CMSContext.CurrentSiteID;

                // If user is member of current site
                if (UserSiteInfoProvider.GetUserSiteInfo(userId, siteId) != null)
                {
                    // Force uniselector to preselect current site
                    siteSelector.Value = siteId;
                }

                // Force to load data
                siteSelector.UpdateWhereCondition();
                siteSelector.Reload(true);
            }

            // Get truly selected item
            siteId = ValidationHelper.GetInteger(siteSelector.Value, 0);
        }

        usRoles.OnSelectionChanged += new EventHandler(usRoles_OnSelectionChanged);
        string siteIDWhere = (siteId <= 0) ? " SiteID IS NULL " : " SiteID =" + siteId;

        usRoles.WhereCondition = siteIDWhere + " AND RoleGroupID IS NULL";

        usRoles.SelectItemPageUrl     = "~/CMSModules/Membership/Pages/Users/User_Edit_Add_Item_Dialog.aspx";
        usRoles.ListingWhereCondition = siteIDWhere + " AND RoleGroupID IS NULL AND UserID=" + userId;
        usRoles.ReturnColumnName      = "RoleID";
        usRoles.DynamicColumnName     = false;
        usRoles.GridName               = "User_Role_List.xml";
        usRoles.AdditionalColumns      = "ValidTo";
        usRoles.OnAdditionalDataBound += new CMSAdminControls_UI_UniSelector_UniSelector.AdditionalDataBoundEventHandler(usMemberships_OnAdditionalDataBound);

        // Exclude generic roles
        string    genericWhere = null;
        ArrayList genericRoles = RoleInfoProvider.GetGenericRoles();

        if (genericRoles.Count != 0)
        {
            foreach (string role in genericRoles)
            {
                genericWhere += "'" + role.Replace("'", "''") + "',";
            }

            genericWhere            = genericWhere.TrimEnd(',');
            usRoles.WhereCondition += " AND ( RoleName NOT IN (" + genericWhere + ") )";
        }

        // Get the active roles for this site
        DataSet ds = UserRoleInfoProvider.GetUserRoles("UserID = " + userId + " AND RoleID IN (SELECT RoleID FROM CMS_Role WHERE SiteID IS NULL OR SiteID = " + siteId + ")", null, 0, "RoleID");

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            currentValues = TextHelper.Join(";", SystemDataHelper.GetStringValues(ds.Tables[0], "RoleID"));
        }

        // If not postback or site selection changed
        if (!RequestHelper.IsPostBack() || (siteId != Convert.ToInt32(ViewState["rolesOldSiteId"])))
        {
            // Set values
            usRoles.Value = currentValues;
        }

        // Store selected site id
        ViewState["rolesOldSiteId"] = siteId;

        string script = "function setNewDateTime(date) {$j('#" + hdnDate.ClientID + "').val(date);}";

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "key", ScriptHelper.GetScript(script));

        string eventTarget   = Request["__EVENTTARGET"];
        string eventArgument = Request["__EVENTARGUMENT"];

        if (eventTarget == ucCalendar.DateTimeTextBox.UniqueID)
        {
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Users", "ManageUserRoles"))
            {
                RedirectToAccessDenied("CMS.Users", "Manage user roles");
            }

            int id = ValidationHelper.GetInteger(hdnDate.Value, 0);
            if (id != 0)
            {
                DateTime     dt  = ValidationHelper.GetDateTime(eventArgument, DateTimeHelper.ZERO_TIME);
                UserRoleInfo uri = UserRoleInfoProvider.GetUserRoleInfo(userId, id);
                if (uri != null)
                {
                    uri.ValidTo = dt;
                    UserRoleInfoProvider.SetUserRoleInfo(uri);

                    // Invalidate user
                    UserInfoProvider.InvalidateUser(userId);

                    ShowChangesSaved();
                }
            }
        }
    }