Comments (7)
This has been discussed a couple of times before. It's a good idea though it is not yet implemented.
Probably the syntax would be just like the one you posted, there was also an Idea about adding a default redirect at the role definition instead of the route data. Though I think that would cause app mantainability issues.
We have to priorize other problems first, though if you feel like creating a PR I'd gladly review it thoroughly.
Either way, it's very likely I'll implement this at some point in the near future.
from angular-permission.
Alright, I'll give it a try. Please be patient, I'm not a JS profi ;-)
I also like the idea to add the default redirect to the role definition. For me, both ways would be okay. Where do you see the maintainability issues?
Here a snippet how I understood the other idea, is this correct?
Permission.defineRole('anonymous', 'page.login', function (stateParams) {
// or...
Permission.defineRole({ name: 'anonymous', otherwise: 'page.login'}, function (stateParams) {
- Edit:
What about a custom callback?
Permission.defineRole('anonymous', function (stateParams) {
// Check role
}).accepted(function() {
console.log('User is not anonymous!');
}).denied(function($state) {
$state.go('page.login');
});
// or something easier to implement...
Permission.defineRole('anonymous', function (stateParams) {
// Check role
}).defineDenied('anonymous', function($state) {
$state.go('page.login');
})
from angular-permission.
In the app itself creating a default redirection of the role denied is kind of weird when you take a closer look. For example say we have roles: roleA
, roleB
If we use the except
way of granting access
data: {
permissions: {
except: ['roleA', 'roleB']
}
}
If we define a default redirect for roleA
then weird stuff would happen. The idea of except
is that it only grants state access if roleA
and roleB
are rejected therefore, since we defined a redirect at role-definition level, this state cannot be accessed.
This is one of the reasons why I think redirection should be defined at state/route config level.
from angular-permission.
Hi, thanks for the amazing package!! I wanted to suggest if is a good idea to have as parameter either a string or a function in the redirectTo
property. If a function is given we have more control to choose which redirect state we should take the user. Ex:
.state('mnm.activate-profile',{
url:'/account/activation',
data: {
permissions: {
only: ['authenticated'],
redirectTo: function(rejectedPromise) {
if (!angular.isDefined(rejectedPromise)) {
return 'auth.login';
} else if(rejectedPromise.active === false){
return 'auth.activation';
}
return 'home';
}
}
},
template: '<h1>Hiii</h1>'
})
Permission:
Permission.defineRole('authenticated', function(stateParams) {
var deferred = $q.defer();
Account.identity()
.then(function(user) {
if (!user) {
defer.reject();
} else if(user.active === false){
defer.reject(user);
} else {
defer.resolve();
}
});
return deferred.promise;
})
from angular-permission.
@fenos that sounds like a good idea, would have to probably add support for promises so that you can do async operations on the redirectTo function.
If you feel like it, open a discussion with your idea of a good implementation of this feature so we can all evaluate it.
from angular-permission.
Working on this right now, @fenos I'm trying your approach as it is the most powerful solution for now
from angular-permission.
A new version of Permission is now available, supporting @fenos' idea
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.