I have an api on node and I have the following situation:
I am the master user and create a usuário A
for any employee. This usuário A
has the permissions
User Permissions A
[criar_usuario,editar_usuario,receber_contas,editar_contas,ver_clientes]
Then, this usuário A
creates another usuário B
on the system with permissions
User permissions B
[criar_usuario,deletar_usuario,deletar_contas,enviar_sms,excluir_registro]
What I want is to map the permissions of usuário A
, and if I create or edit usuário B
, usuário B
can have the same permissions as usuário A
or less, but never have permissions that% user A does not have.
In the example above,% w / w% may have:
usuário B
But never:
[criar_usuario,editar_usuario,ver_clientes]
I tried this
let p = usuarioLogado.permissions; // permissões do usuário logado
let up = req.body.permissoes; // permissões do usuário que será criado ou editado
up.map((o, index) => {
if (p.indexOf(o) <= -1) {
up.splice(index, 1)
}
})
but it does not work, there are remnants of permissions that can not be applied