Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ“Œ load pinboard for V2 fronts tool if user has Pinboard permission (and feature switch on) #1679

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/conf/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ class ApplicationConfiguration(

val applicationName = "facia-tool"

// isProd is derived from the enviroment mode which is given
// isProd is derived from the environment mode which is given
// to us by play, it is true for both prod and code. Stage is a variable coming
// from the config and tells us which bucket we are reading fronts and collections from.
// Stage is prod for production environment and code for code and dev environemnts.
// These two variables together allow us to determine the application url.
val applicationUrl = if (isProd && stage == "code") "https://fronts.code.dev-gutools.co.uk"
else if (isProd) "https://fronts.gutools.co.uk"
else "https://fronts.local.dev-gutools.co.uk"
val correspondingToolsDomainSuffix = if (isProd && stage == "code") "code.dev-gutools.co.uk"
else if (isProd) "gutools.co.uk"
else "local.dev-gutools.co.uk"

val applicationUrl = s"https://fronts.${correspondingToolsDomainSuffix}"
}

object ophanApi {
Expand Down
17 changes: 13 additions & 4 deletions app/controllers/V2App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package controllers
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB
import org.scanamo._
import org.scanamo.syntax._
import model.{ClipboardCard, FeatureSwitch, UserData, UserDataForDefaults}
import model.{ClipboardCard, FeatureSwitch, PinboardIntegration, UserData, UserDataForDefaults}

import scala.concurrent.ExecutionContext
import com.gu.facia.client.models.{Metadata, TargetedTerritory}
Expand All @@ -14,7 +14,7 @@ import play.api.libs.json.Json
import services.editions.db.EditionsDB
import software.amazon.awssdk.services.dynamodb.DynamoDbClient
import switchboard.SwitchManager
import util.{Acl, AclJson}
import util.{AccessGranted, Acl, AclJson}

class V2App(isDev: Boolean, val acl: Acl, dynamoClient: DynamoDbClient, db: EditionsDB, val deps: BaseFaciaControllerComponents)(implicit ec: ExecutionContext) extends BaseFaciaController(deps) {

Expand All @@ -39,6 +39,7 @@ class V2App(isDev: Boolean, val acl: Acl, dynamoClient: DynamoDbClient, db: Edit
val hasBreakingNews = acl.testUser(Permissions.BreakingNewsAlert, "facia-tool-allow-breaking-news-for-all")(req.user.email)
val hasConfigureFronts = acl.testUser(Permissions.ConfigureFronts, "facia-tool-allow-config-for-all")(req.user.email)
val hasEditionsPermissions = acl.testUser(Permissions.EditEditions, "facia-tool-allow-edit-editions-for-all")(req.user.email)
val pinboardPermission = acl.testUser(Permissions.Pinboard, "facia-tool-allow-pinboard-for-all")(req.user.email)

val acls = AclJson(
fronts = Map(config.faciatool.breakingNewsFront -> hasBreakingNews),
Expand All @@ -51,7 +52,9 @@ class V2App(isDev: Boolean, val acl: Acl, dynamoClient: DynamoDbClient, db: Edit
val maybeUserData: Option[UserData] = Scanamo(dynamoClient).exec(
userDataTable.get("email" === userEmail)).flatMap(_.toOption)

val clipboardCards = if (editingEdition) {
val maybePinboardFeatureSwitch = maybeUserData.flatMap(_.featureSwitches.flatMap(_.find(_.key == PinboardIntegration.key)))

val clipboardCards = if (editingEdition) {
if(isFeast)
maybeUserData.map(_.feastEditionsClipboardCards.getOrElse(List()).map(ClipboardCard.apply))
else
Expand Down Expand Up @@ -96,7 +99,13 @@ class V2App(isDev: Boolean, val acl: Acl, dynamoClient: DynamoDbClient, db: Edit
cssLocation,
faviconLocation,
Json.toJson(conf).toString(),
isDev
isDev,
maybePinboardUrl = pinboardPermission match {
case AccessGranted if config.environment.stage != "prod" || maybePinboardFeatureSwitch.exists(_.enabled) =>
Some(s"https://pinboard.${config.environment.correspondingToolsDomainSuffix}/pinboard.loader.js")
case _ =>
None
}
))
}

Expand Down
8 changes: 7 additions & 1 deletion app/model/FeatureSwitches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ object UsePortraitCropsForSomeCollectionTypes extends FeatureSwitch(
enabled = false
)

object PinboardIntegration extends FeatureSwitch(
key = "pinboard",
title = "Enable Pinboard integration",
enabled = false
)

object FeatureSwitches {
val all: List[FeatureSwitch] = List(ObscureFeed, PageViewDataVisualisation, TenImageSlideshows, UsePortraitCropsForSomeCollectionTypes)
val all: List[FeatureSwitch] = List(ObscureFeed, PageViewDataVisualisation, TenImageSlideshows, UsePortraitCropsForSomeCollectionTypes, PinboardIntegration)

def updateFeatureSwitchesForUser(userDataSwitches: Option[List[FeatureSwitch]], switch: FeatureSwitch): List[FeatureSwitch] = {
val newSwitches = userDataSwitches match {
Expand Down
19 changes: 11 additions & 8 deletions app/permissions/Permissions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package permissions
import com.gu.permissions.PermissionDefinition

object Permissions {
val FrontsAccess = PermissionDefinition("fronts_access", "fronts")
val ConfigureFronts = PermissionDefinition("configure_fronts", "fronts")
val BreakingNewsAlert = PermissionDefinition("breaking_news_alert", "fronts")
val LaunchCommercialFronts = PermissionDefinition("launch_commercial_fronts", "fronts")
val LaunchEditorialFronts = PermissionDefinition("launch_editorial_fronts", "fronts")
val EditEditorialFronts = PermissionDefinition("edit_editorial_fronts", "fronts")
val EditEditions = PermissionDefinition("edit_editions", "fronts")
val LaunchAndEditEmailFronts = PermissionDefinition("edit_and_launch_email_fronts", "fronts")
private val app = "fronts"
val FrontsAccess = PermissionDefinition("fronts_access", app)
val ConfigureFronts = PermissionDefinition("configure_fronts", app)
val BreakingNewsAlert = PermissionDefinition("breaking_news_alert", app)
val LaunchCommercialFronts = PermissionDefinition("launch_commercial_fronts", app)
val LaunchEditorialFronts = PermissionDefinition("launch_editorial_fronts", app)
val EditEditorialFronts = PermissionDefinition("edit_editorial_fronts", app)
val EditEditions = PermissionDefinition("edit_editions", app)
val LaunchAndEditEmailFronts = PermissionDefinition("edit_and_launch_email_fronts", app)

val Pinboard = PermissionDefinition("pinboard", "pinboard")
}
15 changes: 13 additions & 2 deletions app/views/V2App/app.scala.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
@(title: String, jsLocation: String, cssLocation: String, faviconLocation: String, clientConfigJson:
String, isDev: Boolean)
@(
title: String,
jsLocation: String,
cssLocation: String,
faviconLocation: String,
clientConfigJson: String,
isDev: Boolean,
maybePinboardUrl: Option[String]
)
<!DOCTYPE html>
<html lang="en">

Expand Down Expand Up @@ -52,6 +59,10 @@
<link rel="stylesheet" href="@cssLocation">
<script type="module" src="@jsLocation" type="application/javascript"></script>
}

@maybePinboardUrl.map { pinboardUrl =>
<script async defer src="@pinboardUrl"></script>
}
</body>

</html>