-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
672 roles are no longer in a hierarchy #681
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b0f2d61
627 roles are no longer in a hierarchy
aloeser 6ca28ce
Merge branch 'dev' into 672_refactor_role_system
bjrne aff28af
Merge branch 'dev' into 672_refactor_role_system
aloeser 595d5f7
fix code climate
aloeser 265dc77
Merge branch 'dev' into 672_refactor_role_system
ekrebs5 9ebbecc
make requested changes
aloeser 80742fa
Merge branch '672_refactor_role_system' of github.com:hpi-swt2/worksh…
aloeser 7aed1a5
Merge branch 'dev' into 672_refactor_role_system
ekrebs5 9387d0b
Update user.rb
ekrebs5 54eb1b3
requested changes
aloeser fc8a52c
Merge branch '672_refactor_role_system' of github.com:hpi-swt2/worksh…
aloeser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ class Ability | |
def initialize(user) | ||
# Define abilities for the passed in user here. For example: | ||
# | ||
# user ||= User.new # guest user (not logged in) | ||
# user ||= User.new # guest user [not logged in] | ||
# if user.admin? | ||
# can :manage, :all | ||
# else | ||
|
@@ -29,57 +29,56 @@ def initialize(user) | |
# See the wiki for details: | ||
# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities | ||
|
||
user ||= User.new # guest user (not logged in) | ||
user ||= User.new # guest user [not logged in] | ||
|
||
# Even guests can see the apply button | ||
# This is revoked for coaches and organizers below. | ||
can :view_apply_button, Event | ||
can %i(show index archive), Event | ||
can %i[view_apply_button], Event | ||
can %i[show index archive], Event | ||
|
||
if user.role? :pupil | ||
# Pupils can only edit their own profiles | ||
can %i(new create), Profile | ||
can %i(index show edit update destroy), Profile, user: { id: user.id } | ||
can %i[new create], Profile | ||
can %i[index show edit update destroy], Profile, user: { id: user.id } | ||
# Pupils can only edit their own applications | ||
can %i(new create), ApplicationLetter if user.profile.present? | ||
can %i(index show edit update check destroy), ApplicationLetter, user: { id: user.id } | ||
can %i[new create], ApplicationLetter if user.profile.present? | ||
can %i[index show edit update check destroy view_personal_details], ApplicationLetter, user: { id: user.id } | ||
# Pupils can upload their letters of agreement | ||
can [:create], AgreementLetter | ||
can %i(new create), Request | ||
cannot :view_personal_details, ApplicationLetter, user: { id: !user.id } | ||
end | ||
if user.role? :coach | ||
can :create, AgreementLetter | ||
can %i[new create], Request | ||
|
||
elsif user.role? :coach | ||
# Coaches can only edit their own profiles | ||
can %i[new create], Profile | ||
can %i[index show edit update destroy], Profile, user: { id: user.id } | ||
|
||
# Coaches can view Applications and participants for and view, upload and download materials for Event | ||
can %i(view_applicants view_participants view_material upload_material print_applications download_material), Event | ||
can %i(view_and_add_notes show), ApplicationLetter | ||
can %i(show index), Request | ||
cannot :view_apply_button, Event | ||
cannot :check, ApplicationLetter | ||
end | ||
if user.role? :organizer | ||
can %i(index show), Profile | ||
can %i(index show view_and_add_notes update_status), ApplicationLetter | ||
cannot :update, ApplicationLetter | ||
can %i(view_applicants edit_applicants view_participants print_applications | ||
manage view_material upload_material print_agreement_letters download_material | ||
view_unpublished show_eating_habits print_applications_eating_habits view_hidden), Event | ||
can %i[view_applicants view_participants view_material upload_material print_applications download_material], Event | ||
can %i[view_and_add_notes show], ApplicationLetter | ||
can %i[show index], Request | ||
cannot %i[apply view_apply_button], Event | ||
|
||
elsif user.role? :organizer | ||
# Organizers can only edit their own profiles | ||
can %i[new create index show], Profile | ||
can %i[edit update destroy], Profile, user: { id: user.id } | ||
can %i[manage set_contact_person set_notes show index], Request | ||
can %i[index show view_and_add_notes update_status], ApplicationLetter | ||
can %i[manage view_applicants edit_applicants view_participants print_applications view_material | ||
upload_material print_agreement_letters download_material view_unpublished show_eating_habits | ||
print_applications_eating_habits view_hidden edit update destroy], Event | ||
cannot %i[apply view_apply_button], Event | ||
can :send_email, Email | ||
can %i(manage set_contact_person set_notes), Request | ||
cannot :apply, Event | ||
cannot :view_apply_button, Event | ||
can %i(edit update destroy), Event | ||
can [:update], ParticipantGroup | ||
can :update, ParticipantGroup | ||
|
||
# Organizers can update user roles of pupil, coach and organizer, but cannot manage admins and cannot update a role to admin | ||
can :manage, User, role: %w(pupil coach organizer) | ||
can :manage, User, role: %w[pupil coach organizer] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this |
||
cannot :update_role, User, role: 'admin' | ||
cannot :update_role_to_admin, User | ||
end | ||
if user.role? :admin | ||
can :manage, :all | ||
|
||
can :view_delete_button, ApplicationLetter | ||
cannot %i(edit update), ApplicationLetter | ||
elsif user.role? :admin | ||
can :manage, :all | ||
cannot %i[edit update], ApplicationLetter | ||
end | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit eager with the brace removal :-D