question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property "redirectTo" inheritance

See original GitHub issue

Hello!

Documentation states that when using ui.router, we don’t need to repeat permissions already specified on parents within child’s permission data.

However it does not mention whether “redirectTo” is also inherited.

I’ve just decided to give it a try to angular-permission and I specified “redirectTo” on the topmost state (which I should point is also an abstract state).

Even though I could confirm that indeed it checks for permissions defined on the parent, the redirection logic doesn’t seem to be inherited.

Is that intended? Or maybe I’m doing something wrong?

Here’s a snippet of my configuration:

.state("app", { url: "", templateUrl: "app/shell.html", abstract: true, data: { permissions: { only: "AUTHORIZED", redirectTo: { default: "login" } } } })
   .state("dashboard", { parent: "app", url: "/dashboard", templateUrl: "app/dashboard.html" })
   .state("something", { parent: "app", url: "/something", templateUrl: "app/something.html", data: { permissions: { only: "SPECIFIC_ONE" } } })

With that configuration, going to “dashboard” validates “AUTHORIZED” and redirects to “login” if invalid.

Going to “something” will validate “AUTHORIZED”, then will validate “SPECIFIC_ONE” but if invalid will just stop transition and will not redirect to login.

Appreciate any help.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
axarcommented, Sep 23, 2016

My 2 cents.

Looking at the code

StatePermissionMap.prototype.extendPermissionMap = function (permissionMap) {
    if (permissionMap.only.length) {
      this.only = this.only.concat([permissionMap.only]);
    }
    if (permissionMap.except.length) {
      this.except = this.except.concat([permissionMap.except]);
    }
    this.redirectTo = permissionMap.redirectTo;
  };

Why don’t we check if permissionMap.redirectTo is undefined before setting it. That way parent redirect to will not changed until something in child decides to change. It seems when I set a redirectTo rule in parent state, it gets override with undefined when child does not set redirectTo. This would be the simplest way to trickle redirectTo (under the assumption the path is properly inherited). This would required parent state to have defined permission. (areSetStatePermissions)

StatePermissionMap.prototype.extendPermissionMap = function (permissionMap) {
    if (permissionMap.only.length) {
      this.only = this.only.concat([permissionMap.only]);
    }
    if (permissionMap.except.length) {
      this.except = this.except.concat([permissionMap.except]);
    }
    if(permissionMap.redirectTo !== undefined) {
      this.redirectTo = permissionMap.redirectTo;
    }
  };

Then again ng-route doesn’t seem to extend the permissions; I’m not too familiar with ngRoute to comment.

0reactions
masterspambotcommented, Dec 9, 2016

Included in release 5.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to redefine a property in C# through interface inheritance?
Redefinable property, the 'real' property of TheClass. That way it's actually redefined, as in back through the hierarchy.
Read more >
Redirecting Your Inheritance - Timbrell Law Solicitors
This can be achieved through a Deed of Variation. You can redirect your inheritance to anyone you want. It does not matter if...
Read more >
State.statedeclaration - UI-Router
Use an abstract state to provide inherited properties (url, resolve, data, ... Note: redirectTo is processed as an onStart hook, before LAZY resolves....
Read more >
Route - Angular
The following route uses the redirectTo property to ignore a segment of a given URL when looking for a child path. When navigating...
Read more >
Angular Router: Revealing some interesting facts and features
The path property which resides in the same configuration object as the redirectTo property poses a few more interesting possibilities. The path property...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found