mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-25 01:03:18 +08:00
Merge pull request #3691 from okriuchykhin/ok_SCI_6289
Fix user assignments migration, all assignments are automatic [SCI-6289]
This commit is contained in:
commit
21c97027c1
1 changed files with 7 additions and 7 deletions
|
@ -21,6 +21,8 @@ class MigrateToNewUserRoles < ActiveRecord::Migration[6.1]
|
|||
end
|
||||
dir.down do
|
||||
UserAssignment.joins(:user_role).where(user_role: { predefined: true }).delete_all
|
||||
Project.where(default_public_user_role: UserRole.where(predefined: true))
|
||||
.update_all(default_public_user_role_id: nil)
|
||||
UserRole.where(predefined: true).delete_all
|
||||
end
|
||||
end
|
||||
|
@ -28,13 +30,11 @@ class MigrateToNewUserRoles < ActiveRecord::Migration[6.1]
|
|||
|
||||
private
|
||||
|
||||
def new_user_assignment(user, assignable, user_role, assigned = :manually, existing_assignments = {})
|
||||
return if existing_assignments[[user.id, assignable.id, assignable.class.name]]
|
||||
|
||||
def new_user_assignment(user, assignable, user_role)
|
||||
UserAssignment.new(
|
||||
user: user,
|
||||
assignable: assignable,
|
||||
assigned: assigned,
|
||||
assigned: :automatically,
|
||||
user_role: user_role
|
||||
)
|
||||
end
|
||||
|
@ -52,11 +52,11 @@ class MigrateToNewUserRoles < ActiveRecord::Migration[6.1]
|
|||
unassigned_users = team.users.reject { |u| already_assigned_user_ids.include?(u.id) }
|
||||
|
||||
unassigned_users.each do |user|
|
||||
user_assignments << new_user_assignment(user, project, viewer_role, :automatically)
|
||||
user_assignments << new_user_assignment(user, project, viewer_role)
|
||||
project.experiments.each do |experiment|
|
||||
user_assignments << new_user_assignment(user, experiment, viewer_role, :automatically)
|
||||
user_assignments << new_user_assignment(user, experiment, viewer_role)
|
||||
experiment.my_modules.each do |my_module|
|
||||
user_assignments << new_user_assignment(user, my_module, viewer_role, :automatically)
|
||||
user_assignments << new_user_assignment(user, my_module, viewer_role)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue