scinote-web/app/jobs/user_assignments/group_assignment_job.rb
artoscinote 78ab094bf2
Implement public user grouping, deletion and updates to manually assigned [SCI-6228] (#3701)
* Implement public user grouping, deletion and updates to manually assigned [SCI-6228]

* PR fixes [SCI-6228]

* Permission check improvement [SCI-6228]
2021-12-01 16:23:24 +01:00

36 lines
966 B
Ruby

# frozen_string_literal: true
module UserAssignments
class GroupAssignmentJob < ApplicationJob
queue_as :high_priority
def perform(team, project, assigned_by)
@team = team
@assigned_by = assigned_by
ActiveRecord::Base.transaction do
team.users.where.not(id: assigned_by.id).find_each do |user|
user_assignment = UserAssignment.find_or_initialize_by(
user: user,
assignable: project
)
next if user_assignment.manually_assigned?
user_assignment.update!(
user_role: project.default_public_user_role,
assigned_by: @assigned_by
)
# make sure all related experiments and my modules are assigned
UserAssignments::PropagateAssignmentJob.perform_later(
project,
user,
project.default_public_user_role,
@assigned_by
)
end
end
end
end
end