Comments (7)
Can you explain more in details what this feature request is about? I dind't really understand
from angular-permission.
For example, i have an API service $.get which at the handler returns all the session data needed to know what is the current role. So it would be usefull to do something like this:
.defineMultipleRoles([...], function (stateParams) {
var defer = $q.defer();
accountService.pullSession().then(function (data) {
...
defer.resolve(['admin', 'user', 'manager']);
...
defer.resolve(['admin']);
...
defer.reject(['anonymous']);
}, function () {
defer.resolve(['anonymous']);
});
return defer.promise;
})
from angular-permission.
This doesn't really makes sense as defineMultipleRoles
runs once per role defined
This means you should do something like this:
.defineMultipleRoles(['admin', 'user', 'manager', 'anonymous'], function (stateParams, roleName) {
// ... Do some checking with roleName
// for example:
if (roleName === 'anonymous') {
return !User.hasSession(); // Will resolve as anonymous if use doesn't have a session
}
if (roleName === 'manager') {
return User.isManager();
}
// ... and so on ... //
});
from angular-permission.
when i said defineMultipleRoles i meant some "the new function".
but in that case defineMultipleRoles does not consider asynchronous such as $.get does.
from angular-permission.
I'm pretty sure defineMultipleRoles
uses defineRole
in the background, that being the case, you can return a promise.
The condition is: If the promise resolves, the session has the role, if the promise rejects, then the user doesn't have the role.
from angular-permission.
Oh ok. didn't noticed that.
but in that case the $.get request wouldn't be called 'n' times? (being n the number of roles)
from angular-permission.
Yeah, therefore you should cache that response in a service or via standard caching itself.
I'd suggest having some sort of User/Session service and inject it into the module where you are defining the roles.
Then you could have a method called getSessionData
or something, and have it return a promise (which is the same for every request, this means it will only request the server once, and the next times return its response on its resolve callback).
Hope this helps, closing this issue
from angular-permission.
Related Issues (20)
- resolve function in state provider problem HOT 2
- Disabling Angular UI bootsrap element.
- angular-ui-router is deprecated in lieu of @uirouter/angularjs HOT 3
- Set up roles and permissions after authentication HOT 2
- permission-sref with dynamic access HOT 1
- PermPermissionStore has no method define Permission
- How to add permission-only dynamically? HOT 5
- A different approach for ng-if HOT 4
- permissions context
- Pass parameter inside a permission-on-authorized function
- How to get current user Roles on services? HOT 1
- Any example of defining Permission before permission.ui load HOT 1
- UI-Router 1.x HOT 4
- permission-sref state params
- $q.any is not a function (Lazyloading angular modules using webpack) HOT 2
- Where the API?
- where i should store session and store after login ?? (Can you give example)
- How to do asynchronous task when defining a permission
- State params not passed to signin state HOT 2
- no $stateChangePermissionStart after upgrading to @uirouter/angularjs && angular-permission 5.3.2 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-permission.