- added LicenseController.ts and MimetypeController for enabling mime_types and licences
Some checks failed
CI Pipeline / japa-tests (push) Failing after 58s
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:
parent
770e791613
commit
ac473b1e72
27 changed files with 1720 additions and 914 deletions
|
@ -32,6 +32,8 @@ import AuthController from '#controllers/Http/Auth/AuthController';
|
|||
import UserController from '#controllers/Http/Auth/UserController';
|
||||
import AdminuserController from '#controllers/Http/Admin/AdminuserController';
|
||||
import RoleController from '#controllers/Http/Admin/RoleController';
|
||||
import LicenseController from '#controllers/Http/Admin/LicenseController';
|
||||
import MimetypeController from '#controllers/Http/Admin/MimetypeController';
|
||||
|
||||
import DatasetController from '#app/Controllers/Http/Submitter/DatasetController';
|
||||
import PersonController from '#app/Controllers/Http/Submitter/PersonController';
|
||||
|
@ -160,6 +162,17 @@ router.group(() => {
|
|||
// // .as('role.destroy')
|
||||
// // .where('id', Route.matchers.number())
|
||||
// // .use(middleware.can(['user-delete']));
|
||||
|
||||
router.get('/license', [LicenseController, 'index']).as('license.index');
|
||||
// router.get('/license/:id/edit', [LicenseController, 'edit']).as('license.edit').where('id', router.matchers.number()).use(middleware.can(['settings']));
|
||||
router.get('/license/:id/down', [LicenseController, 'down']).as('license.down').where('id', router.matchers.number()).use(middleware.can(['settings']));
|
||||
router.get('/license/:id/up', [LicenseController, 'up']).as('license.up').where('id', router.matchers.number()).use(middleware.can(['settings']));
|
||||
|
||||
router.get('/mimetype', [MimetypeController, 'index']).as('mimetype.index');
|
||||
// router.get('/mimetype/:id/edit', [MimetypeController, 'edit']).as('mimetype.edit').where('id', router.matchers.number()).use(middleware.can(['settings']));
|
||||
router.get('/mimetype/:id/down', [MimetypeController, 'down']).as('mimetype.down').where('id', router.matchers.number()).use(middleware.can(['settings']));
|
||||
router.get('/mimetype/:id/up', [MimetypeController, 'up']).as('mimetype.up').where('id', router.matchers.number()).use(middleware.can(['settings']));
|
||||
|
||||
})
|
||||
.prefix('admin')
|
||||
.as('settings')
|
||||
|
|
51
start/rules/file_length.ts
Normal file
51
start/rules/file_length.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Preloaded File - node ace make:preload rules/translatedLanguage
|
||||
|--------------------------------------------------------------------------
|
||||
|*/
|
||||
|
||||
import { FieldContext } from '@vinejs/vine/types';
|
||||
import vine from '@vinejs/vine';
|
||||
// import { VineString } from '@vinejs/vine';
|
||||
import { VineMultipartFile, isBodyParserFile } from '#providers/vinejs_provider';
|
||||
import type { MultipartFile } from '@adonisjs/core/bodyparser';
|
||||
|
||||
/**
|
||||
* Options accepted by the unique rule
|
||||
*/
|
||||
// type Options = {
|
||||
// mainLanguageField: string;
|
||||
// typeField: string;
|
||||
// };
|
||||
type Options = {
|
||||
// size: string | number;
|
||||
// extnames: string[];
|
||||
clientNameSizeLimit: number
|
||||
};
|
||||
|
||||
async function filenameLength(file: VineMultipartFile | unknown, options: Options, field: FieldContext) {
|
||||
// if (typeof value !== 'string' && typeof value != 'number') {
|
||||
// return;
|
||||
// }
|
||||
if (!isBodyParserFile(file)) {
|
||||
return;
|
||||
}
|
||||
const validatedFile = file as MultipartFile;
|
||||
|
||||
if (validatedFile.clientName.length > options.clientNameSizeLimit) {
|
||||
|
||||
field.report(`Filename length should be less or equal than ${options.clientNameSizeLimit} characters`, 'filenameLength', field);
|
||||
}
|
||||
}
|
||||
|
||||
export const filenameLengthRule = vine.createRule(filenameLength);
|
||||
|
||||
declare module '#providers/vinejs_provider' {
|
||||
interface VineMultipartFile {
|
||||
filenameLength(options: Options): this;
|
||||
}
|
||||
}
|
||||
|
||||
VineMultipartFile.macro('filenameLength', function (this: VineMultipartFile, options: Options) {
|
||||
return this.use(filenameLengthRule(options));
|
||||
});
|
|
@ -30,7 +30,7 @@ async function translatedLanguage(value: unknown, options: Options, field: Field
|
|||
if (typeValue === 'Translated') {
|
||||
if (value === mainLanguage) {
|
||||
// report thattranlated language field is same as main language field of dataset
|
||||
field.report('The tranlated {{ field }} hast the same language seted as dataset language', 'translatedLanguage', field);
|
||||
field.report('The tranlated {{ field }} hast the same language as dataset language', 'translatedLanguage', field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
64
start/rules/unique_person.ts
Normal file
64
start/rules/unique_person.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Preloaded File - node ace make:preload rules/uniquePerson
|
||||
|--------------------------------------------------------------------------
|
||||
|*/
|
||||
|
||||
import { FieldContext } from '@vinejs/vine/types';
|
||||
import db from '@adonisjs/lucid/services/db';
|
||||
import vine from '@vinejs/vine';
|
||||
import { VineString, VineNumber } from '@vinejs/vine';
|
||||
|
||||
/**
|
||||
* Options accepted by the unique rule
|
||||
*/
|
||||
type Options = {
|
||||
table: string;
|
||||
column: string;
|
||||
// whereNot?: ((field: FieldContext) => string);
|
||||
idField: string;
|
||||
};
|
||||
|
||||
|
||||
async function isUniquePerson(value: unknown, options: Options, field: FieldContext) {
|
||||
if (typeof value !== 'string' && typeof value != 'number') {
|
||||
return;
|
||||
}
|
||||
|
||||
// let ignoreId: string | undefined;
|
||||
// if (options.whereNot) {
|
||||
// ignoreId = options.whereNot(field);
|
||||
// }
|
||||
const idValue = vine.helpers.getNestedValue(options.idField, field); //'Main' or 'Translated'
|
||||
|
||||
const builder = db.from(options.table).select(options.column).where(options.column, value);
|
||||
// if existent id, exclide it from validating
|
||||
if (idValue) {
|
||||
builder.whereNot('id', '=', idValue);
|
||||
}
|
||||
const result = await builder.first();
|
||||
if (result) {
|
||||
// report that value is NOT unique
|
||||
field.report('The {{ field }} field is not unique', 'isUnique', field);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const isUniquePersonRule = vine.createRule(isUniquePerson);
|
||||
|
||||
|
||||
declare module '@vinejs/vine' {
|
||||
interface VineString {
|
||||
isUniquePerson(options: Options): this;
|
||||
}
|
||||
interface VineNumber {
|
||||
isUniquePerson(options: Options): this;
|
||||
}
|
||||
}
|
||||
|
||||
VineString.macro('isUniquePerson', function (this: VineString, options: Options) {
|
||||
return this.use(isUniquePersonRule(options));
|
||||
});
|
||||
VineNumber.macro('isUniquePerson', function (this: VineNumber, options: Options) {
|
||||
return this.use(isUniquePersonRule(options));
|
||||
});
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue