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

What's the recommended approach for user roles? #30

Closed
dfalling opened this issue Oct 5, 2018 · 6 comments
Closed

What's the recommended approach for user roles? #30

dfalling opened this issue Oct 5, 2018 · 6 comments

Comments

@dfalling
Copy link
Contributor

dfalling commented Oct 5, 2018

The docs mention using the extended plug to check for an admin role, but how should that data be set on the user? If I simply add a role field to the user table it still won't be present on the AccessPass.Users record.

Thanks!

@jpiepkow
Copy link
Collaborator

jpiepkow commented Oct 5, 2018

Sure, so extended plug does comparison inside the user meta objects. So if you had

plug AuthExtended, role: "admin"

it would check the uses meta object(that was stored on registration) for the key of role that equals value of "admin".

So all things you want to compare against in the keyword list passed to the plug are compared in the users meta object.

@jpiepkow jpiepkow closed this as completed Oct 5, 2018
@dfalling
Copy link
Contributor Author

dfalling commented Oct 5, 2018

Great! Last question: how can I make sure users can't make themselves admins? Normally I'd filter out that field in my controller if the user isn't an admin.

@jpiepkow
Copy link
Collaborator

jpiepkow commented Oct 5, 2018

Sure so you can do that a couple different ways.

You can run your own custom validation on the changeset to include/exclude roles in the meta object using the custom_user_changes behavior.

Or

You could do the same custom validation logic and use insert_override to handle the changeset insert yourself.

https://hexdocs.pm/access_pass/AccessPassBehavior.html

@jpiepkow
Copy link
Collaborator

jpiepkow commented Oct 5, 2018

If for example you don't want users to add role to the meta on registration you would do something like follows inside the custom_user_changes behavior

put_change(changeset, :meta, %{})

This would update the meta object to empty regardless of what the users passed in.

@dfalling
Copy link
Contributor Author

dfalling commented Oct 5, 2018

Awesome, that's a very elegant solution. Thanks!

@jpiepkow
Copy link
Collaborator

jpiepkow commented Oct 5, 2018

No problem! Thanks for all the feedback through github issues! I have a project I have been working on for quite a while that is going through a closed private beta shortly I would love feedback on if thats something that might interest you. It is actually the reason I made accesspass in the first place.

Information on the project:

https://medium.com/appdoctor/what-is-appdoctor-5cceaedf7a05

email beta@appdoctor.io if interested so I can send you a key when we add our next group to the closed beta!

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

2 participants