openflighthpc / flight-control

0 stars 0 forks source link

User roles #19

Closed VoxSecundus closed 2 years ago

VoxSecundus commented 2 years ago

NB: The contents of this PR depend upon #17, and should be rebased once that branch is merged.

This PR introduces the idea of user roles to Flight Control.

A user role is a database-backed model used to represent the permissions of a user for a particular project. They are volatile and can be created/destroyed without fear for loss of integrity. A user can have numerous roles, among numerous projects. This means that a user can have differing roles/permissions for different projects.

When a user has no projects to view, they are instead taken to a page displaying a message telling them so. When a user tries to visit a page they are not authorised to view, they are redirected to the root path with a flash alert telling them so.

Pundit policies

Pundit has been added to Flight Control to make the creation of policies easier. At the moment, one policy exists (ProjectPolicy) with two methods (show? and create_event?).

Rake tasks

Two new rake tasks have been added for assigning/revoking user roles. Each are of the form:

rake users:roles:assign/revoke[username,project,role]

to assign/revoke a role. The users:list task has also been updated to display a user's projects and roles.