Last active
June 22, 2016 12:25
-
-
Save silasrm/70544462b5d94039fded to your computer and use it in GitHub Desktop.
AngularJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AngularACL | |
Criar as classes: | |
UserObj, onde é obrigatório ter a as propriedades: | |
- isLogged: true|false | |
- roles: array | |
- name: string | |
Security, onde irá ter métodos para checagem de permissão, recebendo o usuário (instância de UserObj) | |
e o nome da rota, onde irá checar se a rota existe, e se existir, checa se o usuário possui alguma das | |
roles que a rota necessita. | |
Criar directive onde recebe o nome da rota e o usuário (instância de UserObj), que chama o Security para verificar, | |
e se não tiver permissão garantida, esconde o elemento (div, link e etc). | |
Inspiração: https://coderwall.com/p/f6brkg e a necessidade de controlar os recursos (rotas e ações) via permissões. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// routes.js | |
{ | |
"/welcome": { | |
templateUrl: 'partials/welcome.html', | |
controller: 'WelcomeCtrl', | |
name: 'welcome' | |
}, | |
"/user-details": { | |
templateUrl: 'partials/userDetails.html', | |
controller: 'UserDetailsCtrl', | |
requireLogin: true, | |
name: 'user_details' | |
}, | |
"/payments/remove/:id": { | |
templateUrl: 'partials/userDetails.html', | |
controller: 'UserDetailsCtrl', | |
name: 'payments_remove' | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// security.js | |
{ | |
// 'user' is a default role for all | |
roles: { | |
'asshole': ['user'], | |
'project_leader': ['user'], | |
'manager': ['project_leader', 'asshole'], | |
'admin': ['manager'] | |
}, | |
permissions: { | |
"welcome": {}, | |
"user_details": { | |
requireLogin: true, | |
roles: ['user', 'admin'] | |
}, | |
"payments_remove": { | |
requireLogin: true, | |
roles: ['admin'] | |
}, | |
{ | |
key: 'todo_list_remove', | |
controller: 'Todo_List', | |
action: 'remove', | |
roles: ['project_leader', 'manager'] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment