Skip to content

Commit 9df5513

Browse files
Merge branch 'develop' into feat/openapi-oauth-apps-get
2 parents ba8b68f + aa05adc commit 9df5513

File tree

66 files changed

+2455
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2455
-131
lines changed

.changeset/loud-chefs-complain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
Fixes `create-p` and `create-c` permissions not being applyed in teams creation

.changeset/lovely-shirts-play.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rocket.chat/rest-typings': patch
3+
'@rocket.chat/meteor': patch
4+
---
5+
6+
Fix an issue where the report exported in the App logs page would not consider the instance id filter

apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/CreateChannelModal.tsx

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,14 @@ import {
2222
ModalFooterControllers,
2323
} from '@rocket.chat/fuselage';
2424
import type { TranslationKey } from '@rocket.chat/ui-contexts';
25-
import {
26-
useSetting,
27-
useTranslation,
28-
useEndpoint,
29-
usePermission,
30-
useToastMessageDispatch,
31-
usePermissionWithScopedRoles,
32-
} from '@rocket.chat/ui-contexts';
25+
import { useSetting, useTranslation, useEndpoint, useToastMessageDispatch, usePermissionWithScopedRoles } from '@rocket.chat/ui-contexts';
3326
import type { ComponentProps, ReactElement } from 'react';
3427
import { useId, useEffect, useMemo } from 'react';
3528
import { useForm, Controller } from 'react-hook-form';
3629

3730
import { useEncryptedRoomDescription } from './useEncryptedRoomDescription';
3831
import UserAutoCompleteMultipleFederated from '../../../components/UserAutoCompleteMultiple/UserAutoCompleteMultipleFederated';
32+
import { useCreateChannelTypePermission } from '../../../hooks/useCreateChannelTypePermission';
3933
import { useHasLicenseModule } from '../../../hooks/useHasLicenseModule';
4034
import { goToRoomById } from '../../../lib/utils/goToRoomById';
4135

