effective_storage 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce0b1d8d9b061e3e2a3b81d4662a6ff7f4bea772bb3b639068e4148867b79e7c
4
- data.tar.gz: 88115f4894e78a14807ef47eaf8af3f4f20e300ca42ac5f8e6148ff4b56aa84f
3
+ metadata.gz: de41d5679792d22ce1d00b2d9f4ba396de441a723eaef5359c8475fa00732538
4
+ data.tar.gz: 9c6e0a0c32fbcaf488ce51b3857aab7322dede9936d842783f04f2ae6eae5c17
5
5
  SHA512:
6
- metadata.gz: c261ab3931f45c6892f7c1df8780e27f0f17fdf4af5b2eb1046682c8580496f23e9275f0a649f795c91421c33a012eacce8d352d335cf7150412640f97afe16a
7
- data.tar.gz: e8bd885fe445aeb7b9b071cb101225199ff411ceb8da2194ed727ee18cb2e66d433640ef4e455190c6184ff40f1e6f350a43e67a0fc24e602ccf06a52c825917
6
+ metadata.gz: e07be03e0526dea2ebbcefb438d3ce9a4fd8d3c76eb273d15ed9bfa775b4b7f161daa37d7f189638d58ef79e571e1084ced3722d73562aa088a5cae76be46718
7
+ data.tar.gz: 5fa8b3f7a68a1b0c14dde1e29838f25570ca7bc3f48aa4434be0e95857c5a0d088af6fa67ac5d6f5a3852e85679a9b996583f25799d58bfc19426e535898d09d
@@ -14,12 +14,12 @@
14
14
  module ActiveStorageAuthorization
15
15
  extend ActiveSupport::Concern
16
16
 
17
- AUTHORIZED_EFFECTIVE_DOWNLOADS = [
18
- 'Effective::CarouselItem',
19
- 'Effective::PageBanner',
20
- 'Effective::PageSection',
17
+ AUTHORIZED_EFFECTIVE_DOWNLOADS = Set.new([
18
+ 'Effective::CarouselItem',
19
+ 'Effective::PageBanner',
20
+ 'Effective::PageSection',
21
21
  'Effective::Permalink'
22
- ]
22
+ ]).freeze
23
23
 
24
24
  included do
25
25
  rescue_from(Effective::UnauthorizedStorageException, with: :unauthorized_active_storage_request)
@@ -54,7 +54,7 @@ module ActiveStorageAuthorization
54
54
  private
55
55
 
56
56
  def set_download_blob
57
- @blob ||= ActiveStorage::Blob.where(key: decode_verified_key().try(:dig, :key)).first
57
+ @blob ||= ActiveStorage::Blob.includes(:attachments, :active_storage_extensions).where(key: decode_verified_key().try(:dig, :key)).first
58
58
  end
59
59
 
60
60
  # Authorize the current blob and prevent it from being served if unauthorized
@@ -73,12 +73,12 @@ module ActiveStorageAuthorization
73
73
  # If the blob is a known good effective class fast path it
74
74
  return true if @blob.attachments.any? { |attachment| authorized_effective_download?(attachment) }
75
75
 
76
+ # If the blob has been marked public, permit the download (in-memory check, no queries)
77
+ return true if @blob.permission_public?
78
+
76
79
  # If we are authorized on any attached record, permit the download
77
80
  return true if @blob.attachments.any? { |attachment| authorized_attachment_download?(attachment) }
78
81
 
79
- # If the blob has been given permission using Mark Public
80
- return true if authorized?(@blob)
81
-
82
82
  # Otherwise raise a 404 Not Found and block the download
83
83
  head(:not_found)
84
84
 
@@ -30,10 +30,22 @@ module EffectiveStorage
30
30
 
31
31
  ActiveStorage::Blobs::RedirectController.class_eval do
32
32
  before_action :authorize_active_storage_redirect!, only: [:show]
33
+
34
+ private
35
+
36
+ def blob_scope
37
+ ActiveStorage::Blob.includes(:attachments, :active_storage_extensions)
38
+ end
33
39
  end
34
40
 
35
41
  ActiveStorage::Representations::RedirectController.class_eval do
36
42
  before_action :authorize_active_storage_redirect!, only: [:show]
43
+
44
+ private
45
+
46
+ def blob_scope
47
+ ActiveStorage::Blob.scope_for_strict_loading.includes(:attachments, :active_storage_extensions)
48
+ end
37
49
  end
38
50
  end
39
51
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveStorage
2
- VERSION = '0.4.6'.freeze
2
+ VERSION = '0.4.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-01 00:00:00.000000000 Z
11
+ date: 2026-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails