diff --git a/.changeset/real-bobcats-train.md b/.changeset/real-bobcats-train.md new file mode 100644 index 000000000000..6d51414c9fc4 --- /dev/null +++ b/.changeset/real-bobcats-train.md @@ -0,0 +1,6 @@ +--- +'@rocket.chat/rest-typings': patch +'@rocket.chat/meteor': patch +--- + +Don't show Join default channels option on edit user form. diff --git a/apps/meteor/client/views/admin/users/AdminUserForm.tsx b/apps/meteor/client/views/admin/users/AdminUserForm.tsx index a85754705090..69aeb4e31205 100644 --- a/apps/meteor/client/views/admin/users/AdminUserForm.tsx +++ b/apps/meteor/client/views/admin/users/AdminUserForm.tsx @@ -52,10 +52,12 @@ const getInitialValue = ({ data, defaultUserRoles, isSmtpEnabled, + isEditingExistingUser, }: { data?: Serialized; defaultUserRoles?: IUser['roles']; isSmtpEnabled?: boolean; + isEditingExistingUser?: boolean; }) => ({ roles: data?.roles ?? defaultUserRoles, name: data?.name ?? '', @@ -69,7 +71,7 @@ const getInitialValue = ({ requirePasswordChange: data?.requirePasswordChange || false, customFields: data?.customFields ?? {}, statusText: data?.statusText ?? '', - joinDefaultChannels: true, + ...(!isEditingExistingUser && { joinDefaultChannels: true }), sendWelcomeEmail: isSmtpEnabled, avatar: '' as AvatarObject, }); @@ -97,6 +99,8 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => { const goToUser = useCallback((id) => router.navigate(`/admin/users/info/${id}`), [router]); + const isEditingExistingUser = Boolean(userData?._id); + const { control, watch, @@ -104,7 +108,7 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => { reset, formState: { errors, isDirty }, } = useForm({ - defaultValues: getInitialValue({ data: userData, defaultUserRoles, isSmtpEnabled }), + defaultValues: getInitialValue({ data: userData, defaultUserRoles, isSmtpEnabled, isEditingExistingUser }), mode: 'onBlur', }); @@ -166,7 +170,7 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => { <> - {userData?._id && ( + {isEditingExistingUser && ( { ( { {errors?.roles && {errors.roles.message}} - - - {t('Join_default_channels')} - ( - - )} - /> - - + {!isEditingExistingUser && ( + + + {t('Join_default_channels')} + ( + + )} + /> + + + )} {t('Send_welcome_email')} diff --git a/apps/meteor/tests/e2e/administration.spec.ts b/apps/meteor/tests/e2e/administration.spec.ts index 48657efea73a..c778e165a769 100644 --- a/apps/meteor/tests/e2e/administration.spec.ts +++ b/apps/meteor/tests/e2e/administration.spec.ts @@ -88,6 +88,26 @@ test.describe.parallel('administration', () => { await poAdmin.tabs.users.setupSmtpLink.click(); await expect(page).toHaveURL('/admin/settings/Email'); }); + + test('expect to show join default channels option only when creating new users, not when editing users', async () => { + const username = faker.internet.userName(); + + await poAdmin.tabs.users.btnNewUser.click(); + await poAdmin.tabs.users.inputName.type(faker.person.firstName()); + await poAdmin.tabs.users.inputUserName.type(username); + await poAdmin.tabs.users.inputEmail.type(faker.internet.email()); + await poAdmin.tabs.users.checkboxVerified.click(); + await poAdmin.tabs.users.inputPassword.type('any_password'); + await expect(poAdmin.tabs.users.userRole).toBeVisible(); + await expect(poAdmin.tabs.users.joinDefaultChannels).toBeVisible(); + await poAdmin.tabs.users.btnSave.click(); + + await poAdmin.inputSearchUsers.fill(username); + await poAdmin.getUserRow(username).click(); + await poAdmin.btnEdit.click(); + await expect(poAdmin.tabs.users.inputUserName).toHaveValue(username); + await expect(poAdmin.tabs.users.joinDefaultChannels).not.toBeVisible(); + }); }); test.describe('Rooms', () => { diff --git a/apps/meteor/tests/e2e/page-objects/admin.ts b/apps/meteor/tests/e2e/page-objects/admin.ts index 5f61d2ef43e1..791768778295 100644 --- a/apps/meteor/tests/e2e/page-objects/admin.ts +++ b/apps/meteor/tests/e2e/page-objects/admin.ts @@ -20,10 +20,18 @@ export class Admin { return this.page.locator('[role="link"]', { hasText: name }); } + getUserRow(username?: string): Locator { + return this.page.locator('[role="link"]', { hasText: username }); + } + get btnSave(): Locator { return this.page.locator('button >> text="Save"'); } + get btnEdit(): Locator { + return this.page.locator('button >> text="Edit"'); + } + get privateLabel(): Locator { return this.page.locator(`label >> text=Private`); } diff --git a/apps/meteor/tests/e2e/page-objects/fragments/admin-flextab-users.ts b/apps/meteor/tests/e2e/page-objects/fragments/admin-flextab-users.ts index 23e855b1aa21..d57d6be612c6 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/admin-flextab-users.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/admin-flextab-users.ts @@ -39,6 +39,10 @@ export class AdminFlextabUsers { return this.page.locator('//label[text()="Verified"]'); } + get joinDefaultChannels(): Locator { + return this.page.locator('//label[text()="Join default channels"]'); + } + get userRole(): Locator { return this.page.locator('button[role="option"]:has-text("user")'); }