| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -143,6 +143,20 @@ class AuthenticatedActions( | |||
| 143 | 143 | def refine[A](request: AuthRequest[A]) = checkRecentAuthenticationAndRedirect(request) | |
| 144 | 144 | } | |
| 145 | 145 | ||
| 146 | + private def decideConsentsRedirectFilter: ActionFilter[AuthRequest] = | ||
| 147 | + new ActionFilter[AuthRequest] { | ||
| 148 | + override val executionContext = ec | ||
| 149 | + | ||
| 150 | + def filter[A](request: AuthRequest[A]) = { | ||
| 151 | + redirectService.toConsentsRedirect(request.user, request).map { redirect => | ||
| 152 | + if (redirect.isAllowedFrom("")) | ||
| 153 | + Some(sendUserToUserRedirectDecision(request, redirect)) | ||
| 154 | + else | ||
| 155 | + None | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + } | ||
| 159 | + | ||
| 146 | 160 | // Play will not let you set up an ActionBuilder with a Refiner hence this empty actionBuilder to set up Auth | |
| 147 | 161 | private def noOpActionBuilder: DefaultActionBuilder = DefaultActionBuilder(anyContentParser) | |
| 148 | 162 | ||
@@ -162,7 +176,11 @@ class AuthenticatedActions( | |||
| 162 | 176 | def consentAuthWithIdapiUserAction: ActionBuilder[AuthRequest, AnyContent] = | |
| 163 | 177 | noOpActionBuilder andThen consentAuthRefiner andThen retrieveUserFromIdapiRefiner | |
| 164 | 178 | ||
| 165 | - /** Auth with at least SC_GU_RP and decide if user should be redirected to consent journey */ | ||
| 179 | + /** Enforce a validated email */ | ||
| 180 | + def consentsRedirectAction(): ActionBuilder[AuthRequest, AnyContent] = | ||
| 181 | + consentAuthWithIdapiUserAction andThen decideConsentsRedirectFilter | ||
| 182 | + | ||
| 183 | + /** Redirects for the account page */ | ||
| 166 | 184 | def manageAccountRedirectAction(pageId: String = ""): ActionBuilder[AuthRequest, AnyContent] = | |
| 167 | 185 | consentAuthWithIdapiUserAction andThen decideManageAccountRedirectFilter(pageId) | |
| 168 | 186 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | package controllers.editprofile | |
| 2 | 2 | ||
| 3 | - import actions.AuthenticatedActions.AuthRequest | ||
| 3 | + import actions.AuthenticatedActions._ | ||
| 4 | 4 | import com.gu.identity.model.{Consent, EmailNewsletters, StatusFields, User} | |
| 5 | 5 | import idapiclient.UserUpdateDTO | |
| 6 | 6 | import model.{IdentityPage, NoCache} | |
@@ -61,15 +61,17 @@ trait ConsentsJourney | |||
| 61 | 61 | page: ConsentJourneyPage, | |
| 62 | 62 | consentHint: Option[String]): Action[AnyContent] = | |
| 63 | 63 | ||
| 64 | - csrfAddToken { | ||
| 65 | - consentAuthWithIdapiUserAction.async { implicit request => | ||
| 66 | - consentJourneyView( | ||
| 67 | - page = page, | ||
| 68 | - journey = page.journey, | ||
| 69 | - forms = ProfileForms(userWithOrderedConsents(request.user, consentHint), PublicEditProfilePage), | ||
| 70 | - request.user, | ||
| 71 | - consentHint | ||
| 72 | - ) | ||
| 64 | + | ||
| 65 | + csrfAddToken { | ||
| 66 | + consentsRedirectAction.async { implicit request => | ||
| 67 | + consentJourneyView( | ||
| 68 | + page = page, | ||
| 69 | + journey = page.journey, | ||
| 70 | + forms = ProfileForms(userWithOrderedConsents(request.user, consentHint), PublicEditProfilePage), | ||
| 71 | + request.user, | ||
| 72 | + consentHint | ||
| 73 | + ) | ||
| 74 | + | ||
| 73 | 75 | } | |
| 74 | 76 | } | |
| 75 | 77 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,12 +22,8 @@ sealed abstract class ProfileRedirect(val url: String) { | |||
| 22 | 22 | def isAllowedFrom(url: String): Boolean | |
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | - case object RedirectToEmailValidationFromEmailPrefs extends ProfileRedirect("/verify-email?isRepermissioningRedirect=true") { | ||
| 26 | - override def isAllowedFrom(url: String): Boolean = url contains "email-prefs" | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | - case object RedirectToEmailValidationFromAnywhere extends ProfileRedirect("/verify-email?isRepermissioningRedirect=true") { | ||
| 30 | - override def isAllowedFrom(url: String): Boolean = true | ||
| 25 | + case object RedirectToEmailValidationFromAnywhereButAccountDetails extends ProfileRedirect("/verify-email?isRepermissioningRedirect=true") { | ||
| 26 | + override def isAllowedFrom(url: String): Boolean = !(url contains "account/edit") | ||
| 31 | 27 | } | |
| 32 | 28 | ||
| 33 | 29 | case object RedirectToConsentsFromEmailPrefs extends ProfileRedirect("/consents") { | |
@@ -54,17 +50,21 @@ class ProfileRedirectService( | |||
| 54 | 50 | ||
| 55 | 51 | private implicit lazy val ec: ExecutionContext = controllerComponents.executionContext | |
| 56 | 52 | ||
| 53 | + def toConsentsRedirect[A](user: User, request: RequestHeader): Future[ProfileRedirect] = { | ||
| 54 | + user.statusFields.isUserEmailValidated match { | ||
| 55 | + case true => Future.successful(NoRedirect) | ||
| 56 | + case false => Future.successful(RedirectToEmailValidationFromAnywhereButAccountDetails) | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + | ||
| 57 | 60 | def toProfileRedirect[A](user: User, request: RequestHeader): Future[ProfileRedirect] = { | |
| 58 | 61 | ||
| 59 | 62 | def userHasRepermissioned: Boolean = user.statusFields.hasRepermissioned.contains(true) | |
| 60 | 63 | def userEmailValidated: Boolean = user.statusFields.isUserEmailValidated | |
| 61 | 64 | ||
| 62 | 65 | (userEmailValidated, userHasRepermissioned) match { | |
| 63 | - case (false, false) => | ||
| 64 | - Future.successful(RedirectToEmailValidationFromAnywhere) | ||
| 65 | - | ||
| 66 | - case (false, true) => | ||
| 67 | - Future.successful(RedirectToEmailValidationFromEmailPrefs) | ||
| 66 | + case (false, _) => | ||
| 67 | + Future.successful(RedirectToEmailValidationFromAnywhereButAccountDetails) | ||
| 68 | 68 | ||
| 69 | 69 | case (true, false) => | |
| 70 | 70 | Future.successful(RedirectToConsentsFromEmailPrefs) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,8 +60,13 @@ | |||
| 60 | 60 | role="tabpanel" | |
| 61 | 61 | aria-labelledby="tabs-account-profile-@i-tab" | |
| 62 | 62 | data-link-name="Public Profile" | |
| 63 | - data-link-context="Identity/profile"> | ||
| 64 | - @body | ||
| 63 | + data-link-context="Identity/profile" | ||
| 64 | + > | ||
| 65 | + @(if(redirectDecision.isAllowedFrom(url)) { | ||
| 66 | + Html("<div class='identity-forms-loading u-identity-forms-padded'><div class='identity-forms-loading__spinner is-updating'></div></div>") | ||
| 67 | + } else { | ||
| 68 | + body | ||
| 69 | + }) | ||
| 65 | 70 | </div> | |
| 66 | 71 | } | |
| 67 | 72 | ||
@@ -100,12 +105,7 @@ <h1 class="identity-title" data-test-id="edit-profile-header">Edit your profile< | |||
| 100 | 105 | ||
| 101 | 106 | @content(5, "/contribution/recurring/edit")(profile.recurringContributionDetailsForm(idUrlBuilder, idRequest, user)) | |
| 102 | 107 | ||
| 103 | - @content(6, "/email-prefs")( | ||
| 104 | - redirectDecision match { | ||
| 105 | - case NoRedirect => profile.privacyForm(idUrlBuilder, idRequest, user, forms.privacyForm, emailPrefsForm, emailSubscriptions, availableLists, consentsUpdated, consentHint) | ||
| 106 | - case _: ProfileRedirect => Html("<div class='identity-forms-loading u-identity-forms-padded'><div class='identity-forms-loading__spinner is-updating'></div></div>") | ||
| 107 | - } | ||
| 108 | - ) | ||
| 108 | + @content(6, "/email-prefs")(profile.privacyForm(idUrlBuilder, idRequest, user, forms.privacyForm, emailPrefsForm, emailSubscriptions, availableLists, consentsUpdated, consentHint)) | ||
| 109 | 109 | </div> | |
| 110 | 110 | </div> | |
| 111 | 111 | </div> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments