mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 02:04:33 +08:00
Assign user to public projects after adding to a team [SCI-7295]
This commit is contained in:
parent
7fbac92f9c
commit
9a05bf04bd
1 changed files with 16 additions and 0 deletions
|
@ -3,7 +3,9 @@
|
|||
class UserAssignment < ApplicationRecord
|
||||
before_validation -> { self.team ||= (assignable.is_a?(Team) ? assignable : assignable.team) }
|
||||
after_create :assign_shared_inventories, if: -> { assignable.is_a?(Team) }
|
||||
after_create :assign_public_projects, if: -> { assignable.is_a?(Team) }
|
||||
before_destroy :unassign_shared_inventories, if: -> { assignable.is_a?(Team) }
|
||||
before_destroy :unassign_public_projects, if: -> { assignable.is_a?(Team) }
|
||||
|
||||
belongs_to :assignable, polymorphic: true, touch: true
|
||||
belongs_to :user_role
|
||||
|
@ -38,7 +40,21 @@ class UserAssignment < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def assign_public_projects
|
||||
assignable.projects.visible.find_each do |project|
|
||||
UserAssignments::GroupAssignmentJob.perform_later(
|
||||
assignable,
|
||||
project,
|
||||
assigned_by
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def unassign_shared_inventories
|
||||
assignable.repository_sharing_user_assignments.where(user: user).find_each(&:destroy!)
|
||||
end
|
||||
|
||||
def unassign_public_projects
|
||||
UserAssignments::RemoveUserAssignmentJob.perform_now(user, assignable)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue