-
Notifications
You must be signed in to change notification settings - Fork 140
Rearrange, not change the abilities in Ability #997
Changes from 7 commits
d00277c
27ead4d
e1b56f1
6b4664e
bfaeb99
f6da595
b172a3f
ec3c037
f84460e
dad17d8
ff1e8ba
975877f
1e5db7d
cabcae9
6e7d601
9a0f39b
e765a2b
9d685da
419bdf7
cb126b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
# frozen_string_literal: true | ||
# See the wiki for details: | ||
# https://github.com/ryanb/cancan/wiki/Defining-Abilities | ||
|
||
class Ability | ||
include CanCan::Ability | ||
|
@@ -10,22 +8,66 @@ def initialize(user) | |
|
||
alias_action :create, :read, :update, :destroy, to: :crud | ||
|
||
can :crud, User, id: user.id | ||
can :crud, User if user.admin? | ||
# guest user | ||
can :read, [Activity, User, Team, Project, Conference] | ||
|
||
return unless signed_in?(user) | ||
|
||
# unconfirmed, logged in user | ||
can :update, User, id: user.id | ||
can :resend_confirmation_instruction, User, id: user.id | ||
can :read_email, User, hide_email: false # view helper # delete? only used once | ||
|
||
return unless user.confirmed? && signed_in?(user) | ||
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. I think the |
||
|
||
# confirmed user | ||
can [:update, :destroy], User, id: user.id | ||
can :resend_confirmation_instruction, User, id: user.id | ||
can :resend_confirmation_instruction, User if user.admin? | ||
can :create, Project | ||
can [:join, :create], Team | ||
can :index, Mailing | ||
can :read, Mailing do |mailing| | ||
mailing.recipient? user | ||
end | ||
|
||
# Members in a team | ||
can [:update, :destroy], Team do |team| | ||
on_team?(user, team) | ||
end | ||
|
||
# current_student | ||
if user.current_student? # TODO is this a valid check? | ||
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. From what I remember this checks whether the user is a student in an accepted team for the current season. So this may already be scoped too narrow here... At least user.teams.none? and creating teams in general does not make much sense then 🤔 |
||
can :create, Team if user.teams.none? | ||
can :create, Conference | ||
end | ||
|
||
# visibility of email address in user profile | ||
can :read_email, User, id: user.id if !user.hide_email? | ||
can :read_email, User if user.admin? | ||
can :read_email, User do |other_user| | ||
user.confirmed? && (supervises?(other_user, user) || !other_user.hide_email?) | ||
# supervisor | ||
if user.supervisor? | ||
can :read, :users_info | ||
can :read_email, User do |other_user| | ||
supervises?(other_user, user) | ||
end | ||
end | ||
|
||
can :crud, Team do |team| | ||
user.admin? || signed_in?(user) && team.new_record? || on_team?(user, team) | ||
# project submitter | ||
can [:update, :destroy], Project, submitter_id: user.id | ||
can :use_as_template, Project do |project| | ||
user == project.submitter && !project.season&.current? | ||
end | ||
|
||
# admin | ||
if user.admin? | ||
can :manage, :all | ||
# MEMO add "cannot's" only; and only after this line | ||
cannot :create, User # this only happens through GitHub | ||
end | ||
|
||
################# REMAININGS FROM OLD FILE, # = rewritten above ############ | ||
|
||
# can :crud, Team do |team| | ||
# user.admin? || signed_in?(user) && team.new_record? || on_team?(user, team) | ||
# end | ||
|
||
can :update_conference_preferences, Team do |team| | ||
team.accepted? && team.students.include?(user) | ||
end | ||
|
@@ -38,10 +80,10 @@ def initialize(user) | |
team.students.include?(user) | ||
end | ||
|
||
cannot :create, Team do |team| | ||
on_team_for_season?(user, team.season) || !user.confirmed? | ||
end | ||
|
||
# cannot :create, Team do |team| | ||
# on_team_for_season?(user, team.season) || !user.confirmed? | ||
# end | ||
# todo helpdesk team join | ||
can :join, Team do |team| | ||
team.helpdesk_team? and signed_in?(user) and user.confirmed? and not on_team?(user, team) | ||
end | ||
|
@@ -62,35 +104,10 @@ def initialize(user) | |
user.admin? || (preference.team.students.include? user) | ||
end | ||
|
||
can :crud, Conference if user.admin? || user.current_student? | ||
|
||
# todo add mailing controller and view for users in their namespace, where applicable | ||
can :read, Mailing do |mailing| | ||
mailing.recipient? user | ||
end | ||
|
||
can :crud, :comments if user.admin? | ||
can :read, :users_info if user.admin? || user.supervisor? | ||
|
||
# projects | ||
can :crud, Project do |project| | ||
user.admin? || | ||
(user.confirmed? && user == project.submitter) | ||
end | ||
can :use_as_template, Project do |project| | ||
user == project.submitter && !project.season&.current? | ||
end | ||
|
||
can :create, Project if user.confirmed? | ||
cannot :create, Project if !user.confirmed? | ||
|
||
# activities | ||
can :read, :feed_entry | ||
can :read, :mailing if signed_in?(user) | ||
|
||
# applications | ||
can :create, :application_draft if user.student? && user.application_drafts.in_current_season.none? | ||
end | ||
|
||
end # initializer | ||
|
||
def signed_in?(user) | ||
user.persisted? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
FactoryBot.define do | ||
factory :user, aliases: [:member] do | ||
github_handle { FFaker::InternetSE.user_name_variant_short } | ||
github_handle { FFaker::InternetSE.unique.user_name_variant_short } | ||
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. This fixes flickering specs because of failing uniqueness validation on gh handle. |
||
name { FFaker::Name.name } | ||
email { FFaker::Internet.email } | ||
location { FFaker::Address.city } | ||
|
@@ -84,5 +84,9 @@ | |
create(:reviewer_role, user: user) | ||
end | ||
end | ||
|
||
trait :unconfirmed do | ||
confirmed_at { nil } | ||
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. No need for a block here. |
||
end | ||
end | ||
end |
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.
👍