fix: Don't show join default channels option for edit user form (#31750)

pull/32469/head
Yash Rajpal 2 years ago committed by GitHub
parent 760ab4be21
commit 07c4ca0621
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      .changeset/real-bobcats-train.md
  2. 38
      apps/meteor/client/views/admin/users/AdminUserForm.tsx
  3. 20
      apps/meteor/tests/e2e/administration.spec.ts
  4. 8
      apps/meteor/tests/e2e/page-objects/admin.ts
  5. 4
      apps/meteor/tests/e2e/page-objects/fragments/admin-flextab-users.ts

@ -0,0 +1,6 @@
---
'@rocket.chat/rest-typings': patch
'@rocket.chat/meteor': patch
---
Don't show Join default channels option on edit user form.

@ -52,10 +52,12 @@ const getInitialValue = ({
data,
defaultUserRoles,
isSmtpEnabled,
isEditingExistingUser,
}: {
data?: Serialized<IUser>;
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) => {
<>
<ContextualbarScrollableContent {...props}>
<FieldGroup>
{userData?._id && (
{isEditingExistingUser && (
<Field>
<Controller
name='avatar'
@ -346,7 +350,7 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => {
<Controller
control={control}
name='password'
rules={{ required: !userData?._id && t('The_field_is_required', t('Password')) }}
rules={{ required: !isEditingExistingUser && t('The_field_is_required', t('Password')) }}
render={({ field }) => (
<PasswordInput
{...field}
@ -434,18 +438,20 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => {
</FieldRow>
{errors?.roles && <FieldError>{errors.roles.message}</FieldError>}
</Field>
<Field>
<FieldRow>
<FieldLabel htmlFor={joinDefaultChannelsId}>{t('Join_default_channels')}</FieldLabel>
<Controller
control={control}
name='joinDefaultChannels'
render={({ field: { ref, onChange, value } }) => (
<ToggleSwitch id={joinDefaultChannelsId} ref={ref} onChange={onChange} checked={value} />
)}
/>
</FieldRow>
</Field>
{!isEditingExistingUser && (
<Field>
<FieldRow>
<FieldLabel htmlFor={joinDefaultChannelsId}>{t('Join_default_channels')}</FieldLabel>
<Controller
control={control}
name='joinDefaultChannels'
render={({ field: { ref, onChange, value } }) => (
<ToggleSwitch id={joinDefaultChannelsId} ref={ref} onChange={onChange} checked={value} />
)}
/>
</FieldRow>
</Field>
)}
<Field>
<FieldRow>
<FieldLabel htmlFor={sendWelcomeEmailId}>{t('Send_welcome_email')}</FieldLabel>

@ -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', () => {

@ -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`);
}

@ -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")');
}

Loading…
Cancel
Save