mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 21:55:20 +08:00
Merge pull request #8686 from aignatov-bio/ai-sci-11839-update-team-export-import-script
Update team/export import script [SCI-11839]
This commit is contained in:
commit
396e04b99f
3 changed files with 67 additions and 3 deletions
|
@ -47,6 +47,9 @@ module ModelExporters
|
|||
user_assignments: @experiment.user_assignments.map do |ua|
|
||||
user_assignment(ua)
|
||||
end,
|
||||
team_assignments: @experiment.team_assignments.map do |ta|
|
||||
team_assignment(ta)
|
||||
end,
|
||||
my_modules: my_modules.map { |m| my_module(m) },
|
||||
my_module_groups: my_module_groups
|
||||
}, @assets_to_copy
|
||||
|
@ -61,12 +64,24 @@ module ModelExporters
|
|||
}
|
||||
end
|
||||
|
||||
def team_assignment(team_assignment)
|
||||
{
|
||||
team_id: team_assignment.team_id,
|
||||
assigned_by_id: team_assignment.assigned_by_id,
|
||||
role_name: team_assignment.user_role.name,
|
||||
assigned: team_assignment.assigned
|
||||
}
|
||||
end
|
||||
|
||||
def my_module(my_module)
|
||||
{
|
||||
my_module: my_module,
|
||||
user_assignments: my_module.user_assignments.map do |ua|
|
||||
user_assignment(ua)
|
||||
end,
|
||||
team_assignments: my_module.team_assignments.map do |ta|
|
||||
team_assignment(ta)
|
||||
end,
|
||||
my_module_status_name: my_module.my_module_status&.name,
|
||||
outputs: my_module.outputs,
|
||||
my_module_tags: my_module.my_module_tags,
|
||||
|
|
|
@ -51,9 +51,14 @@ module ModelExporters
|
|||
tiny_mce_assets: team.tiny_mce_assets.map { |tma| tiny_mce_asset_data(tma) },
|
||||
protocols: team.protocols.where(my_module: nil).map do |pr|
|
||||
protocol(pr).merge(
|
||||
user_assignments: pr.user_assignments.map do |ua|
|
||||
user_assignment(ua)
|
||||
end
|
||||
{
|
||||
user_assignments: pr.user_assignments.map do |ua|
|
||||
user_assignment(ua)
|
||||
end,
|
||||
team_assignments: pr.team_assignments.map do |ta|
|
||||
team_assigment(ta)
|
||||
end
|
||||
}
|
||||
)
|
||||
end,
|
||||
protocol_keywords: team.protocol_keywords,
|
||||
|
@ -102,6 +107,9 @@ module ModelExporters
|
|||
user_assignments: project.user_assignments.map do |ua|
|
||||
user_assignment(ua)
|
||||
end,
|
||||
team_assignments: project.team_assignments.map do |ta|
|
||||
team_assigment(ta)
|
||||
end,
|
||||
activities: project.activities,
|
||||
project_comments: project.project_comments,
|
||||
reports: project.reports.map { |r| report(r) },
|
||||
|
@ -120,12 +128,24 @@ module ModelExporters
|
|||
}
|
||||
end
|
||||
|
||||
def team_assigment(team_assignment)
|
||||
{
|
||||
team_id: team_assignment.team_id,
|
||||
assigned_by_id: team_assignment.assigned_by_id,
|
||||
role_name: team_assignment.user_role.name,
|
||||
assigned: team_assignment.assigned
|
||||
}
|
||||
end
|
||||
|
||||
def report(report)
|
||||
{
|
||||
report: report,
|
||||
user_assignments: report.user_assignments.map do |ua|
|
||||
user_assignment(ua)
|
||||
end,
|
||||
team_assignments: report.team_assignments.map do |ta|
|
||||
team_assigment(ta)
|
||||
end,
|
||||
report_elements: report.report_elements
|
||||
}
|
||||
end
|
||||
|
@ -145,6 +165,10 @@ module ModelExporters
|
|||
repository.user_assignments.where(team: repository.team, user: repository.team.users).map do |ua|
|
||||
user_assignment(ua)
|
||||
end
|
||||
result[:team_assignments] =
|
||||
repository.team_assignments.where(team: repository.team).map do |ta|
|
||||
team_assigment(ta)
|
||||
end
|
||||
result[:repository_snapshots] = repository.repository_snapshots.map { |r| repository(r) }
|
||||
end
|
||||
result
|
||||
|
|
|
@ -428,10 +428,12 @@ class TeamImporter
|
|||
repository.archived_by_id = find_user(repository.archived_by_id)
|
||||
repository.restored_by_id = find_user(repository.restored_by_id)
|
||||
repository.discarded_by_id = find_user(repository.discarded_by_id)
|
||||
repository.repository_template_id = nil
|
||||
repository.skip_user_assignments = true
|
||||
repository.save!
|
||||
|
||||
create_user_assignments(repository_json['user_assignments'], repository)
|
||||
create_team_assignments(repository_json['team_assignments'], repository)
|
||||
|
||||
@repository_mappings[orig_repository_id] = repository.id
|
||||
@repository_counter += 1
|
||||
|
@ -498,6 +500,7 @@ class TeamImporter
|
|||
orig_rep_row_id = repository_row.id
|
||||
repository_row.id = nil
|
||||
repository_row.repository = repository
|
||||
repository_row.my_module_id = @my_module_mappings[repository_row.my_module_id]
|
||||
repository_row.created_by_id = find_user(repository_row.created_by_id)
|
||||
repository_row.archived_by_id = find_user(repository_row.archived_by_id)
|
||||
repository_row.restored_by_id = find_user(repository_row.restored_by_id)
|
||||
|
@ -578,11 +581,14 @@ class TeamImporter
|
|||
project.restored_by_id = find_user(project.restored_by_id)
|
||||
project.skip_user_assignments = true
|
||||
project.project_folder_id = @project_folder_mappings[project.project_folder_id]
|
||||
project.supervised_by_id = find_user(project.supervised_by_id) if project.supervised_by_id
|
||||
project.save!
|
||||
@project_mappings[orig_project_id] = project.id
|
||||
@project_counter += 1
|
||||
puts 'Creating project user_assignments...'
|
||||
create_user_assignments(project_json['user_assignments'], project)
|
||||
puts 'Creating project team_assignments...'
|
||||
create_team_assignments(project_json['team_assignments'], project)
|
||||
puts 'Creating project_comments...'
|
||||
project_json['project_comments'].each do |project_comment_json|
|
||||
project_comment = ProjectComment.new(project_comment_json)
|
||||
|
@ -632,6 +638,7 @@ class TeamImporter
|
|||
@experiment_mappings[orig_experiment_id] = experiment.id
|
||||
|
||||
create_user_assignments(experiment_json['user_assignments'], experiment)
|
||||
create_team_assignments(experiment_json['team_assignments'], experiment)
|
||||
|
||||
experiment_json['my_module_groups'].each do |my_module_group_json|
|
||||
my_module_group = MyModuleGroup.new(my_module_group_json)
|
||||
|
@ -678,6 +685,7 @@ class TeamImporter
|
|||
@my_module_counter += 1
|
||||
|
||||
create_user_assignments(my_module_json['user_assignments'], my_module)
|
||||
create_team_assignments(my_module_json['team_assignments'], my_module)
|
||||
|
||||
unless @is_template
|
||||
my_module_json['my_module_tags'].each do |my_module_tag_json|
|
||||
|
@ -768,6 +776,7 @@ class TeamImporter
|
|||
protocol.save!
|
||||
|
||||
create_user_assignments(protocol_json['user_assignments'], protocol) if protocol.in_repository?
|
||||
create_team_assignments(protocol_json['team_assignments'], protocol) if protocol.in_repository?
|
||||
|
||||
@protocol_counter += 1
|
||||
@protocol_mappings[orig_protocol_id] = protocol.id
|
||||
|
@ -832,6 +841,7 @@ class TeamImporter
|
|||
elsif element_json['checklist']
|
||||
orderable = create_step_checklist(element_json['checklist'], step, user_id)
|
||||
end
|
||||
|
||||
StepOrderableElement.create!(
|
||||
position: element_json['position'],
|
||||
step: step,
|
||||
|
@ -971,6 +981,7 @@ class TeamImporter
|
|||
report.save!
|
||||
|
||||
create_user_assignments(report_json['user_assignments'], report)
|
||||
create_team_assignments(report_json['team_assignments'], report)
|
||||
|
||||
@report_mappings[orig_report_id] = report.id
|
||||
@report_counter += 1
|
||||
|
@ -1050,6 +1061,20 @@ class TeamImporter
|
|||
end
|
||||
end
|
||||
|
||||
def create_team_assignments(team_assignments_json, assignable)
|
||||
return if team_assignments_json.blank?
|
||||
|
||||
team_assignments_json.each do |team_assignment_json|
|
||||
team_assignment = TeamAssignment.new
|
||||
team_assignment.assignable = assignable
|
||||
team_assignment.team_id = @team_id
|
||||
team_assignment.user_role = @user_roles.find { |role| role.name == team_assignment_json['role_name'] }
|
||||
team_assignment.assigned = team_assignment_json['assigned']
|
||||
team_assignment.assigned_by_id = find_user(team_assignment_json['assigned_by_id'])
|
||||
team_assignment.save!
|
||||
end
|
||||
end
|
||||
|
||||
def create_cell_value(repository_cell, value_json, team)
|
||||
cell_json = value_json['repository_value']
|
||||
case repository_cell.value_type
|
||||
|
|
Loading…
Add table
Reference in a new issue