add require file links auth toggle

This commit is contained in:
Pete Matsyburka committed 2024-04-15 20:34:00 +03:00
1 parent 652b0da021
commit fc679bcd72
6 files changed
+43 -8

No files matched your search

@@ -20,6 +20,8 @@ module Api
blob = ActiveStorage::Blob.find_by!(uuid: blob_uuid)
authorization_check!(blob) if exp.blank?
if request.headers['Range'].present?
send_blob_byte_range_data blob, request.headers['Range']
else
@@ -31,5 +33,20 @@ module Api
end
end
end
private
def authorization_check!(blob)
is_authorized =
blob.attachments.all? do |a|
a.name.in?(%w[logo preview_images]) ||
(current_user && a.record.account.id == current_user.account_id) ||
!a.record.account.account_configs.find_or_initialize_by(key: AccountConfig::DOWNLOAD_LINKS_AUTH_KEY).value
end
return if is_authorized
raise CanCan::AccessDenied
end
end
end