diff --git a/app/models/user.py b/app/models/user.py
@@ -107,10 +107,7 @@ class UserCreate(User):
)
if self.expire:
raise ValueError("User cannot be on hold with specified expire.")
- elif self.status == UserStatusCreate.active:
- if not self.expire:
- raise ValueError("expire field should be set when status is active.")
- if self.on_hold_expire_duration or self.on_hold_timeout:
+ elif self.status == UserStatusCreate.active and (self.on_hold_expire_duration or self.on_hold_timeout):
raise ValueError(
"on hold parametrs set when user status isn't on_hold."
)
diff --git a/dashboard/src/features/users/dialogs/mutation/index.tsx b/dashboard/src/features/users/dialogs/mutation/index.tsx
@@ -87,6 +87,7 @@ export const UsersMutationDialog: FC<UsersMutationDialogProps> = ({
else
return 'unlimited'
}, [])
+
const defaultExpirationMethodTab = entity?.username ? getUserExpirationMethod(entity) : 'determined'
const [
selectedExpirationMethodTab,
@@ -100,8 +101,8 @@ export const UsersMutationDialog: FC<UsersMutationDialogProps> = ({
form.setValue("expire", null);
form.clearErrors("expire");
} else if (selectedExpirationMethodTab === "unlimited") {
- form.setValue("expire", 0);
- form.setValue("on_hold_expire_duration", 0);
+ form.setValue("expire", undefined);
+ form.setValue("on_hold_expire_duration", undefined);
form.setValue("on_hold_timeout", undefined);
form.clearErrors("expire");
form.clearErrors("on_hold_expire_duration");
diff --git a/dashboard/src/features/users/dialogs/mutation/schema.ts b/dashboard/src/features/users/dialogs/mutation/schema.ts
@@ -8,14 +8,15 @@ export const UserSchema = z.object({
.min(0, 'The minimum number is 0')
.or(z.number())
.nullable()
+ .optional()
.transform((str) => {
if (str) return Number((parseFloat(String(str)) * 1073741824).toFixed(5));
return 0;
}),
- expire: z.string().nullable(),
- data_limit_reset_strategy: z.string().nullable(),
+ expire: z.string().or(z.number()).nullable().optional(),
+ data_limit_reset_strategy: z.string().nullable().optional(),
status: z.string(),
- on_hold_expire_duration: z.number().nullable(),
+ on_hold_expire_duration: z.number().nullable().optional(),
on_hold_timeout: z.string().nullable().optional(),
services: z.array(z.number().or(z.string())).nonempty({ message: 'At least one service is required' })
.transform((v) => v.map(Number)),