Skip to content

Commit

Permalink
feat: store content rating history from scene deployed (#370)
Browse files Browse the repository at this point in the history
* feat: store content rating history from scene deployed

* feat: add admin
  • Loading branch information
braianj authored Oct 9, 2023
1 parent cffa505 commit 883633a
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/config/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"WORLDS_FIND_OUT_URL": "https://decentraland.org/blog/announcements/introducing-decentraland-worlds-beta-your-own-3d-space-in-the-metaverse",
"GATSBY_DCL_LIST_URL": "https://dcl-lists.decentraland.zone",
"GATSBY_SSO_URL": "https://id.decentraland.zone",
"GATSBY_ADMIN_ADDRESSES": "0xd9b96b5dc720fc52bede1ec3b40a930e15f70ddd,0x8Cff6832174091DAe86F0244e3Fd92d4CeD2Fe07,0x3385C05cA0dDB46B51F9c2D99FC597cf6F0DA891,0xC1cAD2e2B78E14843004E7e1994B8CD68bA383a0,0x4DAa4f8704fE0cfFaCa667810e8cB212b4FC516e,0x35b248d06Bf280E17d8Cbff63C56A58e52a936f1,0xd545B9E0A5F3638a5026d1914CC9b47ed16B5ae9"
"GATSBY_ADMIN_ADDRESSES": "0xd9b96b5dc720fc52bede1ec3b40a930e15f70ddd,0x8Cff6832174091DAe86F0244e3Fd92d4CeD2Fe07,0x3385C05cA0dDB46B51F9c2D99FC597cf6F0DA891,0xC1cAD2e2B78E14843004E7e1994B8CD68bA383a0,0x4DAa4f8704fE0cfFaCa667810e8cB212b4FC516e,0x35b248d06Bf280E17d8Cbff63C56A58e52a936f1,0xd545B9E0A5F3638a5026d1914CC9b47ed16B5ae9,0x5Ea403933d9F0CF0d0De41dEAE5fD39911834ad3"
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("processContentEntityScene", () => {
created_at: processEntitySceneResult!.new!.created_at,
updated_at: processEntitySceneResult!.new!.updated_at,
},
rating: processEntitySceneResult?.rating,
disabled: [],
})
})
Expand All @@ -61,6 +62,7 @@ describe("processContentEntityScene", () => {
created_at: processEntitySceneResult!.update!.created_at,
updated_at: processEntitySceneResult!.update!.updated_at,
},
rating: processEntitySceneResult?.rating,
disabled: [],
})
})
Expand All @@ -80,6 +82,7 @@ describe("processContentEntityScene", () => {
created_at: processEntitySceneResult!.new!.created_at,
updated_at: processEntitySceneResult!.new!.updated_at,
},
rating: processEntitySceneResult?.rating,
disabled: [placeGenesisPlazaWithAggregatedAttributes],
})
})
Expand Down Expand Up @@ -107,6 +110,7 @@ describe("processContentEntityScene", () => {
created_at: processEntitySceneResult!.update!.created_at,
updated_at: processEntitySceneResult!.update!.updated_at,
},
rating: processEntitySceneResult?.rating,
disabled: [placeGenesisPlazaWithAggregatedAttributes],
})
})
Expand Down
37 changes: 35 additions & 2 deletions src/entities/CheckScenes/task/processContentEntityScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ import getContentRating, {
import PlaceModel from "../../Place/model"
import { PlaceAttributes } from "../../Place/types"
import { getThumbnailFromContentDeployment as getThumbnailFromContentEntityScene } from "../../Place/utils"
import { PlaceContentRatingAttributes } from "../../PlaceContentRating/types"
import { notifyDowngradeRating, notifyUpgradingRating } from "../../Slack/utils"
import { findNewDeployedPlace, findSamePlace } from "../utils"

export type ProcessEntitySceneResult =
| {
new: PlaceAttributes
update?: never
rating: PlaceContentRatingAttributes | null
disabled: PlaceAttributes[]
}
| {
new?: never
update: PlaceAttributes
rating: PlaceContentRatingAttributes | null
disabled: PlaceAttributes[]
}

Expand All @@ -36,14 +39,44 @@ export function processContentEntityScene(
return null
}
if (!samePlace) {
const placefromContentEntity =
createPlaceFromContentEntityScene(contentEntityScene)
return {
new: createPlaceFromContentEntityScene(contentEntityScene),
new: placefromContentEntity,
rating: {
id: uuid(),
place_id: placefromContentEntity.id,
original_rating: null,
update_rating: placefromContentEntity.content_rating,
moderator: null,
comment: null,
created_at: new Date(),
},
disabled: places,
}
}

const placefromContentEntity = createPlaceFromContentEntityScene(
contentEntityScene,
samePlace
)

let rating = null
if (placefromContentEntity.content_rating !== samePlace.content_rating) {
rating = {
id: uuid(),
place_id: samePlace.id,
original_rating: samePlace.content_rating,
update_rating: placefromContentEntity.content_rating,
moderator: null,
comment: null,
created_at: new Date(),
}
}

return {
update: createPlaceFromContentEntityScene(contentEntityScene, samePlace),
update: placefromContentEntity,
rating,
disabled: places.filter((place) => samePlace.id !== place.id),
}
}
Expand Down
76 changes: 55 additions & 21 deletions src/entities/CheckScenes/task/taskRunnerSqs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { v4 as uuid } from "uuid"

