mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 06:35:56 +08:00
Update Yomu gem, add reset protocols creator user assignments and extract missing asset texts rake tasks [SCI-9812] (#6761)
This commit is contained in:
parent
4df097b251
commit
e2342ace6c
|
@ -50,7 +50,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: https://github.com/scinote-eln/yomu
|
||||
revision: 020ab670b2919f3b436e926a890d1dad23d75676
|
||||
revision: 09b7b4910f59453970aab03d7b3ddb60b41db89a
|
||||
branch: master
|
||||
specs:
|
||||
yomu (0.2.4)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue