Making asset sync feature switchable [SCI-9709]

This commit is contained in:
Ivan Kljun 2023-11-17 07:41:12 +01:00
parent 6feb61d45c
commit dd2611bb82
3 changed files with 20 additions and 7 deletions

View file

@ -4,6 +4,7 @@ class AssetSyncController < ApplicationController
skip_before_action :authenticate_user!, only: %i(update download)
skip_before_action :verify_authenticity_token, only: %i(update download)
before_action :authenticate_asset_sync_token!, only: %i(update download)
before_action :check_asset_sync
def show
asset = Asset.find_by(id: params[:asset_id])
@ -42,7 +43,7 @@ class AssetSyncController < ApplicationController
render plain: Constants::ASSET_SYNC_URL
end
# private
private
def conflicting_asset_copy_token
Asset.transaction do
@ -74,4 +75,8 @@ class AssetSyncController < ApplicationController
head :forbidden unless can_manage_asset?(@asset)
end
def check_asset_sync
render_404 if ENV['ASSET_SYNC_URL'].blank?
end
end

View file

@ -102,10 +102,12 @@
emit: 'open_scinote_editor',
})
}
menu.push({
text: this.i18n.t('Open_locally'),
emit: 'open_locally'
})
if (this.attachment.attributes.urls.open_locally) {
menu.push({
text: this.i18n.t('Open_locally'),
emit: 'open_locally'
})
}
menu.push({
text: this.i18n.t('Download'),
url: this.attachment.attributes.urls.download,

View file

@ -131,14 +131,20 @@ class AssetSerializer < ActiveModel::Serializer
start_edit_image: start_edit_image_path(object),
delete: asset_destroy_path(object),
move_targets: asset_move_tagets_path(object),
move: asset_move_path(object),
open_locally: asset_sync_show_path(object)
move: asset_move_path(object)
)
end
urls[:open_vector_editor_edit] = edit_gene_sequence_asset_path(object.id) if can_manage_asset?(user, object)
urls[:open_locally] = asset_sync_show_path(object) if can_manage_asset?(user, object) && can_open_locally?
urls[:wopi_action] = object.get_action_url(user, 'embedview') if wopi && can_manage_asset?(user, object)
urls[:blob] = rails_blob_path(object.file, disposition: 'attachment') if object.file.attached?
urls
end
private
def can_open_locally?
ENV['ASSET_SYNC_URL'].present?
end
end