-
Notifications
You must be signed in to change notification settings - Fork 212
Angular-permission breaks state transition options #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting this, this can actually be fixed: $rootScope.$on('$stateChangeStart',
function (event, toState, toParams, fromState, fromParams) { The $state.go(toState.name, toParams, {notify: false}).then(function() { ... }); to something like toOptions = toState.options;
toOptions.notify = false;
$state.go(toState.name, toParams, toOptions).then(function() { ... }); Think this would solve the issue you describe? (Haven't tested it myself) Feel free to submit a PR if you can, I can otherwise fix this myself later this week when I'm free, though I'd priorize your PR since you discovered the problem and should get the credit for it. Cheers and thanks |
I don't see the As of right now, there appears to be no way to capture the options during a |
My bad I apparently read the docs wrong. One option would be to specify state options via the Something like: $stateProvider
.state('staffpanel', {
url: '...',
data: {
permissions: {
only: ['admin', 'moderator']
},
stateOptions: {
location: 'replace'
}
}
}); Any other ideas? |
The problem is those options are transient: they may only exist for a particular link (in my case, when toggling between different IDs within the same parent), but not when referenced from the outside. For now, it's not critical, and UI-Router is supposed to have an all-new transition library soon, which will be a better place for Permission to hook. I'm hoping in the short term they simply start passing the options along, you can vote for the issue to help bring attention to it. It's a much faster fix if they go that route, rather than waiting for a breaking-change release. |
The only other option I can think of would be to allow for synchronous permissions checks, which would complicate your library significantly. But the idea is, if the result of a permissions test is exactly That seems really hacky, though. |
Thanks for the reply, lets see if this issue can be addressed by the angular-ui team, otherwise we will have to re-check our options. |
@Narzerus after using angular-permission in my application all the CREATE button on all forms(10 approx) have stopped working because soon as the resource is created reload: true is passed in state options as to reload and newly created resource is shown in list, Using following line: I have read the above comments and also posted on ui-router github issue and waiting for the solution. |
Since this issue depends on a problem with ui-router's |
@Narzerus 0.2.15 of Angular UI Router is released, when will you be releasing angular-permission to incorporate the changes ? |
I will check the changelog and see what this implies before giving a
|
I rewritten the thing into my own module in a synchronous fashion and it works. That way you don't need to prevent the state transition in any case but those which aren't allowed. Is there any reason you used promises rather than the sync approach? I do like and use promises a lot but I don't see the need in this scenario) |
Many people have roles which require a request to some backend
|
Hello, I am facing exactly the same pb as @abhinandankothari and using ui-router 0.2.15, any improvements from here ? By the way : thanks for the lib, appart from that it looked really great. But for me this bug is a showstopper |
@ronanquillevere sadly as mentioned in the thread, this has to do with an issue on ui-router's end so there's not much we can do about it for now. |
@Narzerus |
Actually I'm testing this right now, will respond in a moment |
@Narzerus As I see it one could more easily implement a workaround for the need of making requests during permission check (by caching those e.g.) as to find a way to cope with the issue of this thread. At least I guess a lot more people have said issue than the need to check back with a backend. |
@asperling I'm not sure that's really the case, many people here need to query their back-end at specific points to get the actual session state, I cannot change such core behavior it would break everyone's code. I'm sorry if this is not the answer you were expecting, I'll try to find some way for this to work in your use-case |
@Narzerus @asperling I do not have a strong opinion on the matter but I think making an asynch call to retrieve your permissions each time a route is called is not the best option in terms of performance. I personnaly do it only once when starting my app. Would be interesting if someone could share his use case for an asynch call |
I agree with that, still it would depend on the use-case. Caching will still work swiftly with promises, which is why I'm using it, its the best for both cases (If it weren't for this issue we are having) |
Welp, about the "I'm testing this" it was actually meant as a response for a different issue. |
@asperling would you have a fork with a sync version to share ? |
@Narzerus I solved my case by integrating your great idea and some of your work in my own access module in a sync fashion and... But the main idea was to only stop propagation if a synchronous authorization check fails:
See https://github.com/Narzerus/angular-permission/blob/v0.1.7/src/permission.mdl.js for comparision. Then you'll need to refactor all promise based functions into synchronous ones. As an example:
instead of https://github.com/Narzerus/angular-permission/blob/master/src/permission.svc.js#L128 (_my module is called _AccessControl*, you will need to change that) Maybe I can manage to build such a synchronous fork some time... And @Narzerus, you're right, just switch back to sync would affect all of those that have already implemented it. Not to easy... |
Due to the fact that angular-permission completely stops and restarts every state transition, any options passed in (for example, via
ui-sref-opts
) are lost.This means it's impossible to use angular-permission and do things like
location: 'replace'
, because the option is lost.The text was updated successfully, but these errors were encountered: