From e58ac60253adda944c98a7cba8dc1159e91446db Mon Sep 17 00:00:00 2001 From: Denis Volkov Date: Tue, 1 Nov 2022 21:01:31 -0700 Subject: [PATCH] Clean up Notifications and re-enable Account menu for Admins --- Amen/Amen.csproj | 4 +- Amen/Controllers/NotificationController.cs | 64 +++--- Amen/Views/Shared/_Layout.cshtml | 6 +- Amen/Web.config | 226 ++++++++++----------- 4 files changed, 141 insertions(+), 159 deletions(-) diff --git a/Amen/Amen.csproj b/Amen/Amen.csproj index 9d31631..de73429 100644 --- a/Amen/Amen.csproj +++ b/Amen/Amen.csproj @@ -13,7 +13,7 @@ Properties Amen Amen - v4.8 + v4.8.1 false true @@ -242,9 +242,9 @@ - + diff --git a/Amen/Controllers/NotificationController.cs b/Amen/Controllers/NotificationController.cs index b4d3bad..ac317ae 100644 --- a/Amen/Controllers/NotificationController.cs +++ b/Amen/Controllers/NotificationController.cs @@ -1,14 +1,11 @@ using Amen.Models; using System; using System.Configuration; -using System.Diagnostics; using System.Linq; using System.Net; -using System.Net.Http; using System.Net.Mail; using System.Web.Mvc; using System.Web.Routing; -using System.Xml; using Twilio; namespace Amen.Controllers @@ -54,7 +51,6 @@ namespace Amen.Controllers return View("~/Views/Email/PrayerSubmitted.cshtml", model); } - public ActionResult PreviewNoteSent(int id) { var prayer = controllerHelper.db.Prayers.Include("Affiliate").FirstOrDefault(i => i.Id == id); @@ -72,7 +68,6 @@ namespace Amen.Controllers return View("~/Views/Email/NoteSent.cshtml", model); } - public ActionResult PreviewAdminNotification(int id) { var prayer = controllerHelper.db.Prayers.Include("Affiliate").FirstOrDefault(i => i.Id == id); @@ -154,15 +149,23 @@ namespace Amen.Controllers } } - static bool CanSendText(Affiliate affiliate, ApplicationUser appUser, Prayer prayer) + static bool CanSendText(Affiliate affiliate, ref ApplicationUser appUser, Prayer prayer) { //if we don't have what we need then return - if (affiliate == null || appUser == null || prayer == null) + if (affiliate == null || prayer == null) return false; - //if user opted not to recieve text notifications then return - if (!appUser.IsSmsCapable || !prayer.EnableTextNotification || !affiliate.IsSmsCapable) - return false; + if (appUser == null) + { + //if login not required, then set the user with anonymous email and name + appUser = new ApplicationUser() + { + Email = prayer.AnonymousEmail, + PhoneNumber = prayer.AnonymousPhone, + FullName = prayer.AnonymousName, + EnableSmsNotifications = true + }; + } return true; } @@ -175,37 +178,16 @@ namespace Amen.Controllers if (appUser == null) { - // log in is no longer required - //if (!affiliate.RequireLoginForNoticiations) - //{ - //if login not required, then set the user with anonymous email and name - appUser = new ApplicationUser() - { - Email = prayer.AnonymousEmail, - PhoneNumber = prayer.AnonymousPhone, - FullName = prayer.AnonymousName, - EnableEmailNotifications = true - }; - //} - //else - //{ - // return false; - //} + //if login not required, then set the user with anonymous email and name + appUser = new ApplicationUser() + { + Email = prayer.AnonymousEmail, + PhoneNumber = prayer.AnonymousPhone, + FullName = prayer.AnonymousName, + EnableEmailNotifications = true + }; } - //ignore any settings that logged-in user might have - comment out the following - ////this indicates that someone submitted a prayer, so we should check if the user allows notifications, and then send them an email regarless of whether they sellected to allow prayed for notifications - //if (appUser.EnableEmailNotifications && submitCheck) - // return true; - - ////if doing a noteCheck, then ignore the prayer.EnableEmailNotification flag as they explicitly chose to allow notes of encouragement but not necessarily to be notified when someone prays. - //if (appUser.EnableEmailNotifications && noteCheck && prayer.EnableEmailNote) - // return true; - - ////if user opted not to recieve notifications then return - //if (!appUser.EnableEmailNotifications || !prayer.EnableEmailNotification) - // return false; - return true; } @@ -246,7 +228,7 @@ namespace Amen.Controllers } } - if (CanSendText(affiliate, appUser, prayer)) + if (CanSendText(affiliate, ref appUser, prayer)) { if (prayer.ContactPreference == "phone" || prayer.ContactPreference == "any") { @@ -293,7 +275,7 @@ namespace Amen.Controllers model.DetailUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Detail", "Prayer", new { id = prayer.Id, affiliatekey = affiliate.Key })); model.ManageUrl = controller.controllerHelper.Absolute(urlHelper, urlHelper.Action("Index", "Manage", new { affiliatekey = affiliate.Key })); - if (CanSendText(affiliate, appUser, prayer)) + if (CanSendText(affiliate, ref appUser, prayer)) { if (prayer.ContactPreference == "phone" || prayer.ContactPreference == "any") { diff --git a/Amen/Views/Shared/_Layout.cshtml b/Amen/Views/Shared/_Layout.cshtml index 2c89003..aea1617 100644 --- a/Amen/Views/Shared/_Layout.cshtml +++ b/Amen/Views/Shared/_Layout.cshtml @@ -128,8 +128,10 @@
  • @Html.ActionLink("Dashboard", "Index", "Group", new { affiliatekey = ViewBag.AffiliateKey }, new { @class = controllerName == "Affiliate" ? "selected" : "" })
  • } - - @*@Html.Partial("_LoginPartial")*@ + @if (User.IsInRole(Amen.Controllers.ControllerHelper.Role_Administrator) || User.IsInRole(Amen.Controllers.ControllerHelper.Role_AffiliateAdministrator) || User.IsInRole(Amen.Controllers.ControllerHelper.Role_SuperAdministrator)) + { + @Html.Partial("_LoginPartial") + } diff --git a/Amen/Web.config b/Amen/Web.config index ae95b68..5f49ff5 100644 --- a/Amen/Web.config +++ b/Amen/Web.config @@ -1,4 +1,4 @@ - + -
    +
    @@ -16,71 +16,69 @@ - - - - - - - - + + + + + + + - - - + + - - - - - - - + + + + + + + - - + + - - - - - - - - - - + + + + + + + + + + - - - - + + + + - + - - - - + + + +