import PlaceModel from "../../Place/model"
import { PlaceAttributes } from "../../Place/types"
import PlaceContentRatingModel from "../../PlaceContentRating/model"
import PlacePositionModel from "../../PlacePosition/model"
import {
notifyDisablePlaces,
Expand Down Expand Up @@ -69,17 +72,27 @@ export async function taskRunnerSqs(job: DeploymentToSqs) {
const worldIndexing = await verifyWorldsIndexing([worldName])

if (!worlds.length) {
const placefromContentEntity = createPlaceFromContentEntityScene(
contentEntityScene,
{
hidden: !worldIndexing[0].shouldBeIndexed,
disabled:
!!contentEntityScene?.metadata?.worldConfiguration?.placesConfig
?.optOut,
},
{ url: job.contentServerUrls![0] }
)
placesToProcess = {
new: createPlaceFromContentEntityScene(
contentEntityScene,
{
hidden: !worldIndexing[0].shouldBeIndexed,
disabled:
!!contentEntityScene?.metadata?.worldConfiguration?.placesConfig
?.optOut,
},
{ url: job.contentServerUrls![0] }
),
new: placefromContentEntity,
rating: {
id: uuid(),
place_id: placefromContentEntity.id,
original_rating: null,
update_rating: placefromContentEntity.content_rating,
moderator: null,
comment: null,
created_at: new Date(),
},
disabled: [],
}
} else {
Expand All @@ -96,18 +109,35 @@ export async function taskRunnerSqs(job: DeploymentToSqs) {
)
}

const placefromContentEntity = createPlaceFromContentEntityScene(
contentEntityScene,
{
...worlds[0],
hidden: !worldIndexing[0].shouldBeIndexed,
disabled:
!!contentEntityScene?.metadata?.worldConfiguration?.placesConfig
?.optOut,
},
{ url: job.contentServerUrls![0] }
)

let rating = null

if (placefromContentEntity.content_rating !== worlds[0].content_rating) {
rating = {
id: uuid(),
place_id: worlds[0].id,
original_rating: worlds[0].content_rating,
update_rating: placefromContentEntity.content_rating,
moderator: null,
comment: null,
created_at: new Date(),
}
}

placesToProcess = {
update: createPlaceFromContentEntityScene(
contentEntityScene,
{
...worlds[0],
hidden: !worldIndexing[0].shouldBeIndexed,
disabled:
!!contentEntityScene?.metadata?.worldConfiguration?.placesConfig
?.optOut,
},
{ url: job.contentServerUrls![0] }
),
update: placefromContentEntity,
rating,
disabled: [],
}
}
Expand Down Expand Up @@ -164,6 +194,10 @@ export async function taskRunnerSqs(job: DeploymentToSqs) {
})
}

if (placesToProcess?.rating) {
PlaceContentRatingModel.create(placesToProcess.rating)
}

if (placesToProcess?.disabled.length) {
const placesIdToDisable = placesToProcess.disabled.map((place) => place.id)
await PlaceModel.disablePlaces(placesIdToDisable)
Expand Down
2 changes: 1 addition & 1 deletion src/entities/PlaceContentRating/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type PlaceContentRatingAttributes = {
place_id: string
original_rating: string | null
update_rating: string
moderator: string
moderator: string | null
comment: string | null
created_at: Date
}
15 changes: 15 additions & 0 deletions src/migrations/1696625541164_update-place-content-rating.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MigrationBuilder } from "node-pg-migrate"

import PlaceContentRatingModel from "../entities/PlaceContentRating/model"

export async function up(pgm: MigrationBuilder): Promise<void> {
pgm.alterColumn(PlaceContentRatingModel.tableName, "moderator", {
notNull: false,
})
}

export async function down(pgm: MigrationBuilder): Promise<void> {
pgm.alterColumn(PlaceContentRatingModel.tableName, "moderator", {
notNull: true,
})
}

0 comments on commit 883633a

Please sign in to comment.