debian-mirror-gitlab/app/controllers/concerns/workhorse_authorization.rb

44 lines
980 B
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
2021-02-22 17:27:13 +05:30
module WorkhorseAuthorization
2020-06-23 00:09:42 +05:30
extend ActiveSupport::Concern
include WorkhorseRequest
included do
skip_before_action :verify_authenticity_token, only: %i[authorize]
before_action :verify_workhorse_api!, only: %i[authorize]
end
def authorize
set_workhorse_internal_api_content_type
2021-02-22 17:27:13 +05:30
authorized = uploader_class.workhorse_authorize(
2020-06-23 00:09:42 +05:30
has_length: false,
2021-02-22 17:27:13 +05:30
maximum_size: maximum_size.to_i)
2020-06-23 00:09:42 +05:30
render json: authorized
rescue SocketError
render json: _("Error uploading file"), status: :internal_server_error
end
private
def file_is_valid?(file)
return false unless file.is_a?(::UploadedFile)
2021-12-11 22:18:48 +05:30
file_extension_allowlist.include?(File.extname(file.original_filename).downcase.delete('.'))
2021-02-22 17:27:13 +05:30
end
def uploader_class
raise NotImplementedError
end
def maximum_size
raise NotImplementedError
end
2021-12-11 22:18:48 +05:30
def file_extension_allowlist
ImportExportUploader::EXTENSION_ALLOWLIST
2020-06-23 00:09:42 +05:30
end
end