Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(api): let new channels inherit the adult-only setting (#3053)

Hampusdcdf7e1d9399
diff --git a/fluxer_api/src/api/channel/tests/ChannelOperationPermissions.test.ts b/fluxer_api/src/api/channel/tests/ChannelOperationPermissions.test.ts
index 6dcdddd00..37a3a4b02 100644
--- a/fluxer_api/src/api/channel/tests/ChannelOperationPermissions.test.ts
+++ b/fluxer_api/src/api/channel/tests/ChannelOperationPermissions.test.ts
@@ -9,6 +9,7 @@ import {
deleteChannel,
getChannel,
updateChannel,
+ updateGuild,
} from '@app/api/channel/tests/ChannelTestUtils';
import {type ApiTestHarness, createApiTestHarness} from '@app/api/test/ApiTestHarness';
import {HTTP_STATUS} from '@app/api/test/TestConstants';
@@ -58,6 +59,34 @@ describe('Channel Operation Permissions', () => {
.expect(HTTP_STATUS.FORBIDDEN)
.execute();
});
+ it('should gate channels created before a guild becomes adult-only', async () => {
+ const owner = await createTestAccount(harness);
+ const minor = await createTestAccount(harness, {dateOfBirth: '2010-01-01'});
+ const guild = await createGuild(harness, owner.token, 'Later Mature Guild');
+ const category = await createChannel(harness, owner.token, guild.id, 'category', 4);
+ const child = await createBuilder<{id: string; nsfw_override?: boolean | null}>(harness, owner.token)
+ .post(`/guilds/${guild.id}/channels`)
+ .body({name: 'child', type: 0, parent_id: category.id})
+ .execute();
+ const opened = await createBuilder<{id: string}>(harness, owner.token)
+ .post(`/guilds/${guild.id}/channels`)
+ .body({name: 'opened', type: 0, nsfw_override: false})
+ .execute();
+ const systemChannel = await getChannel(harness, owner.token, guild.system_channel_id!);
+ expect(systemChannel.nsfw_override ?? null).toBeNull();
+ expect(category.nsfw_override ?? null).toBeNull();
+ expect(child.nsfw_override ?? null).toBeNull();
+ const invite = await createChannelInvite(harness, owner.token, systemChannel.id);
+ await acceptInvite(harness, minor.token, invite.code);
+ await updateGuild(harness, owner.token, guild.id, {nsfw: true});
+ for (const channelId of [systemChannel.id, child.id]) {
+ await createBuilder(harness, minor.token)
+ .get(`/channels/${channelId}/messages`)
+ .expect(HTTP_STATUS.FORBIDDEN)
+ .execute();
+ }
+ await createBuilder(harness, minor.token).get(`/channels/${opened.id}/messages`).expect(HTTP_STATUS.OK).execute();
+ });
it('should reject member from updating channel without MANAGE_CHANNELS', async () => {
const owner = await createTestAccount(harness);
const member = await createTestAccount(harness);
diff --git a/fluxer_api/src/api/guild/services/channel/ChannelOperationsService.ts b/fluxer_api/src/api/guild/services/channel/ChannelOperationsService.ts
index 5493d4d0d..54fe8eaa4 100644
--- a/fluxer_api/src/api/guild/services/channel/ChannelOperationsService.ts
+++ b/fluxer_api/src/api/guild/services/channel/ChannelOperationsService.ts
@@ -134,7 +134,7 @@ export class ChannelOperationsService {
}
}
const requestedNsfwOverride =
- params.data.nsfw_override !== undefined ? params.data.nsfw_override : (params.data.nsfw ?? null);
+ params.data.nsfw_override !== undefined ? params.data.nsfw_override : params.data.nsfw === true ? true : null;
const requestedContentWarningLevel =
params.data.content_warning_level === ContentWarningLevel.CONTENT_WARNING
? ContentWarningLevel.CONTENT_WARNING
diff --git a/fluxer_api/src/api/guild/services/data/GuildOperationsService.ts b/fluxer_api/src/api/guild/services/data/GuildOperationsService.ts
index e3cf5ff2c..293a6f2d4 100644
--- a/fluxer_api/src/api/guild/services/data/GuildOperationsService.ts
+++ b/fluxer_api/src/api/guild/services/data/GuildOperationsService.ts
@@ -828,7 +828,7 @@ export class GuildOperationsService {
position,
owner_id: null,
recipient_ids: null,
- nsfw: false,
+ nsfw: null,
content_warning_level: null,
content_warning_text: null,
rate_limit_per_user: 0,
@@ -1048,7 +1048,7 @@ export class GuildOperationsService {
position: channel.position,
owner_id: null,
recipient_ids: null,
- nsfw: channel.nsfw ?? false,
+ nsfw: channel.nsfw === true ? true : null,
content_warning_level: null,
content_warning_text: null,
rate_limit_per_user: channel.rate_limit_per_user ?? 0,
@@ -1100,7 +1100,7 @@ export class GuildOperationsService {
position: 0,
owner_id: null,
recipient_ids: null,
- nsfw: false,
+ nsfw: null,
content_warning_level: null,
content_warning_text: null,
rate_limit_per_user: 0,
diff --git a/fluxer_api/src/api/search/tests/MessageSearchPermissions.test.ts b/fluxer_api/src/api/search/tests/MessageSearchPermissions.test.ts
index 2e441c40c..3d82baee7 100644
--- a/fluxer_api/src/api/search/tests/MessageSearchPermissions.test.ts
+++ b/fluxer_api/src/api/search/tests/MessageSearchPermissions.test.ts
@@ -384,7 +384,7 @@ describe('Message Search Permissions', () => {
const guild = await createGuild(harness, owner.token, 'Age Restricted Override Guild');
const channel = await createBuilder<{id: string; nsfw_override?: boolean | null}>(harness, owner.token)
.post(`/guilds/${guild.id}/channels`)
- .body({name: 'override-channel', type: ChannelTypes.GUILD_TEXT, nsfw: false})
+ .body({name: 'override-channel', type: ChannelTypes.GUILD_TEXT, nsfw_override: false})
.execute();
expect(channel.nsfw_override).toBe(false);
await sendChannelMessage(harness, owner.token, channel.id, 'age restricted override searchable message');