From 9a05bf04bd67dba54909e48d0c8057df40b6f574 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Wed, 5 Oct 2022 22:40:46 +0200 Subject: [PATCH] Assign user to public projects after adding to a team [SCI-7295] --- app/models/user_assignment.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/models/user_assignment.rb b/app/models/user_assignment.rb index 426471e1b..8271dee63 100644 --- a/app/models/user_assignment.rb +++ b/app/models/user_assignment.rb @@ -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