@@ -75,8 +69,6 @@ const CreateChannelModal = ({ teamId = '', onClose, reload }: CreateChannelModal
7569
const federationEnabled = useSetting('Federation_Matrix_enabled', false);
7670
const e2eEnabledForPrivateByDefault = useSetting('E2E_Enabled_Default_PrivateRooms') && e2eEnabled;
7771

78-
const canCreateChannel = usePermission('create-c');
79-
const canCreatePrivateChannel = usePermission('create-p');
8072
const getEncryptedHint = useEncryptedRoomDescription('channel');
8173

8274
const channelNameRegex = useMemo(() => new RegExp(`^${namesValidation}$`), [namesValidation]);
@@ -89,15 +81,7 @@ const CreateChannelModal = ({ teamId = '', onClose, reload }: CreateChannelModal
8981

9082
const dispatchToastMessage = useToastMessageDispatch();
9183

92-
const canOnlyCreateOneType = useMemo(() => {
93-
if (!canCreateChannel && canCreatePrivateChannel) {
94-
return 'p';
95-
}
96-
if (canCreateChannel && !canCreatePrivateChannel) {
97-
return 'c';
98-
}
99-
return false;
100-
}, [canCreateChannel, canCreatePrivateChannel]);
84+
const canOnlyCreateOneType = useCreateChannelTypePermission();
10185

10286
const {
10387
register,
@@ -272,7 +256,7 @@ const CreateChannelModal = ({ teamId = '', onClose, reload }: CreateChannelModal
272256
id={privateId}
273257
aria-describedby={`${privateId}-hint`}
274258
ref={ref}
275-
checked={value}
259+
checked={canOnlyCreateOneType ? canOnlyCreateOneType === 'p' : value}
276260
disabled={!!canOnlyCreateOneType}
277261
onChange={onChange}
278262
/>

apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/CreateTeamModal.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { Controller, useForm } from 'react-hook-form';
3838

3939
import { useEncryptedRoomDescription } from './useEncryptedRoomDescription';
4040
import UserAutoCompleteMultiple from '../../../components/UserAutoCompleteMultiple';
41+
import { useCreateChannelTypePermission } from '../../../hooks/useCreateChannelTypePermission';
4142
import { goToRoomById } from '../../../lib/utils/goToRoomById';
4243

4344
type CreateTeamModalInputs = {
@@ -76,6 +77,8 @@ const CreateTeamModal = ({ onClose }: CreateTeamModalProps) => {
7677
return new RegExp(`^${namesValidation}$`);
7778
}, [allowSpecialNames, namesValidation]);
7879

80+
const canOnlyCreateOneType = useCreateChannelTypePermission();
81+
7982
const validateTeamName = async (name: string): Promise<string | undefined> => {
8083
if (!name) {
8184
return;
@@ -100,7 +103,7 @@ const CreateTeamModal = ({ onClose }: CreateTeamModalProps) => {
100103
formState: { errors, isSubmitting },
101104
} = useForm<CreateTeamModalInputs>({
102105
defaultValues: {
103-
isPrivate: true,
106+
isPrivate: canOnlyCreateOneType ? canOnlyCreateOneType === 'p' : true,
104107
readOnly: false,
105108
encrypted: (e2eEnabledForPrivateByDefault as boolean) ?? false,
106109
broadcast: false,
@@ -244,7 +247,14 @@ const CreateTeamModal = ({ onClose }: CreateTeamModalProps) => {
244247
control={control}
245248
name='isPrivate'
246249
render={({ field: { onChange, value, ref } }): ReactElement => (
247-
<ToggleSwitch id={privateId} aria-describedby={`${privateId}-hint`} onChange={onChange} checked={value} ref={ref} />
250+
<ToggleSwitch
251+
id={privateId}
252+
aria-describedby={`${privateId}-hint`}
253+
onChange={onChange}
254+
checked={canOnlyCreateOneType ? canOnlyCreateOneType === 'p' : value}
255+
disabled={!!canOnlyCreateOneType}
256+
ref={ref}
257+
/>
248258
)}
249259
/>
250260
</FieldRow>

apps/meteor/client/NavBarV2/NavBarPagesGroup/hooks/useCreateNewItems.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ export const useCreateNewItems = (): GenericMenuItemProps[] => {
6363
...(canCreateDirectMessages ? [createDirectMessageItem] : []),
6464
...(canCreateDiscussion && discussionEnabled ? [createDiscussionItem] : []),
6565
...(canCreateChannel ? [createChannelItem] : []),
66-
...(canCreateTeam ? [createTeamItem] : []),
66+
...(canCreateTeam && canCreateChannel ? [createTeamItem] : []),
6767
];
6868
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { IRoom } from '@rocket.chat/core-typings';
2+
import { usePermission } from '@rocket.chat/ui-contexts';
3+
import { useMemo } from 'react';
4+
5+
/**
6+
* Determines if a user's permissions restrict them to creating only one type of channel.
7+
*
8+
* This hook checks a user's permissions for creating public and private channels,
9+
* either globally or within a specific team. It returns a string indicating the
10+
* single channel type they can create, or `false` if they can create both or neither.
11+
*
12+
* @param {string} [teamRoomId] The optional ID of the main team room to check for team-specific permissions.
13+
* @returns {'c' | 'p' | false} A string ('c' or 'p') if the user can only create one channel type, otherwise `false`.
14+
*/
15+
export const useCreateChannelTypePermission = (teamRoomId?: IRoom['_id']) => {
16+
const canCreateChannel = usePermission('create-c');
17+
const canCreatePrivateChannel = usePermission('create-p');
18+
19+
const canCreateTeamChannel = usePermission('create-team-channel', teamRoomId);
20+
const canCreateTeamGroup = usePermission('create-team-group', teamRoomId);
21+
22+
return useMemo(() => {
23+
if (teamRoomId) {
24+
if (!canCreateTeamChannel && canCreateTeamGroup) {
25+
return 'p';
26+
}
27+
28+
if (canCreateTeamChannel && !canCreateTeamGroup) {
29+
return 'c';
30+
}
31+
}
32+
33+
if (!canCreateChannel && canCreatePrivateChannel) {
34+
return 'p';
35+
}
36+
37+
if (canCreateChannel && !canCreatePrivateChannel) {
38+
return 'c';
39+
}
40+
return false;
41+
}, [canCreateChannel, canCreatePrivateChannel, canCreateTeamChannel, canCreateTeamGroup, teamRoomId]);
42+
};

apps/meteor/client/sidebar/header/CreateChannel/CreateChannelModal.tsx

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,13 @@ import {
2323
ModalFooterControllers,
2424
} from '@rocket.chat/fuselage';
2525
import type { TranslationKey } from '@rocket.chat/ui-contexts';
26-
import {
27-
useSetting,
28-
useTranslation,
29-
useEndpoint,
30-
usePermission,
31-
useToastMessageDispatch,
32-
usePermissionWithScopedRoles,
33-
} from '@rocket.chat/ui-contexts';
26+
import { useSetting, useTranslation, useEndpoint, useToastMessageDispatch, usePermissionWithScopedRoles } from '@rocket.chat/ui-contexts';
3427
import type { ComponentProps, ReactElement } from 'react';
3528
import { useId, useEffect, useMemo } from 'react';
3629
import { useForm, Controller } from 'react-hook-form';
3730

3831
import UserAutoCompleteMultipleFederated from '../../../components/UserAutoCompleteMultiple/UserAutoCompleteMultipleFederated';
32+
import { useCreateChannelTypePermission } from '../../../hooks/useCreateChannelTypePermission';
3933
import { useHasLicenseModule } from '../../../hooks/useHasLicenseModule';
4034
import { goToRoomById } from '../../../lib/utils/goToRoomById';
4135
import { useEncryptedRoomDescription } from '../hooks/useEncryptedRoomDescription';
@@ -77,8 +71,6 @@ const CreateChannelModal = ({ teamId = '', mainRoom, onClose, reload }: CreateCh
7771
const federationEnabled = useSetting('Federation_Matrix_enabled', false);
7872
const e2eEnabledForPrivateByDefault = useSetting('E2E_Enabled_Default_PrivateRooms') && e2eEnabled;
7973

80-
const canCreateChannel = usePermission('create-c');
81-
const canCreateGroup = usePermission('create-p');
8274
const getEncryptedHint = useEncryptedRoomDescription('channel');
8375

8476
const channelNameRegex = useMemo(() => new RegExp(`^${namesValidation}$`), [namesValidation]);
@@ -89,20 +81,9 @@ const CreateChannelModal = ({ teamId = '', mainRoom, onClose, reload }: CreateCh
8981
const createChannel = useEndpoint('POST', '/v1/channels.create');
9082
const createPrivateChannel = useEndpoint('POST', '/v1/groups.create');
9183

92-
const canCreateTeamChannel = usePermission('create-team-channel', mainRoom?._id);
93-
const canCreateTeamGroup = usePermission('create-team-group', mainRoom?._id);
94-
9584
const dispatchToastMessage = useToastMessageDispatch();
9685

97-
const canOnlyCreateOneType = useMemo(() => {
98-
if ((!teamId && !canCreateChannel && canCreateGroup) || (teamId && !canCreateTeamChannel && canCreateTeamGroup)) {
99-
return 'p';
100-
}
101-
if ((!teamId && canCreateChannel && !canCreateGroup) || (teamId && canCreateTeamChannel && !canCreateTeamGroup)) {
102-
return 'c';
103-
}
104-
return false;
105-
}, [canCreateChannel, canCreateGroup, canCreateTeamChannel, canCreateTeamGroup, teamId]);
86+
const canOnlyCreateOneType = useCreateChannelTypePermission(mainRoom?._id);
10687

10788
const {
10889
register,

apps/meteor/client/sidebar/header/CreateTeam/CreateTeamModal.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { useId, memo, useEffect, useMemo } from 'react';
3434
import { Controller, useForm } from 'react-hook-form';
3535

3636
import UserAutoCompleteMultiple from '../../../components/UserAutoCompleteMultiple';
37+
import { useCreateChannelTypePermission } from '../../../hooks/useCreateChannelTypePermission';
3738
import { goToRoomById } from '../../../lib/utils/goToRoomById';
3839
import { useEncryptedRoomDescription } from '../hooks/useEncryptedRoomDescription';
3940

@@ -68,6 +69,8 @@ const CreateTeamModal = ({ onClose }: { onClose: () => void }): ReactElement =>
6869
return new RegExp(`^${namesValidation}$`);
6970
}, [allowSpecialNames, namesValidation]);
7071

72+
const canOnlyCreateOneType = useCreateChannelTypePermission();
73+
7174
const validateTeamName = async (name: string): Promise<string | undefined> => {
7275
if (!name) {
7376
return;
@@ -92,7 +95,7 @@ const CreateTeamModal = ({ onClose }: { onClose: () => void }): ReactElement =>
9295
formState: { errors, isSubmitting },
9396
} = useForm<CreateTeamModalInputs>({
9497
defaultValues: {
95-
isPrivate: true,
98+
isPrivate: canOnlyCreateOneType ? canOnlyCreateOneType === 'p' : true,
9699
readOnly: false,
97100
encrypted: (e2eEnabledForPrivateByDefault as boolean) ?? false,
98101
broadcast: false,
@@ -228,7 +231,14 @@ const CreateTeamModal = ({ onClose }: { onClose: () => void }): ReactElement =>
228231
control={control}
229232
name='isPrivate'
230233
render={({ field: { onChange, value, ref } }): ReactElement => (
231-
<ToggleSwitch id={privateId} aria-describedby={`${privateId}-hint`} onChange={onChange} checked={value} ref={ref} />
234+
<ToggleSwitch
235+
id={privateId}
236+
aria-describedby={`${privateId}-hint`}
237+
onChange={onChange}
238+
checked={canOnlyCreateOneType ? canOnlyCreateOneType === 'p' : value}
239+
disabled={!!canOnlyCreateOneType}
240+
ref={ref}
241+
/>
232242
)}
233243
/>
234244
</FieldRow>

apps/meteor/client/sidebar/header/actions/hooks/useCreateRoomItems.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ export const useCreateRoomItems = (): GenericMenuItemProps[] => {
6363
...(canCreateDirectMessages ? [createDirectMessageItem] : []),
6464
...(canCreateDiscussion && discussionEnabled ? [createDiscussionItem] : []),
6565
...(canCreateChannel ? [createChannelItem] : []),
66-
...(canCreateTeam ? [createTeamItem] : []),
66+
...(canCreateTeam && canCreateChannel ? [createTeamItem] : []),
6767
];
6868
};

apps/meteor/client/views/e2e/EnterE2EPasswordModal.tsx

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)