Fix initialization and add download endpoint [SCI-9465]

This commit is contained in:
Martin Artnik 2023-10-24 13:51:25 +02:00
parent 2031286261
commit d181465e12
4 changed files with 12 additions and 5 deletions

View file

@ -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'])

View file

@ -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

View file

@ -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

View file

@ -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'