|
@@ -16,39 +16,37 @@ class UserMenuService extends CrudService {
|
|
|
}
|
|
|
|
|
|
async create(data) {
|
|
|
- const { project, userid } = data;
|
|
|
+ const { userid } = data;
|
|
|
let res;
|
|
|
- res = await this.model.findOne({ project, userid });
|
|
|
+ res = await this.model.findOne({ userid });
|
|
|
if (res) {
|
|
|
- res = await this.model.update({ project, userid }, data);
|
|
|
+ res = await this.model.update({ userid }, data);
|
|
|
} else {
|
|
|
res = await this.model.create(data);
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- async findUserMenu({ project, userid }) {
|
|
|
- assert(project, '缺少需要查找的项目信息');
|
|
|
+ async findUserMenu({ userid }) {
|
|
|
assert(userid, '缺少用户信息');
|
|
|
- const res = await this.model.findOne({ project, userid });
|
|
|
+ const res = await this.model.findOne({ userid });
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- async getUserMenu({ project, type, userid }) {
|
|
|
- assert(project, '缺少需要查找的项目信息');
|
|
|
+ async getUserMenu({ type, userid }) {
|
|
|
assert(type, '缺少需要查找角色代码');
|
|
|
assert(userid, '缺少需要查找用户信息');
|
|
|
// 找到这个角色的权限,找到用户权限,合并在一起
|
|
|
// 找到这个角色的所有权限
|
|
|
const menuids = [];
|
|
|
- const res = await this.Rolemodel.findOne({ project, type });
|
|
|
+ const res = await this.Rolemodel.findOne({ type });
|
|
|
if (!res) { throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定角色'); }
|
|
|
const { menu: roleMenu, params } = res;
|
|
|
// roleMenu只存id
|
|
|
menuids.push(...roleMenu);
|
|
|
// 找到用户的特殊权限
|
|
|
if (userid !== 'dev') {
|
|
|
- const umidsRes = await this.ctx.service.userMenu.findUserMenu({ project, userid });
|
|
|
+ const umidsRes = await this.ctx.service.userMenu.findUserMenu({ userid });
|
|
|
if (umidsRes) {
|
|
|
const { menu: uMenuids } = umidsRes;
|
|
|
// uMenuids只存id
|
|
@@ -61,7 +59,7 @@ class UserMenuService extends CrudService {
|
|
|
parentIds = _.compact(parentIds);
|
|
|
menuids.push(...parentIds);
|
|
|
// 找到该项目的所有的权限
|
|
|
- const allMenu = await this.Menumodel.find({ project, disabled: false }).sort({ sort: -1 });
|
|
|
+ const allMenu = await this.Menumodel.find({ disabled: false }).sort({ sort: -1 });
|
|
|
// 需要将根目录整理出来,将
|
|
|
const dup = allMenu.filter(f => menuids.find(um => ObjectId(um).equals(f._id)));
|
|
|
const userMenu = await this.ctx.service.menu.toFindChildren(dup);
|