GithubHelp home page GithubHelp logo

Comments (7)

RafaelVidaurre avatar RafaelVidaurre commented on May 24, 2024

Can you explain more in details what this feature request is about? I dind't really understand

from angular-permission.

danfergo avatar danfergo commented on May 24, 2024

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.

RafaelVidaurre avatar RafaelVidaurre commented on May 24, 2024

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.

danfergo avatar danfergo commented on May 24, 2024

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.

RafaelVidaurre avatar RafaelVidaurre commented on May 24, 2024

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.

danfergo avatar danfergo commented on May 24, 2024

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.

RafaelVidaurre avatar RafaelVidaurre commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.