后端移除所有权限模块
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
||||
import { CanActivate, ExecutionContext, Injectable, RequestTimeoutException } from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { RoleService } from 'src/role/services/role.service';
|
||||
import { UserRoleService } from 'src/role/services/user-role.service';
|
||||
|
||||
@Injectable()
|
||||
export class RolesGuard implements CanActivate {
|
||||
constructor(
|
||||
private reflector: Reflector,
|
||||
private readonly userRoleService: UserRoleService,
|
||||
private readonly roleService: RoleService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const requiredRoles = this.reflector.getAllAndOverride<string[]>('roles', [
|
||||
@@ -24,14 +20,9 @@ export class RolesGuard implements CanActivate {
|
||||
|
||||
if (!userId) return false;
|
||||
|
||||
// 查询用户拥有的有效角色Id
|
||||
const userRoleIds =
|
||||
await this.userRoleService.findValidRoleIdsByUserId(userId);
|
||||
// 查询用户拥有的有效角色Id TODO
|
||||
|
||||
// 查询用户角色Id对应的角色名
|
||||
const userRoleNames =
|
||||
await this.roleService.findRoleNamesByRoleIds(userRoleIds);
|
||||
|
||||
return requiredRoles.some((role) => userRoleNames.includes(role));
|
||||
// return requiredRoles.some((role) => userRoleNames.includes(role));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user