From dd2611bb82631f82ef6744ef257f5eb0a6a59cd0 Mon Sep 17 00:00:00 2001 From: Ivan Kljun Date: Fri, 17 Nov 2023 07:41:12 +0100 Subject: [PATCH] Making asset sync feature switchable [SCI-9709] --- app/controllers/asset_sync_controller.rb | 7 ++++++- .../vue/shared/content/attachments/context_menu.vue | 10 ++++++---- app/serializers/asset_serializer.rb | 10 ++++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/controllers/asset_sync_controller.rb b/app/controllers/asset_sync_controller.rb index d957ee094..1ef9318f5 100644 --- a/app/controllers/asset_sync_controller.rb +++ b/app/controllers/asset_sync_controller.rb @@ -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 diff --git a/app/javascript/vue/shared/content/attachments/context_menu.vue b/app/javascript/vue/shared/content/attachments/context_menu.vue index da89b61cd..3ce4acfae 100644 --- a/app/javascript/vue/shared/content/attachments/context_menu.vue +++ b/app/javascript/vue/shared/content/attachments/context_menu.vue @@ -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, diff --git a/app/serializers/asset_serializer.rb b/app/serializers/asset_serializer.rb index 0b344a64a..9f601f7f2 100644 --- a/app/serializers/asset_serializer.rb +++ b/app/serializers/asset_serializer.rb @@ -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