Skip to content

how do you all store the roles? #246

Answered by palkan
laptopmutia asked this question in Q&A
Discussion options

You must be logged in to vote

Usually, I design the authorization model on top of permissions and roles. Permissions are granular and describe business logic restrictions, e.g., "manage_projects", "view_projects", "manage_users", "view_users", etc. Roles act as permission sets and only used to assign typical permissions for users.

Permissions can be stored in an array or JSONB field (I prefer the latter):

class User < ApplicationRecord
  attribute :permissions, Permissions::Type.new
end

User.new.permissions #=> Permissions::Set

# Roles only used to synchronize permissions
user.permissions = role.permissions

In policies, we check for permissions, not roles:

class ApplicationPolicy < ActionPolicy::Base
  # add permiss…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
3 replies
@laptopmutia
Comment options

@laptopmutia
Comment options

@palkan
Comment options

Answer selected by laptopmutia
Comment options

You must be logged in to vote
3 replies
@palkan
Comment options

@laptopmutia
Comment options

@palkan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants