Skip to content
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

Is it possible to make a Subject's #getPermissions return a Future[List[Permission]]? #12

Open
queirozfcom opened this issue Jun 15, 2015 · 5 comments
Assignees

Comments

@queirozfcom
Copy link

This is what the signature for the getPermissions method in Subject.java looks like right now:

List<? extends Permission> getPermissions();

But in my case (and, I imagine, for other people as well) I need to fetch permissions for a given user from the database, which shouldn't block my app. This is how I've implemented this interface in my actual User class (note that I have to block the thread at the end because I need to return a List[java.List] of it doesn't match the interface signature.

  def getPermissions: java.util.List[Permission] = {

    val q = for {
      u <- users if u.id === this.id
      uxug <- users_x_user_groups if uxug.userId === u.id
      ug <- user_groups if ug.id === uxug.userGroupId
      pug <- permissions_x_user_groups if (pug.userGroupId === ug.id || pug.userGroupId === ug.parentGroupId)
      p <- permissions if p.id === pug.permissionId
    } yield (p)

    val f = db.run(q.result)

    Await.result(f, 10.seconds).toList.asJava

  }

Is there some way to be able to return a Future without needing to fork the repo and changing the signature in Subject.java ? I'm not a very experienced Scala dev so it's possible I missed some simple solution.

@schaloner
Copy link
Collaborator

That's a great idea. I'll make the API changes tomorrow.

@schaloner schaloner self-assigned this Jun 15, 2015
@schaloner
Copy link
Collaborator

"Tomorrow" might have been a bit premature, because I'm releasing the Java 2.4.0 final version today, and this is a non-trivial change. I'll slate this for v2.4.1.

@djx314
Copy link

djx314 commented Jul 19, 2015

+1 for future, now I have to write a simple DynamicResourceHandler for use. Hope for the future implement.

@schaloner
Copy link
Collaborator

I've been thinking about this, and chatted to a few other users, and it seems to make more sense to retrieve roles and permissions at the point the subject is retrieved.

Any thoughts on this?

@djx314
Copy link

djx314 commented Jul 23, 2015

That's great! Actually when the action access the request it will fetch the role and permissions first, why not do it in one space? And I think we must keep the implement to fetch the subject only.
By the way, it's import to fetch the role and permission in other class but not the subject class. It's better to keep the subject, role, permission more pojo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants