/// <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 void SendApprovalEmailAlerts(CMPage editedPage, CMPageRegion region, int userID, bool content, bool isAdmin, bool?approval, int?languageID) { if (Settings.EnableApprovals && Settings.SendApprovalEmails) { MailMessage email = new MailMessage(); SmtpClient client = new SmtpClient(); CMPage originalPage = editedPage.OriginalCMPageID.HasValue ? CMPage.GetByID(editedPage.OriginalCMPageID.Value) : null; string pageName = string.Empty; if (languageID.HasValue) { CMPageTitle titleEntity = null; //If Denied, take the original page title if (originalPage != null && approval.HasValue && !approval.Value) { titleEntity = CMPageTitle.CMPageTitleGetByCMPageIDAndLanguageID(originalPage.CMPageID, languageID.Value).FirstOrDefault(); } //If not approve/deny, take the current displayed unapproved page title if (titleEntity == null) { titleEntity = CMPageTitle.CMPageTitleGetByCMPageIDAndLanguageID(editedPage.CMPageID, languageID.Value).FirstOrDefault(); } if (titleEntity != null) { pageName = titleEntity.Title; } } if (String.IsNullOrEmpty(pageName)) { if (originalPage != null && approval.HasValue && !approval.Value) { pageName = originalPage.Title; } else { pageName = editedPage.Title; } } Language languageEntity = null; if (languageID.HasValue) { languageEntity = Language.GetByID(languageID.Value); } if (!approval.HasValue) { User userEntity = User.GetByID(userID); //Don't send Admin Email if Admin is the one who edited if (!isAdmin) { //Send Admin Email email.From = new MailAddress(Globals.Settings.FromEmail); if (!String.IsNullOrEmpty(Settings.ApprovalAdminEmailAddresses)) { foreach (string s in Settings.ApprovalAdminEmailAddresses.Split(';')) { email.To.Add(new MailAddress(s)); } } else //Send to all Admins { foreach (UserRole admin in UserRole.UserRoleGetWithUserByRoleName("Admin")) { email.To.Add(new MailAddress(admin.User.Email, admin.User.Name)); } } email.IsBodyHtml = true; email.Body = userEntity.Name + " has updated the " + (languageEntity != null ? languageEntity.Culture + " " : "") + (content ? "content" : "properties") + " of <a href=\"" + Helpers.RootPath + (content ? (editedPage.CMMicrositeID.HasValue ? CMMicrosite.GetByID(editedPage.CMMicrositeID.Value).Name + "/" : "") + editedPage.FileName + (languageEntity != null ? "?language=" + languageEntity.CultureName : "") : "admin/content-manager/content-manager-page.aspx?id=" + editedPage.CMPageID + (languageEntity != null ? "&language=" + languageEntity.CultureName : "")) + "\">" + pageName + "</a>"; email.Subject = Globals.Settings.SiteTitle + " - " + (content ? "Content" : "Page Properties") + " Approval Required"; client.Send(email); } //Send Editor Email email = new MailMessage(); email.From = new MailAddress(Globals.Settings.FromEmail); if (content && region != null && !String.IsNullOrEmpty(region.EditorUserIDs)) { foreach (string id in region.EditorUserIDs.Split(',')) { if (!id.Equals(userID.ToString())) { User editor = User.GetByID(Convert.ToInt32(id)); email.To.Add(new MailAddress(editor.Email, editor.Name)); } } } else if (!String.IsNullOrEmpty(editedPage.EditorUserIDs)) { foreach (string id in editedPage.EditorUserIDs.Split(',')) { if (!id.Equals(userID.ToString())) { User editor = User.GetByID(Convert.ToInt32(id)); email.To.Add(new MailAddress(editor.Email, editor.Name)); } } } if (email.To.Count > 0) { email.IsBodyHtml = true; email.Body = userEntity.Name + " has updated the " + (languageEntity != null ? languageEntity.Culture + " " : "") + (content ? "content" : "properties") + " of <a href=\"" + Helpers.RootPath + (content ? (editedPage.CMMicrositeID.HasValue ? CMMicrosite.GetByID(editedPage.CMMicrositeID.Value).Name + "/" : "") + editedPage.FileName + (languageEntity != null ? "?language=" + languageEntity.CultureName : "") : "admin/content-manager/content-manager-page.aspx?id=" + editedPage.CMPageID + (languageEntity != null ? "&language=" + languageEntity.CultureName : "")) + "\">" + pageName + "</a>, which you have also edited. The page is still awaiting approval from an Admin."; email.Subject = Globals.Settings.SiteTitle + " - " + (content ? "Content" : "Page Properties") + " Edited"; client = new SmtpClient(); client.Send(email); } } else //Approve/Denied { //Send Editors Email email = new MailMessage(); email.From = new MailAddress(Globals.Settings.FromEmail); if (content && region != null && !String.IsNullOrEmpty(region.EditorUserIDs)) { foreach (string id in region.EditorUserIDs.Split(',')) { if (!id.Equals(userID.ToString())) { User editor = User.GetByID(Convert.ToInt32(id)); email.To.Add(new MailAddress(editor.Email, editor.Name)); } } } else if (!String.IsNullOrEmpty(editedPage.EditorUserIDs)) { foreach (string id in editedPage.EditorUserIDs.Split(',')) { if (!id.Equals(userID.ToString())) { User editor = User.GetByID(Convert.ToInt32(id)); email.To.Add(new MailAddress(editor.Email, editor.Name)); } } } if (email.To.Count > 0) { email.IsBodyHtml = true; email.Body = "An Admin has " + (approval.Value ? "approved" : "denied") + " the " + (languageEntity != null ? languageEntity.Culture + " " : "") + (content ? "content" : "properties") + " changes to <a href=\"" + Helpers.RootPath + (content ? (editedPage.CMMicrositeID.HasValue ? CMMicrosite.GetByID(editedPage.CMMicrositeID.Value).Name + "/" : "") + editedPage.FileName + (languageEntity != null ? "?language=" + languageEntity.CultureName : "") : "admin/content-manager/content-manager-page.aspx?id=" + editedPage.CMPageID + (languageEntity != null ? "&language=" + languageEntity.CultureName : "")) + "\">" + pageName + "</a> that you made."; email.Subject = Globals.Settings.SiteTitle + " - " + (content ? "Content" : "Page Properties") + " " + (approval.Value ? "Approved" : "Denied"); client = new SmtpClient(); client.Send(email); } } } }