|
|
@ -90,10 +90,59 @@ async function del(ctx) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async function getUserResources(ctx) { |
|
|
|
try { |
|
|
|
const { adminHr } = ctx.fs.api.userInfo; |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { userId } = ctx.params; |
|
|
|
let codes = []; |
|
|
|
//人资管理员-所有权限
|
|
|
|
if (adminHr.some(admin => admin.id == userId)) { |
|
|
|
const resource = await models.Resource.findAll({ |
|
|
|
attributes: ['code'], |
|
|
|
order: [['id', 'asc']] |
|
|
|
}) |
|
|
|
codes = resource.map(r => r.code); |
|
|
|
} else { |
|
|
|
const userResources = await models.RoleResource.findAll({ |
|
|
|
attributes: ['id', 'resId'], |
|
|
|
include: [{ |
|
|
|
required: true, |
|
|
|
model: models.Role, |
|
|
|
attributes: [], |
|
|
|
include: [{ |
|
|
|
model: models.UserRole, |
|
|
|
attributes: [], |
|
|
|
where: { userId: userId } |
|
|
|
}], |
|
|
|
}, { |
|
|
|
required: true, |
|
|
|
model: models.Resource, |
|
|
|
attributes: ['id', 'name', 'code'], |
|
|
|
}], |
|
|
|
order: [['id', 'asc']] |
|
|
|
}); |
|
|
|
let rslt = []; |
|
|
|
userResources && userResources.map(ur => { |
|
|
|
if (!rslt.some(r => r.id === ur.resId)) { |
|
|
|
rslt.push(ur.resource); |
|
|
|
codes.push(ur.resource.code); |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = codes; |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path:${ctx.path},error:${error}`) |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { name: 'FindError', message: '获取用户角色资源失败' } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = { |
|
|
|
get, |
|
|
|
add, |
|
|
|
edit, |
|
|
|
del, |
|
|
|
getUserResources |
|
|
|
} |