-
Notifications
You must be signed in to change notification settings - Fork 120
Automatically add/remove leases when a rights category is selected for an image/s based on application level config #4358
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
Merged
andrew-nowak
merged 15 commits into
guardian:main
from
bbc:t1742-leases-for-rights-category
Feb 10, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b49d578
initial updates for leases based on rights category
AndyKilmory fad05b0
coding to allow batch updating of leases for chosen rights category
AndyKilmory 958dea5
correcting js error
AndyKilmory fa9db51
reverting Elastic Search Client - not part of this functional change
AndyKilmory fa16342
js mods following code review
AndyKilmory 796269c
correcting for shared akka actor name
AndyKilmory 0316c6f
handling removal only of leases when image missing date info
AndyKilmory 3d077da
handling removal only of leases when image missing date info
AndyKilmory b6e9b0d
resolving conflicts
AndyKilmory f16963d
Merge branch 'main' into t1742-leases-for-rights-category
AndyKilmory e050ae5
Update metadata-editor/app/model/UsageRightsLease.scala
AndyKilmory 45e71ed
Update metadata-editor/app/model/UsageRightsLease.scala
AndyKilmory 8d4f2dd
Update metadata-editor/app/model/UsageRightsLease.scala
AndyKilmory 90d7d58
removal of config values
AndyKilmory 9b83f43
Merge branch 'main' into t1742-leases-for-rights-category
AndyKilmory File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // -using config lease definitions to create leases for image based on chosen rights category- | ||
| export function createCategoryLeases(leaseDefs, image) { | ||
| const leaseTypes = ["allow-use", "deny-use", "allow-syndication", "deny-syndication"]; | ||
| const leases = []; | ||
| leaseDefs.forEach((leaseDef) => { | ||
| //-establish start date: TODAY | UPLOAD | TAKEN | TXDATE- | ||
| const startDteType = leaseDef.startDate ?? "NONE"; | ||
| let startDate = undefined; | ||
| switch (startDteType) { | ||
| case ("TODAY"): | ||
| startDate = new Date(); | ||
| break; | ||
| case ("UPLOAD"): | ||
| startDate = new Date(image.data.uploadTime); | ||
| break; | ||
| case ("TAKEN"): | ||
| if (image.data.metadata.dateTaken) { | ||
| startDate = new Date(image.data.metadata.dateTaken); | ||
| } | ||
| break; | ||
| case ("TXDATE"): | ||
| if (image.data.metadata.domainMetadata && | ||
| image.data.metadata.domainMetadata.programmes && | ||
| image.data.metadata.domainMetadata.programmes.originalTxDate) { | ||
| startDate = new Date(image.data.metadata.domainMetadata.programmes.originalTxDate); | ||
| } | ||
| break; | ||
| } | ||
| // -check we have acceptable type and startDate- | ||
| if (leaseTypes.includes(leaseDef.type ?? "") && startDate) { | ||
| const lease = {}; | ||
| lease["access"] = leaseDef.type; | ||
| lease["createdAt"] = (new Date()).toISOString(); | ||
| lease["leasedBy"] = "Usage_Rights_Category"; | ||
| lease["startDate"] = startDate.toISOString(); | ||
| lease["notes"] = leaseDef.notes ?? ""; | ||
|
|
||
| if (leaseDef.duration) { | ||
| let endDate = startDate; | ||
| endDate.setFullYear(endDate.getFullYear() + leaseDef.duration); | ||
| lease["endDate"] = endDate.toISOString(); | ||
| } | ||
| lease["mediaId"] = image.data.id; | ||
| leases.push(lease); | ||
| } | ||
| }); | ||
| return leases; | ||
| } | ||
|
|
||
| /* ****************************************************************************** | ||
| Remove any leases from image that have same type as any rights-cat applied leases | ||
| ********************************************************************************* */ | ||
| export function removeCategoryLeases(categories, image, removeRights) { | ||
| const mtchCats = categories.filter(cat => cat.value === removeRights); | ||
| if (mtchCats.length === 0) { | ||
| return []; | ||
| } | ||
| const removeCat = mtchCats[0]; | ||
| if (removeCat.leases.length === 0) { | ||
| return []; | ||
| } | ||
| const removeLeases = []; | ||
| image.data.leases.data.leases.forEach(lease => { | ||
| const mtches = removeCat.leases.filter(catLease => catLease.type === lease.access); | ||
| if (mtches.length > 0) { | ||
| removeLeases.push(lease); | ||
| } | ||
| }); | ||
|
|
||
| return removeLeases; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package model | ||
|
|
||
| import com.gu.mediaservice.model._ | ||
| import play.api.ConfigLoader | ||
| import play.api.libs.json._ | ||
| import scala.jdk.CollectionConverters._ | ||
|
|
||
| case class UsageRightsLease( | ||
| category: String, | ||
| `type`: String, | ||
| startDate: String, | ||
| duration: Option[Int], | ||
| notes: Option[String] | ||
| ) | ||
|
|
||
| object UsageRightsLease { | ||
|
|
||
| def getLeasesForSpec(u: UsageRightsSpec, leases: Seq[UsageRightsLease]): Seq[UsageRightsLease] = leases.filter(_.category == u.category) | ||
|
|
||
| implicit val writes: Writes[UsageRightsLease] = Json.writes[UsageRightsLease] | ||
|
|
||
| implicit val configLoader: ConfigLoader[Seq[UsageRightsLease]] = { | ||
| ConfigLoader(_.getConfigList).map( | ||
| _.asScala.toSeq.map(config => { | ||
|
|
||
| val categoryId = if (config.hasPath("category")) { | ||
| config.getString("category") | ||
| } else "" | ||
|
|
||
| val leaseType = if (config.hasPath("type")) { | ||
| config.getString("type") | ||
| } else "" | ||
|
|
||
| val startDate = if (config.hasPath("startDate")) { | ||
| config.getString("startDate") | ||
| } else "" | ||
|
|
||
| val duration = if (config.hasPath("duration")) { | ||
| Some(config.getInt("duration")) | ||
| } else None | ||
|
|
||
| val notes = if (config.hasPath("notes")) { | ||
| Some(config.getString("notes")) | ||
| } else None | ||
|
|
||
| UsageRightsLease ( | ||
| category = categoryId, | ||
| `type` = leaseType, | ||
| startDate = startDate, | ||
| duration = duration, | ||
| notes = notes | ||
| ) | ||
|
|
||
| })) | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.