Skip to content

Commit

Permalink
enforce tag_manager_access permission
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-nowak committed Jul 10, 2024
1 parent b089b93 commit b29df38
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/controllers/PanDomainAuthActions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import com.gu.pandomainauth.model.AuthenticatedUser
import services.Config
import permissions.Permissions
import play.api.Logging
import play.api.mvc.{RequestHeader, Result}
import play.api.mvc.Results.Forbidden

trait PanDomainAuthActions extends HMACAuthActions with Logging {

private def noPermissionMessage(authedUser: AuthenticatedUser): String =
s"user ${authedUser.user.email} does not have ${Permissions.TagManagerAccess.name} permission"

override def validateUser(authedUser: AuthenticatedUser): Boolean = {
val isValid = PanDomain.guardianValidation(authedUser)

Expand All @@ -17,10 +22,20 @@ trait PanDomainAuthActions extends HMACAuthActions with Logging {
if (!isValid) {
logger.warn(s"User ${authedUser.user.email} is not valid")
} else if (!canAccess) {
logger.warn(s"User ${authedUser.user.email} does not have tag_manager_access permission")
logger.warn(noPermissionMessage(authedUser))
}

isValid // TODO && canAccess
isValid && canAccess
}

override def showUnauthedMessage(message: String)(implicit request: RequestHeader): Result =
Forbidden(views.html.Application.authError(message))

override def invalidUserMessage(claimedAuth: AuthenticatedUser): String = {
val hasAccess = Permissions.testUser(Permissions.TagManagerAccess)(claimedAuth.user.email)

if (!hasAccess) noPermissionMessage(claimedAuth)
else super.invalidUserMessage(claimedAuth)
}

override def cacheValidation = true
Expand Down
13 changes: 13 additions & 0 deletions app/views/Application/authError.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@(message: String)
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Tag Manager - access denied</title>
</head>
<body>
<h1>Tag Manager - access denied</h1>
<p>@message</p>
<p>If you require access to the Tag Manager tool, please contact <a href="mailto:central.production@@theguardian.com">Central Production</a> for assistance</p>
</body>
</html>

0 comments on commit b29df38

Please sign in to comment.