-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Project Admins can manage Materials Collections [PT-187061879]
Adds the ability for project admins to manage materials collections.
- Loading branch information
1 parent
dc20450
commit 66e635b
Showing
15 changed files
with
417 additions
and
115 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
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 |
---|---|---|
@@ -1,2 +1,60 @@ | ||
class MaterialsCollectionPolicy < ApplicationPolicy | ||
|
||
class Scope < Scope | ||
def resolve | ||
if user && user.has_role?('admin') | ||
all | ||
elsif user | ||
# prevents a bunch of unnecessary model loads by not using the user#admin_for_project_cohorts method | ||
scope | ||
.joins("INNER JOIN admin_project_users __apu_scope ON __apu_scope.project_id = materials_collections.project_id") | ||
.where("__apu_scope.user_id = ? AND __apu_scope.is_admin = 1", user.id) | ||
else | ||
none | ||
end | ||
end | ||
end | ||
|
||
def new? | ||
admin_or_project_admin? | ||
end | ||
|
||
def create? | ||
check_project | ||
end | ||
|
||
def edit? | ||
check_project | ||
end | ||
|
||
def update? | ||
check_project | ||
end | ||
|
||
def show? | ||
check_project | ||
end | ||
|
||
def destroy? | ||
check_project | ||
end | ||
|
||
def sort_materials? | ||
check_project | ||
end | ||
|
||
def remove_material? | ||
check_project | ||
end | ||
|
||
private | ||
|
||
def check_project | ||
if(record.project) | ||
admin? || user.is_project_admin?(record.project) | ||
else | ||
admin_or_project_admin? | ||
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
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
Oops, something went wrong.