forked from geolba/tethys.backend
- update to AdonisJS 6
This commit is contained in:
parent
f828ca4491
commit
cb51a4136f
167 changed files with 21485 additions and 21212 deletions
|
@ -1,13 +1,14 @@
|
|||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
||||
import Config from '@ioc:Adonis/Core/Config';
|
||||
import Database from '@ioc:Adonis/Lucid/Database';
|
||||
import User from 'App/Models/User';
|
||||
import { Exception } from '@adonisjs/core/build/standalone';
|
||||
import { HttpContext } from '@adonisjs/core/http';
|
||||
// import Config from '@ioc:Adonis/Core/Config';
|
||||
import config from '@adonisjs/core/services/config';
|
||||
import db from '@adonisjs/lucid/services/db';
|
||||
import User from '#app/Models/User';
|
||||
import { Exception } from '@adonisjs/core/exceptions';
|
||||
|
||||
const permissionTable = Config.get('rolePermission.permission_table', 'permissions');
|
||||
const rolePermissionTable = Config.get('rolePermission.role_permission_table', 'role_has_permissions');
|
||||
const roleTable = Config.get('rolePermission.role_table', 'roles');
|
||||
const userRoleTable = Config.get('rolePermission.user_role_table', 'link_accounts_roles');
|
||||
const permissionTable = config.get('rolePermission.permission_table', 'permissions');
|
||||
const rolePermissionTable = config.get('rolePermission.role_permission_table', 'role_has_permissions');
|
||||
const roleTable = config.get('rolePermission.role_table', 'roles');
|
||||
const userRoleTable = config.get('rolePermission.user_role_table', 'link_accounts_roles');
|
||||
|
||||
/**
|
||||
* Permission authentication to check if user has any of the specified permissions
|
||||
|
@ -18,7 +19,7 @@ export default class Can {
|
|||
/**
|
||||
* Handle request
|
||||
*/
|
||||
public async handle({ auth, response }: HttpContextContract, next: () => Promise<void>, permissionNames: string[]) {
|
||||
public async handle({ auth, response }: HttpContext, next: () => Promise<void>, permissionNames: string[]) {
|
||||
/**
|
||||
* Check if user is logged-in
|
||||
*/
|
||||
|
@ -31,9 +32,10 @@ export default class Can {
|
|||
// return response.unauthorized({
|
||||
// error: `Doesn't have required role(s): ${permissionNames.join(',')}`,
|
||||
// });
|
||||
throw new Exception(`Doesn't have required permission(s): ${permissionNames.join(',')}`, 401);
|
||||
throw new Exception(`Doesn't have required permission(s): ${permissionNames.join(',')}`, { status: 401 });
|
||||
}
|
||||
await next();
|
||||
// await next();
|
||||
return next();
|
||||
}
|
||||
|
||||
private async checkHasPermissions(user: User, permissionNames: Array<string>): Promise<boolean> {
|
||||
|
@ -66,7 +68,7 @@ export default class Can {
|
|||
rows: {
|
||||
0: { permissioncount },
|
||||
},
|
||||
} = await Database.rawQuery(
|
||||
} = await db.rawQuery(
|
||||
'SELECT count("p"."name") as permissionCount FROM ' +
|
||||
roleTable +
|
||||
' r INNER JOIN ' +
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue