Closed luishdz1010 closed 7 years ago
Relates to #356
Top priority now.
What exactly is not working with ui-router 1.0.0-rc.1? I have a simple setup but have found no problems so far (angular 1.6.1 + ui-router 1.0.0-rc.1 + angular-permission-5.2.0)
Relates to #381
@mbenedettini are you also using the stateEvents
polyfill provided by ui-router? It makes my URL "flashes" and not work properly, but it's needed by angular-permission as far as I can tell.
Hello,
I did a fork to add support for angular-ui-router 1.0.0-rc.1. If you are interested: https://github.com/Lukinos/angular-permission/tree/support-ui-router-1.0.0 DANGER: SUPPORT FOR VERSION < 1.0.0 is dropped
With their new transitions system, it simplifies a lot the code :smile:.
Cool @Lukinos. I was looking at angular-permission codebase and thought about making a similar tweak as yours. However, what I ended up doing was calling PermStateAuthorization
on a $transitions.onStart
inside my run
procedure. Not the most beautiful but it does the job.
@Lukinos thanks for this, was there any breaking API changes? for me passing in a configuration to the state config does not work. (I get no error and am allowed to visit the state.). The directive are still working fine
data: {
permissions: {
only: 'createBatches',
redirectTo: 'login'
}
}
@Lukinos I had an issue with bower cache, but In the end I get your code and it works a charm, except on small thing. If a redirectTo state is not defined, it does not default to $urlRouterProvider.otherwise
@blowsie Sorry, did not see your poke.
I am not sure to understand your question, but I will try to answer:
$urlRouterProvider.otherwise
is trigger only on invalid routes, which implies there is no matches for a route.
Hence, if you try to access a route that does not specify redirectTo
, but the route exists, it will not trigger the otherwise
, because the route exists.
Hope that's help.
I believe I'm having the same issue as @brenolf . I implemented this library into a new project last week, and I love the control it provides over access control to different states. However, I'm seeing 2 specific types of behavior that are highly undesirable since I've implemented it.
First, I'm having an issue where navigation between states / pages (i.e. using the forward / back buttons) breaks on states controlled by angular permissions. For instance, suppose I have two states, A and B. Suppose access to state A is controlled by angular permissions, and state B is not. If i navigate between the two states, I'm having an issue where the back and forward navigation buttons in the browser no longer toggle the correct behavior. If I were to start in some third state C, and then go to A, and then B, it can toggle an infinite loop where if I hit back, it goes to A, and back goes to B, and back goes to A, and over and over between A and B, never arriving at C.
Second, I'm seeing the URL flickering @brenolf mentioned. I believe it's related to the issue described above.
Has anyone else seen this type of behavior?
Hello I have the same behavior such as @brenolf and @jonathanwoahn, and I can't get these problems resolved when I use stateEvents pollyfill. But when I use html5 mode + remove stateEvent, I get it working properly if that can help someone. @brenolf you were saying :
PermStateAuthorization
on a$transitions.onStart
inside my run procedure'
I can't find any documentation about the PermStateAuthorization
or I'm missing something so I was not able to get it working, can you tell me more about this please? I would know which function you use and which parameters you pass to the function?
Thank you!
@thakimb What I ended up doing was to manually call PermStateAuthorization
. There is indeed no documentation for that, I just looked up at their source code to understand how this was supposed to be called.
The final code looks like this:
PermRoleStore.defineManyRoles({
'USER': function() {
return AuthService.verify();
},
'ADMIN': function() {
return AuthService.isAdmin();
}
});
$transitions.onStart({}, function(trans) {
return PermStateAuthorization.authorizeByStateName(trans.to().name)
.catch(function() {
return false;
})
.then(function(result) {
if (angular.isDefined(result) && (!result || !result[0])) {
return trans.router.stateService.target('app.home.login');
}
});
});
@brenolf Thank you! that helped me a lot :+1:
Included in v5.3.0
ui-router's team is encouraging everybody to migrate now, is there any plans for angular-permission to support it anytime soon?