Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ model User {
dateOfBirth DateTime? @db.Date
phoneNumber String?
email String?
disabled Boolean?

@@map("UserModel")
}
Expand Down
5 changes: 5 additions & 0 deletions apps/api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export class AuthService {
}
throw err;
}

if (user.disabled) {
throw new ForbiddenException('Account Disabled');
}

const isCorrectPassword = await this.cryptoService.comparePassword(credentials.password, user.hashedPassword);
if (isCorrectPassword !== true) {
throw new UnauthorizedException('Invalid Credentials');
Expand Down
3 changes: 3 additions & 0 deletions apps/api/src/users/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class CreateUserDto implements CreateUserData {
@ApiProperty({ description: 'Date of Birth' })
dateOfBirth?: Date;

@ApiProperty({ description: 'Disabled' })
disabled?: boolean;

@ApiProperty({ description: 'Email' })
email?: string;

Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class UsersService {
{
basePermissionLevel,
dateOfBirth,
disabled,
email,
firstName,
groupIds,
Expand Down Expand Up @@ -84,6 +85,7 @@ export class UsersService {
additionalPermissions: [],
basePermissionLevel,
dateOfBirth,
disabled,
email,
firstName,
groups: {
Expand Down
15 changes: 15 additions & 0 deletions apps/web/src/routes/_app/admin/users/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ const RouteComponent = () => {
},
variant: 'select'
},
disabled: {
kind: 'boolean',
description: t({
en: 'Use this option if the user is not intended to log in, for example, when the account is used solely to identify the author of uploaded data.',
fr: 'Utilisez cette option si l’utilisateur n’a pas vocation à se connecter, par exemple lorsque le compte sert uniquement à identifier l’auteur de données téléversées.'
}),
label: t({
en: 'Disabled',
fr: 'Désactivé'
}),
variant: 'radio'
},
groupIds: {
kind: 'dynamic',
deps: ['basePermissionLevel'],
Expand Down Expand Up @@ -161,6 +173,9 @@ const RouteComponent = () => {
})
}
]}
initialValues={{
disabled: false
}}
validationSchema={$CreateUserData
.omit({
groupIds: true
Expand Down
19 changes: 18 additions & 1 deletion apps/web/src/routes/_app/admin/users/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { PHONE_REGEX } from '@/utils/validation';
type UpdateUserFormData = {
additionalPermissions?: Partial<UserPermission>[];
confirmPassword?: string | undefined;
disabled?: boolean;
email?: string | undefined;
groupIds: Set<string>;
password?: string | undefined;
Expand Down Expand Up @@ -52,6 +53,7 @@ const UpdateUserForm: React.FC<{
.object({
additionalPermissions: z.array($UserPermission.partial()).optional(),
confirmPassword: z.string().min(1).optional(),
disabled: z.boolean().optional(),
email: z.union([z.literal(''), z.email()]).optional(),
groupIds: z.set(z.string()),
password: z.string().min(1).optional(),
Expand Down Expand Up @@ -240,6 +242,18 @@ const UpdateUserForm: React.FC<{
en: 'Permission',
fr: 'Autorisation'
})
},
disabled: {
description: t({
en: 'Use this option if the user is not intended to log in, for example, when the account is used solely to identify the author of uploaded data.',
fr: 'Utilisez cette option si l’utilisateur n’a pas vocation à se connecter, par exemple lorsque le compte sert uniquement à identifier l’auteur de données téléversées.'
}),
kind: 'boolean',
label: t({
en: 'Disabled',
fr: 'Désactivé'
}),
variant: 'radio'
}
},
title: t({
Expand All @@ -263,7 +277,10 @@ const UpdateUserForm: React.FC<{
}
]}
data-testid="update-user-form"
initialValues={initialValues}
initialValues={{
...initialValues,
disabled: initialValues?.disabled ?? false
}}
key={JSON.stringify(initialValues)}
submitBtnLabel={t('core.save')}
validationSchema={$UpdateUserFormData}
Expand Down
2 changes: 2 additions & 0 deletions packages/schemas/src/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const $User = $BaseModel.extend({
additionalPermissions: $Permissions,
basePermissionLevel: $BasePermissionLevel.nullable(),
dateOfBirth: z.coerce.date().nullish(),
disabled: z.boolean().nullish(),
email: z.email().nullish(),
firstName: z.string().min(1),
groupIds: z.array(z.string()),
Expand All @@ -32,6 +33,7 @@ export const $CreateUserData = $User
})
.extend({
dateOfBirth: z.coerce.date().optional(),
disabled: z.boolean().optional(),
email: z.email().optional(),
password: z.string().min(1),
phoneNumber: z.string().optional(),
Expand Down
Loading