/// <summary> /// Takes in the ID of the current CMPage and returns whether or not /// the currently logged in user may access that page (determined by entries in CMPageRole /// </summary> /// <param name="cmPageID"></param> /// <returns></returns> public static bool CanUserAccessPage(int cmPageID) { bool authorized = true; if (HasFullCMSPermission()) { return(true); } CMPageRole.Filters filterList = new CMPageRole.Filters(); filterList.FilterCMPageRoleCMPageID = cmPageID.ToString(); filterList.FilterCMPageRoleEditor = false.ToString(); List <CMPageRole> pageRoles = CMPageRole.CMPageRolePage(0, 0, "", "", true, filterList); CMPage thePage = CMPage.GetByID(cmPageID); if (thePage.NeedsApproval && pageRoles.Count == 0) { return(false); } if (pageRoles.Count > 0) { authorized = false; if (HttpContext.Current.User.Identity.IsAuthenticated) { List <UserRole> userRoles = UserRole.UserRoleGetByUserID(Helpers.GetCurrentUserID()); if (pageRoles.Any(pageRole => userRoles.Exists(r => r.RoleID == pageRole.RoleID && (!thePage.NeedsApproval || (thePage.NeedsApproval && pageRole.Editor))))) { authorized = true; } } } return(authorized); }
public static bool CanUserManagePage() { CMPage currentPage = GetCurrentRequestCMSPage(); CMMicrosite micrositeEntity = GetCurrentRequestCMSMicrosite(); bool canManage = (HttpContext.Current.User.IsInRole("Microsite Admin") && (micrositeEntity != null && CMMicrositeUser.CMMicrositeUserGetByCMMicrositeID(micrositeEntity.CMMicroSiteID).Exists(m => m.UserID == Helpers.GetCurrentUserID()))); if (HttpContext.Current.User.IsInRole("CMS Page Manager") && !canManage) { if (currentPage != null) { List <CMPageRole> pageRoles = CMPageRole.CMPageRolePage(0, 0, "", "", true, new CMPageRole.Filters { FilterCMPageRoleCMPageID = currentPage.CMPageID.ToString(), FilterCMPageRoleEditor = true.ToString() }); if (pageRoles.Any(role => HttpContext.Current.User.IsInRole(Role.GetByID(role.RoleID).Name))) { canManage = true; } } } return(canManage); }