fix 更新部门权限BUG #120

This commit is contained in:
cool 2023-06-26 14:03:46 +08:00
parent 8477c28590
commit 7c9d76cbed

View File

@ -5,6 +5,9 @@ import { BaseSysRoleService } from './role';
import { BaseSysDepartmentService } from './department';
import { Context } from '@midwayjs/koa';
import { CacheManager } from '@midwayjs/cache';
import { BaseSysRoleEntity } from '../../entity/sys/role';
import { In, Repository } from 'typeorm';
import { InjectEntityModel } from '@midwayjs/typeorm';
/**
*
@ -23,8 +26,12 @@ export class BaseSysPermsService extends BaseService {
@Inject()
baseSysDepartmentService: BaseSysDepartmentService;
@InjectEntityModel(BaseSysRoleEntity)
baseSysRoleEntity: Repository<BaseSysRoleEntity>;
@Inject()
ctx: Context;
base: any;
/**
*
@ -37,11 +44,21 @@ export class BaseSysPermsService extends BaseService {
// 更新部门权限
const departments = await this.baseSysDepartmentService.getByRoleIds(
roleIds,
this.ctx.admin.username === 'admin'
await this.isAdmin(roleIds)
);
await this.cacheManager.set(`admin:department:${userId}`, departments);
}
/**
*
* @param roleIds
*/
async isAdmin(roleIds: number[]) {
const roles = await this.baseSysRoleEntity.findBy({ id: In(roleIds) });
const roleLabels = roles.map(item => item.label);
return roleLabels.includes('admin');
}
/**
*
* @param roleIds