Update Yomu gem, add reset protocols creator user assignments and extract missing asset texts rake tasks [SCI-9812] (#6761)

This commit is contained in:
Alex Kriuchykhin 2023-12-05 13:27:20 +01:00 committed by GitHub
parent 4df097b251
commit e2342ace6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View file

@ -50,7 +50,7 @@ GIT
GIT
remote: https://github.com/scinote-eln/yomu
revision: 020ab670b2919f3b436e926a890d1dad23d75676
revision: 09b7b4910f59453970aab03d7b3ddb60b41db89a
branch: master
specs:
yomu (0.2.4)

View file

@ -1,3 +1,7 @@
# frozen_string_literal: true
# rubocop:disable Metrics/BlockLength
namespace :data do
Rails.logger = Logger.new(STDOUT)
@ -5,7 +9,6 @@ namespace :data do
task clean_temp_files: :environment do
Rails.logger.info "Cleaning temporary files older than 3 days"
TempFile.where("created_at < ?", 3.days.ago).each do |tmp_file|
TempFile.transaction do
begin
tmp_file.destroy!
@ -194,4 +197,37 @@ namespace :data do
end
end
end
desc 'Reset protocols creator user assignments'
task reset_protocols_creator_user_assignments: :environment do
ActiveRecord::Base.transaction do
owner_role = UserRole.find_predefined_owner_role
protocols =
Protocol.where(protocol_type: Protocol::REPOSITORY_TYPES)
.joins('LEFT OUTER JOIN "user_assignments" ON "user_assignments"."assignable_type" = \'Protocol\' ' \
'AND "user_assignments"."assignable_id" = "protocols"."id" ' \
'AND "user_assignments"."assigned" = 1 ' \
'AND "user_assignments"."user_id" = "protocols"."added_by_id"')
.where('"user_assignments"."id" IS NULL')
.distinct
protocols.find_each do |protocol|
new_user_assignment = protocol.user_assignments
.find_or_initialize_by(user: protocol.added_by, team: protocol.team)
new_user_assignment.user_role = owner_role
new_user_assignment.assigned_by = protocol.added_by
new_user_assignment.assigned = :manually
new_user_assignment.save!
end
end
end
desc 'Extract missing asset texts'
task extract_missing_asset_texts: :environment do
Asset.joins(:file_blob)
.where.missing(:asset_text_datum)
.where(file_blob: { content_type: Constants::TEXT_EXTRACT_FILE_TYPES })
.find_each(&:extract_asset_text)
end
end
# rubocop:enable Metrics/BlockLength