We’re currently making rapid changes to the product so our docs may be out of date. If you need help, please email firstname.lastname@example.org.
What is a role?
If authorization is about who has permission to be allowed to do what you want to do, then Roles are common patterns of authorization across users - reducing the administrative overhead.
Why do I need to know about roles?
Some bugs can only be seen for users with specific roles. You will need to change the role to reproduce a problem.
How do we implement roles in Forem?
A new user starts without any roles, and there is no administrative way of adding roles to users yet. To assign a user a role you will have to run commands at the console.
Example of adding permissions to a user
- open the Rails console.
- after verifying the user
test_user_nameis missing the
trustedrole we proceed to add it and then verify the role has been added:
> user = User.find_by(username: "test_user_name")
Another common requirement is changing to the administrative role, and an example of this is found [on the admin page].
A more complex query to list all the users and their roles:
User.joins(:roles).order(:id).group(:id).pluck(:id, :username, Arel.sql("array_agg(roles.name)"))
- Rolify README.md
- [What is the purpose of Rolify?]