Skip to content

Commit 13a6c8b

Browse files
committed
Consider the assigner in assignment policies
The policy doesn't check if the assigner is authorized to add an assignee to a package. As of now everyone can add an assigne. We have to check if the assigner is a collaborator as well.
1 parent dcf1bba commit 13a6c8b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/api/app/policies/assignment_policy.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@
44
class AssignmentPolicy < ApplicationPolicy
55
def create?
66
return false unless Flipper.enabled?(:foster_collaboration, user)
7-
87
return true if user.admin?
8+
return false unless assigneer_is_a_collaborator?
99

1010
record.assignee_is_a_collaborator?
1111
end
1212

1313
def destroy?
1414
create?
1515
end
16+
17+
private
18+
19+
def assigneer_is_a_collaborator?
20+
collaborators = (record.package.relationships + record.package.project.relationships).map(&:user)
21+
return false if collaborators.empty?
22+
23+
collaborators.include?(user)
24+
end
1625
end

0 commit comments

Comments
 (0)