Skip to content

Commit be8945d

Browse files
authored
feat: Support public/private worlds (#800)
* feat: Support public/private worlds * fix: Use world name from metadata * test: fix tests * test: fix tests * test: fix tests
1 parent af90746 commit be8945d

File tree

9 files changed

+189
-129
lines changed

9 files changed

+189
-129
lines changed

package-lock.json

Lines changed: 4 additions & 116 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@contentful/rich-text-react-renderer": "^16.1.6",
1313
"@dcl/hooks": "^1.0.0",
14-
"@dcl/schemas": "^24.0.0",
14+
"@dcl/schemas": "^25.0.0",
1515
"@sentry/browser": "^7.120.3",
1616
"@well-known-components/pushable-channel": "^1.0.3",
1717
"abort-controller": "^3.0.0",
@@ -100,7 +100,7 @@
100100
"workbox-cli": "^6.5.2"
101101
},
102102
"overrides": {
103-
"@dcl/schemas": "^24.0.0"
103+
"@dcl/schemas": "^25.0.0"
104104
},
105105
"keywords": [
106106
"gatsby"

src/entities/CheckScenes/task/handleWorldSettingsChanged.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import WorldModel from "../../World/model"
2525
export async function handleWorldSettingsChanged(
2626
event: WorldSettingsChangedEvent
2727
): Promise<void> {
28-
const worldName = event.key
28+
const { worldName } = event.metadata
2929

3030
if (!worldName) {
3131
logger.error("WorldSettingsChangedEvent missing world name (key)")
@@ -80,6 +80,9 @@ export async function handleWorldSettingsChanged(
8080
show_in_places: event.metadata.showInPlaces,
8181
single_player: event.metadata.singlePlayer,
8282
skybox_time: event.metadata.skyboxTime,
83+
is_private: event.metadata.accessType
84+
? event.metadata.accessType !== "unrestricted"
85+
: false,
8386
})
8487

8588
loggerExtended.log(`Upserted world settings for: ${worldName}`)

src/entities/World/model.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ export default class WorldModel extends Model<WorldAttributes> {
335335
show_in_places: world.show_in_places ?? true,
336336
single_player: world.single_player ?? false,
337337
skybox_time: world.skybox_time ?? null,
338+
is_private: world.is_private ?? false,
338339
likes: world.likes ?? 0,
339340
dislikes: world.dislikes ?? 0,
340341
favorites: world.favorites ?? 0,
@@ -362,7 +363,7 @@ export default class WorldModel extends Model<WorldAttributes> {
362363
INSERT INTO ${table(this)} (
363364
"id", "world_name", "title", "description", "image",
364365
"content_rating", "categories", "owner", "show_in_places",
365-
"single_player", "skybox_time", "likes", "dislikes", "favorites",
366+
"single_player", "skybox_time", "is_private", "likes", "dislikes", "favorites",
366367
"like_rate", "like_score", "disabled", "disabled_at",
367368
"created_at", "updated_at"
368369
) VALUES (
@@ -377,6 +378,7 @@ export default class WorldModel extends Model<WorldAttributes> {
377378
${worldData.show_in_places},
378379
${worldData.single_player},
379380
${worldData.skybox_time},
381+
${worldData.is_private},
380382
${worldData.likes},
381383
${worldData.dislikes},
382384
${worldData.favorites},
@@ -410,6 +412,7 @@ export default class WorldModel extends Model<WorldAttributes> {
410412
"show_in_places",
411413
"single_player",
412414
"skybox_time",
415+
"is_private",
413416
]
414417

415418
// Build changes object with only explicitly provided fields

src/entities/World/schemas.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ export const worldSchema = schema({
166166
minimum: 0,
167167
description: "The number of favorites on the world",
168168
},
169+
is_private: {
170+
type: "boolean",
171+
description: "True if the world has restricted access (private)",
172+
},
169173
disabled: {
170174
type: "boolean",
171175
description: "True if the world is disabled",

src/entities/World/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type WorldAttributes = BaseEntityAttributes & {
1212
show_in_places: boolean
1313
single_player: boolean
1414
skybox_time: number | null
15+
is_private: boolean
1516
}
1617

1718
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Type } from "decentraland-gatsby/dist/entities/Database/types"
2+
import { ColumnDefinitions, MigrationBuilder } from "node-pg-migrate"
3+
4+
import WorldModel from "../entities/World/model"
5+
6+
export const shorthands: ColumnDefinitions | undefined = undefined
7+
8+
export async function up(pgm: MigrationBuilder): Promise<void> {
9+
pgm.addColumn(WorldModel.tableName, {
10+
is_private: {
11+
type: Type.Boolean,
12+
default: false,
13+
notNull: true,
14+
},
15+
})
16+
}
17+
18+
export async function down(pgm: MigrationBuilder): Promise<void> {
19+
pgm.dropColumn(WorldModel.tableName, "is_private")
20+
}

test/fixtures/worldSettingsEvent.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,9 @@ export function createWorldSettingsChangedEvent(
1616
timestamp: Date.now(),
1717
...overrides,
1818
metadata: {
19-
title: "Test World",
20-
description: "A test world for integration tests",
21-
contentRating: "T",
22-
categories: ["art", "game"],
23-
showInPlaces: true,
24-
singlePlayer: false,
25-
skyboxTime: null,
26-
thumbnailUrl: "https://example.com/thumbnail.png",
19+
worldName: "testworld.dcl.eth",
2720
...overrides.metadata,
28-
},
21+
} as WorldSettingsChangedEvent["metadata"],
2922
}
3023
}
3124

@@ -38,6 +31,7 @@ export function createWorldSettingsUpgradeRatingEvent(
3831
return createWorldSettingsChangedEvent({
3932
key: worldName,
4033
metadata: {
34+
worldName: worldName,
4135
contentRating: "A",
4236
},
4337
})
@@ -53,6 +47,7 @@ export function createWorldSettingsDowngradeRatingEvent(
5347
return createWorldSettingsChangedEvent({
5448
key: worldName,
5549
metadata: {
50+
worldName: worldName,
5651
contentRating: "RP",
5752
},
5853
})

0 commit comments

Comments
 (0)