- added LicenseController.ts and MimetypeController for enabling mime_types and licences
Some checks failed
CI Pipeline / japa-tests (push) Failing after 58s

- add new authors and contributors only by unique email addresses
- allow multiple file upload
- added validation rule for validating length of uploaded files
- modified Dockerfile for starting "bin/server.js" instead of *server.js"
- npm updates
This commit is contained in:
Kaimbacher 2024-06-14 12:38:04 +02:00
parent 770e791613
commit ac473b1e72
27 changed files with 1720 additions and 914 deletions

View file

@ -134,7 +134,7 @@ export default class AdminuserController {
// validate update form
await request.validateUsing(updateUserValidator, {
meta: {
userId: user.id,
objId: user.id,
},
});
@ -166,8 +166,8 @@ export default class AdminuserController {
return response.redirect().toRoute('settings.user.index');
}
// private async syncRoles(userId: number, roleIds: Array<number>) {
// const user = await User.findOrFail(userId)
// private async syncRoles(objId: number, roleIds: Array<number>) {
// const user = await User.findOrFail(objId)
// // const roles: Role[] = await Role.query().whereIn('id', roleIds);
// // await user.roles().sync(roles.rows.map(role => role.id))

View file

@ -0,0 +1,51 @@
import type { HttpContext } from '@adonisjs/core/http';
import License from '#models/license';
export default class LicenseController {
public async index({ auth, inertia }: HttpContext) {
const direction = 'asc'; // or 'desc'
const licenses = await License.query().orderBy('sort_order', direction).exec();
return inertia.render('Admin/License/Index', {
licenses: licenses,
can: {
edit: await auth.user?.can(['settings']),
},
});
}
public async down({ request, response }: HttpContext) {
const id = request.param('id');
const license = await License.findOrFail(id);
license.active = false;
await license.save();
// session.flash({ message: 'person has been deactivated!' });
return response.flash('person has been deactivated!', 'message').toRoute('settings.license.index')
}
public async up({ request, response }: HttpContext) {
const id = request.param('id');
const license = await License.findOrFail(id);
license.active = true;
await license.save();
// session.flash({ message: 'person has been activated!' });
return response.flash('person has been activated!', 'message').toRoute('settings.license.index');
}
// public async edit({ request, inertia }: HttpContext) {
// const id = request.param('id');
// const license = await License.query().where('id', id).firstOrFail();
// // const permissions = await Permission.query().pluck('name', 'id');
// // // const userHasRoles = user.roles;
// // const rolerHasPermissions = await role.related('permissions').query().orderBy('name').pluck('id');
// return inertia.render('Admin/License/Edit', {
// // permissions: permissions,
// license: license,
// // roleHasPermissions: Object.keys(rolerHasPermissions).map((key) => rolerHasPermissions[key]), //convert object to array with role ids
// });
// }
}

View file

@ -0,0 +1,51 @@
import type { HttpContext } from '@adonisjs/core/http';
import MimeType from '#models/mime_type';
export default class MimetypeController {
public async index({ auth, inertia }: HttpContext) {
const direction = 'asc'; // or 'desc'
const mimetypes = await MimeType.query().orderBy('name', direction).exec();
return inertia.render('Admin/Mimetype/Index', {
mimetypes: mimetypes,
can: {
edit: await auth.user?.can(['settings']),
},
});
}
public async down({ request, response }: HttpContext) {
const id = request.param('id');
const mimetype = await MimeType.findOrFail(id);
mimetype.enabled = false;
await mimetype .save();
// session.flash({ message: 'person has been deactivated!' });
return response.flash('mimetype has been deactivated!', 'message').toRoute('settings.mimetype.index')
}
public async up({ request, response }: HttpContext) {
const id = request.param('id');
const mimetype = await MimeType.findOrFail(id);
mimetype.enabled = true;
await mimetype .save();
// session.flash({ message: 'person has been activated!' });
return response.flash('mimetype has been activated!', 'message').toRoute('settings.mimetype.index');
}
// public async edit({ request, inertia }: HttpContext) {
// const id = request.param('id');
// const license = await License.query().where('id', id).firstOrFail();
// // const permissions = await Permission.query().pluck('name', 'id');
// // // const userHasRoles = user.roles;
// // const rolerHasPermissions = await role.related('permissions').query().orderBy('name').pluck('id');
// return inertia.render('Admin/License/Edit', {
// // permissions: permissions,
// license: license,
// // roleHasPermissions: Object.keys(rolerHasPermissions).map((key) => rolerHasPermissions[key]), //convert object to array with role ids
// });
// }
}

View file

@ -216,18 +216,24 @@ export default class DatasetController {
authors: vine
.array(
vine.object({
email: vine.string().trim().maxLength(255).email().normalizeEmail(),
email: vine.string().trim().maxLength(255).email().normalizeEmail().isUniquePerson({ table: 'persons', column: 'email', idField: 'id' }),
first_name: vine.string().trim().minLength(3).maxLength(255),
last_name: vine.string().trim().minLength(3).maxLength(255),
}),
)
.minLength(1),
.minLength(1)
.distinct('email'),
contributors: vine
.array(
vine.object({
email: vine.string().trim().maxLength(255).email().normalizeEmail(),
email: vine.string().trim().maxLength(255).email().normalizeEmail().isUniquePerson({ table: 'persons', column: 'email', idField: 'id' }),
first_name: vine.string().trim().minLength(3).maxLength(255),
last_name: vine.string().trim().minLength(3).maxLength(255),
pivot_contributor_type: vine.enum(Object.keys(ContributorTypes)),
}),
)
.optional(),
.distinct('email')
.optional(),
project_id: vine.number().optional(),
});
@ -287,18 +293,24 @@ export default class DatasetController {
authors: vine
.array(
vine.object({
email: vine.string().trim().maxLength(255).email().normalizeEmail(),
email: vine.string().trim().maxLength(255).email().normalizeEmail().isUniquePerson({ table: 'persons', column: 'email', idField: 'id' }),
first_name: vine.string().trim().minLength(3).maxLength(255),
last_name: vine.string().trim().minLength(3).maxLength(255),
}),
)
.minLength(1),
.minLength(1)
.distinct('email'),
contributors: vine
.array(
vine.object({
email: vine.string().trim().maxLength(255).email().normalizeEmail(),
email: vine.string().trim().maxLength(255).email().normalizeEmail().isUniquePerson({ table: 'persons', column: 'email', idField: 'id' }),
first_name: vine.string().trim().minLength(3).maxLength(255),
last_name: vine.string().trim().minLength(3).maxLength(255),
pivot_contributor_type: vine.enum(Object.keys(ContributorTypes)),
}),
)
.optional(),
.distinct('email')
.optional(),
// third step
project_id: vine.number().optional(),
// embargo_date: schema.date.optional({ format: 'yyyy-MM-dd' }, [rules.after(10, 'days')]),
@ -631,7 +643,9 @@ export default class DatasetController {
'The language of the translated description must be different from the language of the dataset',
'authors.array.minLength': 'at least {{ min }} author must be defined',
'authors.distinct': 'The {{ field }} array must have unique values based on the {{ fields }} attribute.',
'contributors.*.pivot_contributor_type.required': 'contributor type is required, if defined',
'contributors.distinct': 'The {{ field }} array must have unique values based on the {{ fields }} attribute.',
'after': `{{ field }} must be older than ${dayjs().add(10, 'day')}`,