Beispiel #1
0
        public static CMPageRole GetByID(int CMPageRoleID, IEnumerable <string> includeList = null)
        {
            CMPageRole obj = null;
            string     key = cacheKeyPrefix + CMPageRoleID + GetCacheIncludeText(includeList);

            CMPageRole tmpClass = null;

            if (Cache.IsEnabled)
            {
                if (Cache.IsEmptyCacheItem(key))
                {
                    return(null);
                }
                tmpClass = Cache[key] as CMPageRole;
            }

            if (tmpClass != null)
            {
                obj = tmpClass;
            }
            else
            {
                using (Entities entity = new Entities())
                {
                    IQueryable <CMPageRole> itemQuery = AddIncludes(entity.CMPageRole, includeList);
                    obj = itemQuery.FirstOrDefault(n => n.CMPageRoleID == CMPageRoleID);
                }
                Cache.Store(key, obj);
            }

            return(obj);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
 public CMPageRole(CMPageRole objectToCopy)
 {
     CMPageID     = objectToCopy.CMPageID;
     CMPageRoleID = objectToCopy.CMPageRoleID;
     Editor       = objectToCopy.Editor;
     RoleID       = objectToCopy.RoleID;
 }
Beispiel #4
0
        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);
        }