feat(permissions): Added member role & permissions - #49
Open
JuanEstebanPradaEspinosa wants to merge 4 commits into
Open
feat(permissions): Added member role & permissions#49JuanEstebanPradaEspinosa wants to merge 4 commits into
JuanEstebanPradaEspinosa wants to merge 4 commits into
Conversation
Plug pipline authorize added for every request check permissions by controller
Author
|
Pushing this up as promised for end of week! The feature work is in place! Permission, roles, permissions on create/edit and some safety guards. Tests exist, but I'd like to do one more integration pass Monday morning before making it my final answer. Hope that's okay. Happy Mother's Day to those celebrating! |
…ler-level): added in the authorize.ex helper function as guard permissions to allow more specefiek actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Propose changes
Plug pipeline authorize added for every request check permissions by controller
Added member role + seeder
Defined a tiered permission hierarchy with roles:
member —
view_event,view_stats,view_graphs,view_profileadmin — all member actions +
trigger_run,view_users,edit_user,create_user,delete_usersuperuser — all admin actions (reserved for future superuser-only operations)
Permissions are enforced at two layers: - Define guards action permissions
Authorizeplug reads@action_permissionsfrom each controller at runtime and denies access viaRoles.can?/2before the action runs.UserControllerhandle fine-grained rules that the plug can't express.can_manage?/2— only users can manage other users if it has permissions for it.sanitize_role_params/2— the current user cannot grant roles to users that doesn't have the specific permission for itAdded a
role_idsvirtual field to theUserschema and a role<select>dropdown on the New User and Edit User forms.Extended
User.changeset/2andUser.update_changeset/2withput_roles_if_present/2to resolverole_id→put_assoc(:roles, ...).Three inline safety guards in
UserController:changing_own_role?/3— prevents users from changing their own role.demoting_last_superuser?/2— prevents removing the last superuser from the system.Task 1:
Task 2: