tethys.backend/app/validators/role.ts
Arno Kaimbacher b5bbe26ec2
Some checks failed
build.yaml / feat: Enhance background job settings UI and functionality (push) Failing after 0s
feat: Enhance background job settings UI and functionality
- Updated BackgroundJob.vue to improve the display of background job statuses, including missing cross-references and current job mode.
- Added auto-refresh functionality for background job status.
- Introduced success toast notifications for successful status refreshes.
- Modified the XML serialization process in DatasetXmlSerializer for better caching and performance.
- Implemented a new RuleProvider for managing custom validation rules.
- Improved error handling in routes for loading background job settings.
- Enhanced ClamScan configuration with socket support for virus scanning.
- Refactored dayjs utility to streamline locale management.
2025-10-14 12:19:09 +02:00

71 lines
2.5 KiB
TypeScript

import vine, { SimpleMessagesProvider } from '@vinejs/vine';
/**
* Validates the role's creation action
* node ace make:validator role
*/
export const createRoleValidator = vine.compile(
vine.object({
name: vine
.string()
.trim()
.minLength(3)
.maxLength(255)
.isUnique({ table: 'roles', column: 'name' })
.regex(/^[a-zA-Z0-9]+$/), // Must be alphanumeric
display_name: vine
.string()
.trim()
.minLength(3)
.maxLength(255)
.isUnique({ table: 'roles', column: 'display_name' })
.regex(/^[a-zA-Z0-9]+$/),
description: vine.string().trim().escape().minLength(3).maxLength(255).optional(),
permissions: vine.array(vine.number()).minLength(1), // At least one permission required
}),
);
export const updateRoleValidator = vine.withMetaData<{ roleId: number }>().compile(
vine.object({
name: vine
.string()
.trim()
.minLength(3)
.maxLength(255)
.isUnique({
table: 'roles',
column: 'name',
whereNot: (field) => field.meta.roleId,
})
.regex(/^[a-zA-Z0-9]+$/),
display_name: vine
.string()
.trim()
.minLength(3)
.maxLength(255)
.isUnique({
table: 'roles',
column: 'display_name',
whereNot: (field) => field.meta.roleId,
})
.regex(/^[a-zA-Z0-9]+$/),
description: vine.string().trim().escape().minLength(3).maxLength(255).optional(),
permissions: vine.array(vine.number()).minLength(1), // At least one permission required
}),
);
let messagesProvider = new SimpleMessagesProvider({
// Applicable for all fields
'required': 'The {{ field }} field is required',
'unique': '{{ field }} must be unique, and this value is already taken',
'string': 'The value of {{ field }} field must be a string',
'email': 'The value is not a valid email address',
// 'contacts.0.email.required': 'The primary email of the contact is required',
// 'contacts.*.email.required': 'Contact email is required',
'permissions.minLength': 'at least {{min }} permission must be defined',
'permissions.*.number': 'Define permissions as valid numbers',
});
createRoleValidator.messagesProvider = messagesProvider;
updateRoleValidator.messagesProvider = messagesProvider;