From d181465e121f11c5e21801adba8d2c7fc67452c6 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Tue, 24 Oct 2023 13:51:25 +0200 Subject: [PATCH] Fix initialization and add download endpoint [SCI-9465] --- app/controllers/asset_sync_controller.rb | 10 +++++++--- app/serializers/asset_sync_token_serializer.rb | 2 +- config/initializers/extends.rb | 4 +++- config/routes.rb | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/asset_sync_controller.rb b/app/controllers/asset_sync_controller.rb index c271fc518..00b51ef30 100644 --- a/app/controllers/asset_sync_controller.rb +++ b/app/controllers/asset_sync_controller.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class AssetSyncController < ApplicationController - skip_before_action :authenticate_user!, only: :update - skip_before_action :verify_authenticity_token, only: :update - before_action :authenticate_asset_sync_token!, only: :update + 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) def show asset = Asset.find_by(id: params[:asset_id]) @@ -19,6 +19,10 @@ class AssetSyncController < ApplicationController render json: AssetSyncTokenSerializer.new(asset_sync_token).as_json end + def download + redirect_to @asset.file.url + end + def update head(:conflict) and return if @asset_sync_token.conflicts?(request.headers['VersionToken']) diff --git a/app/serializers/asset_sync_token_serializer.rb b/app/serializers/asset_sync_token_serializer.rb index cccf23a36..87ded4ad6 100644 --- a/app/serializers/asset_sync_token_serializer.rb +++ b/app/serializers/asset_sync_token_serializer.rb @@ -10,7 +10,7 @@ class AssetSyncTokenSerializer < ActiveModel::Serializer end def url - object.asset.file.url + asset_sync_download_url(asset_id: object.asset) end def filename diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index f4719ef2e..73cd9b033 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -610,7 +610,9 @@ class Extends www.gstatic.com/recaptcha/ ) - EXTERNAL_SERVICES << Constants::ASSET_SYNC_URL unless EXTERNAL_SERVICES.include?(Constants::ASSET_SYNC_URL) + if Constants::ASSET_SYNC_URL && EXTERNAL_SERVICES.exclude?(Constants::ASSET_SYNC_URL) + EXTERNAL_SERVICES << Constants::ASSET_SYNC_URL + end COLORED_BACKGROUND_ACTIONS = %w( my_modules/protocols diff --git a/config/routes.rb b/config/routes.rb index 1d61ab2db..82b899f8a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1003,6 +1003,7 @@ Rails.application.routes.draw do end get 'asset_sync/:asset_id', to: 'asset_sync#show', as: :asset_sync_show + get 'asset_sync/:asset_id/download', to: 'asset_sync#download', as: :asset_sync_download put 'asset_sync', to: 'asset_sync#update' post 'global_activities', to: 'global_activities#index'