A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(api): let channel managers edit a mature channel (#2583)
Hampusa2a68847fdab
diff --git a/fluxer_api/src/api/channel/controllers/ChannelController.ts b/fluxer_api/src/api/channel/controllers/ChannelController.tsindex b1c8a50ee..e2ba92e26 100644--- a/fluxer_api/src/api/channel/controllers/ChannelController.ts+++ b/fluxer_api/src/api/channel/controllers/ChannelController.ts@@ -123,6 +123,7 @@ export function ChannelController(app: HonoApp) {const existing = await ctx.get('channelService').channelData.operations.getChannel({userId: ctx.get('user').id,channelId,+ skipNsfwValidation: true,});ctx.set('channelUpdateType', existing.type);return undefined;diff --git a/fluxer_api/src/api/channel/services/ChannelDataService.ts b/fluxer_api/src/api/channel/services/ChannelDataService.tsindex 7f7a4531b..2961508c9 100644--- a/fluxer_api/src/api/channel/services/ChannelDataService.ts+++ b/fluxer_api/src/api/channel/services/ChannelDataService.ts@@ -111,7 +111,7 @@ export class ChannelDataService {clientFeatures: ReadonlySet<string>;requestCache: RequestCache;}): Promise<Channel> {- const {channel} = await this.auth.getChannelAuthenticated({userId, channelId});+ const {channel} = await this.auth.getChannelAuthenticated({userId, channelId, skipNsfwValidation: true});if (channel.type === ChannelTypes.GROUP_DM) {return await this.groupDmUpdate.updateGroupDmChannel({userId,diff --git a/fluxer_api/src/api/channel/services/channel_data/ChannelOperationsService.ts b/fluxer_api/src/api/channel/services/channel_data/ChannelOperationsService.tsindex 3564143d6..7cbe8881f 100644--- a/fluxer_api/src/api/channel/services/channel_data/ChannelOperationsService.ts+++ b/fluxer_api/src/api/channel/services/channel_data/ChannelOperationsService.ts@@ -90,8 +90,20 @@ export class ChannelOperationsService {private rateLimitService: IRateLimitService,) {}- async getChannel({userId, channelId}: {userId: UserID; channelId: ChannelID}): Promise<Channel> {- const {channel} = await this.channelAuthService.getChannelAuthenticated({userId, channelId});+ async getChannel({+ userId,+ channelId,+ skipNsfwValidation,+ }: {+ userId: UserID;+ channelId: ChannelID;+ skipNsfwValidation?: boolean;+ }): Promise<Channel> {+ const {channel} = await this.channelAuthService.getChannelAuthenticated({+ userId,+ channelId,+ skipNsfwValidation,+ });return channel;}@@ -127,6 +139,7 @@ export class ChannelOperationsService {const {channel, guild, checkPermission} = await this.channelAuthService.getChannelAuthenticated({userId,channelId,+ skipNsfwValidation: true,});if (channel.type === ChannelTypes.GROUP_DM) {throw new InvalidChannelTypeError();@@ -456,7 +469,11 @@ export class ChannelOperationsService {if (this.voiceAvailabilityService === null) {return [];}- const {channel, guild} = await this.channelAuthService.getChannelAuthenticated({userId, channelId});+ const {channel, guild} = await this.channelAuthService.getChannelAuthenticated({+ userId,+ channelId,+ skipNsfwValidation: true,+ });if (channel.type !== ChannelTypes.GUILD_VOICE) {throw new InvalidChannelTypeError();}diff --git a/fluxer_api/src/api/channel/tests/ChannelOperationPermissions.test.ts b/fluxer_api/src/api/channel/tests/ChannelOperationPermissions.test.tsindex cdb7ceed7..29e1b45d9 100644--- a/fluxer_api/src/api/channel/tests/ChannelOperationPermissions.test.ts+++ b/fluxer_api/src/api/channel/tests/ChannelOperationPermissions.test.ts@@ -46,6 +46,18 @@ describe('Channel Operation Permissions', () => {.expect(HTTP_STATUS.FORBIDDEN).execute();});+ it('should let a minor manage a mature channel without reading it', async () => {+ const owner = await createTestAccount(harness, {dateOfBirth: '2010-01-01'});+ const guild = await createGuild(harness, owner.token, 'Mature Channel Guild');+ const systemChannel = await getChannel(harness, owner.token, guild.system_channel_id!);+ await updateChannel(harness, owner.token, systemChannel.id, {nsfw: true});+ const renamed = await updateChannel(harness, owner.token, systemChannel.id, {name: 'still-manageable'});+ expect(renamed.name).toBe('still-manageable');+ await createBuilder(harness, owner.token)+ .get(`/channels/${systemChannel.id}/messages`)+ .expect(HTTP_STATUS.FORBIDDEN)+ .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_app/src/features/channel/components/bottomsheets/channel_details_bottom_sheet/MoreOptionsSheet.tsx b/fluxer_app/src/features/channel/components/bottomsheets/channel_details_bottom_sheet/MoreOptionsSheet.tsxindex 416e9e9f3..05172d10b 100644--- a/fluxer_app/src/features/channel/components/bottomsheets/channel_details_bottom_sheet/MoreOptionsSheet.tsx+++ b/fluxer_app/src/features/channel/components/bottomsheets/channel_details_bottom_sheet/MoreOptionsSheet.tsx@@ -17,7 +17,6 @@ import {UNPIN_GROUP_DM_DESCRIPTOR,} from '@app/features/channel/utils/ChannelMessageDescriptors';import {isGroupDmFull} from '@app/features/channel/utils/GroupDmUtils';-import Guilds from '@app/features/guild/state/Guilds';import {ADD_TO_FAVORITES_DESCRIPTOR,COPY_CHANNEL_ID_DESCRIPTOR,@@ -32,7 +31,6 @@ import {REMOVE_FROM_FAVORITES_DESCRIPTOR,} from '@app/features/i18n/utils/CommonMessageDescriptors';import * as InviteUtils from '@app/features/invite/utils/InviteUtils';-import {getEffectiveChannelMatureContent} from '@app/features/messaging/utils/ContentWarningUtils';import Permission from '@app/features/permissions/state/Permission';import ReadStates from '@app/features/read_state/state/ReadStates';import {AddFriendsToGroupModal} from '@app/features/relationship/components/modals/AddFriendsToGroupModal';@@ -56,7 +54,6 @@ import {modal} from '@app/features/ui/commands/ModalCommands';import type {MenuGroupType, MenuItemType} from '@app/features/ui/menu_bottom_sheet/MenuBottomSheet';import {MenuBottomSheet} from '@app/features/ui/menu_bottom_sheet/MenuBottomSheet';import type {User} from '@app/features/user/models/User';-import Users from '@app/features/user/state/Users';import {Permissions} from '@fluxer/constants/src/ChannelConstants';import {useLingui} from '@lingui/react/macro';import type React from 'react';@@ -251,21 +248,14 @@ export const MoreOptionsSheet: React.FC<MoreOptionsSheetProps> = ({guildId: channel.guildId,});if (canManageChannels) {- const guildForChannel = channel.guildId ? Guilds.getGuild(channel.guildId) : undefined;- const currentUser = Users.getCurrentUser();- const nsfwBlockedForMinor =- getEffectiveChannelMatureContent(channel, guildForChannel ?? null) &&- !!currentUser &&- !currentUser.matureContentAllowed;- const managerItems: Array<MenuItemType> = [];- if (!nsfwBlockedForMinor) {- managerItems.push({+ const managerItems: Array<MenuItemType> = [+ {id: 'edit-channel',icon: <EditIcon size={20} data-flx="channel.channel-details-bottom-sheet.edit-icon--2" />,label: i18n._(EDIT_CHANNEL_DESCRIPTOR),onClick: onEditChannel,- });- }+ },+ ];managerItems.push({id: 'delete-channel',icon: <DeleteIcon size={20} data-flx="channel.channel-details-bottom-sheet.delete-icon" />,diff --git a/fluxer_app/src/features/ui/action_menu/items/ChannelMenuData.tsx b/fluxer_app/src/features/ui/action_menu/items/ChannelMenuData.tsxindex bed5dce0d..c3e5bef77 100644--- a/fluxer_app/src/features/ui/action_menu/items/ChannelMenuData.tsx+++ b/fluxer_app/src/features/ui/action_menu/items/ChannelMenuData.tsx@@ -54,7 +54,6 @@ import {import {InviteModal} from '@app/features/invite/components/modals/InviteModal';import * as InviteUtils from '@app/features/invite/utils/InviteUtils';import Favorites from '@app/features/messaging/state/Favorites';-import {getEffectiveChannelMatureContent} from '@app/features/messaging/utils/ContentWarningUtils';import {buildChannelLink} from '@app/features/messaging/utils/MessageLinkUtils';import * as NavigationCommands from '@app/features/navigation/commands/NavigationCommands';import Permission from '@app/features/permissions/state/Permission';@@ -88,7 +87,6 @@ import * as ToastCommands from '@app/features/ui/commands/ToastCommands';import type {MenuActionEvent, MenuGroupType, MenuItemType} from '@app/features/ui/menu_bottom_sheet/MenuBottomSheet';import UserGuildSettings from '@app/features/user/state/UserGuildSettings';import UserSettings from '@app/features/user/state/UserSettings';-import Users from '@app/features/user/state/Users';import CompactVoiceCallHeight, {getGuildVoiceCallExpansionKey} from '@app/features/voice/state/CompactVoiceCallHeight';import {getMutedText} from '@app/lib/overlay/OverlayContextMenu';import {ME} from '@fluxer/constants/src/AppConstants';@@ -203,7 +201,6 @@ export interface ChannelMenuState {hasUnread: boolean;canManageChannels: boolean;canEditChannel: boolean;- nsfwBlockedForMinor: boolean;canInvite: boolean;developerMode: boolean;isPinned: boolean;@@ -237,10 +234,6 @@ function getChannelMenuState(channel: Channel, guild: Guild | undefined): ChanneguildId: channel.guildId,});const canEditChannel = canManageChannels || canUpdateRtcRegion;- const currentUser = Users.getCurrentUser();- const channelIsNsfw =- (isTextChannel || isVoiceChannel || isLinkChannel) && getEffectiveChannelMatureContent(channel, guild ?? null);- const nsfwBlockedForMinor = channelIsNsfw && !!currentUser && !currentUser.matureContentAllowed;const canInvite = InviteUtils.canInviteToChannel(channel.id, channel.guildId);const developerMode = UserSettings.developerMode;const isPinned = channel.isPinned;@@ -256,7 +249,6 @@ function getChannelMenuState(channel: Channel, guild: Guild | undefined): ChannehasUnread,canManageChannels,canEditChannel,- nsfwBlockedForMinor,canInvite,developerMode,isPinned,@@ -711,24 +703,21 @@ export function useChannelMenuData(});menuGroups.push({items: notificationItems});if (state.canEditChannel) {- const manageItems: Array<MenuItemType> = [];- if (!state.nsfwBlockedForMinor) {- manageItems.push({+ const manageItems: Array<MenuItemType> = [+ {icon: <SettingsIcon size={20} data-flx="ui.action-menu.items.channel-menu-data.groups.settings-icon" />,label: i18n._(EDIT_CHANNEL_DESCRIPTOR),onClick: handlers.handleChannelSettings,- });- }- if (state.canManageChannels && !state.nsfwBlockedForMinor) {+ },+ ];+ if (state.canManageChannels) {manageItems.push({icon: <CopyIcon size={20} data-flx="ui.action-menu.items.channel-menu-data.groups.copy-icon" />,label: i18n._(DUPLICATE_CHANNEL_DESCRIPTOR),onClick: handlers.handleDuplicateChannel,});}- if (manageItems.length > 0) {- menuGroups.push({items: manageItems});- }+ menuGroups.push({items: manageItems});}const debugItems: Array<MenuItemType> = [];if (state.developerMode) {