-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Why these changes are being introduced: We will need authorization for TACOS, as it will contain a variety of features that should not be avilable to every user. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/TCO-31 How this addresses that need: This adds the CanCanCan gem, which [we agreed to use for authorization'](https://github.com/MITLibraries/tacos/blob/main/docs/architecture-decisions/0006-use-cancancan-for-authorization.md). It also introduces a very rudimentary Ability model -- mostly a placeholder until we know what we need -- and a boolean `admin` field to the User model. It does not implement any rules in the Ability model beyond 'admins can manage anything.'' I debated whether to go even that far, as there's nothing yet to manage. It's also worth noting that while I was initially opposed to the admin boolean, it does appear to be an idiom within CanCanCan, so I'm comfortable using it here. I think things become more complicated when we combine that pattern with role-based authorization (more on that in side effects, below). Side effects of this change: Unless we implement [role-based authorization](https://github.com/CanCanCommunity/cancancan/blob/develop/docs/role_based_authorization.md), as we've done in ETD, CanCanCan seems to want us to include all of our rules in the `initialize` method. That feels like it would get out of hand quickly. We had briefly discussed in a team meeting that we _don't_ want to implement authorization similarly to ETD, with increasing permissions at each role. (Though, that type of cascading is where [CanCanCan excels](https://github.com/CanCanCommunity/cancancan/blob/develop/docs/define_check_abilities.md).) It is also possible to assign multiple roles to a single user, [albeit kludgily](https://github.com/CanCanCommunity/cancancan/blob/develop/docs/role_based_authorization.md#many-roles-per-user). I do think roles are the way to go here, but we'll want to proceed with caution. As mentioned in the ADR, we may learn early on that CanCanCan is not actually the best authorization gem; finding that we need a dozen or more roles may be one trigger to consider an alternative gem.
- Loading branch information
Showing
9 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class Ability | ||
include CanCan::Ability | ||
|
||
# Define abilities for the user here. | ||
# See the wiki for details: | ||
# https://github.com/CanCanCommunity/cancancan/blob/develop/docs/define_check_abilities.md | ||
def initialize(user) | ||
return unless user.present? | ||
# Rules will go here. | ||
|
||
return unless user.admin? | ||
can :manage, :all | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddAdminToUsers < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :users, :admin, :boolean, default: false | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
# email :string not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# admin :boolean default(FALSE) | ||
# | ||
|
||
# This model initially had no columns defined. If you add columns to the | ||
|
@@ -16,3 +17,13 @@ | |
valid: | ||
uid: "[email protected]" | ||
email: "[email protected]" | ||
|
||
basic: | ||
uid: "[email protected]" | ||
email: "[email protected]" | ||
admin: false | ||
|
||
admin: | ||
uid: "[email protected]" | ||
email: "[email protected]" | ||
admin: true |
This file contains 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