effective_storage 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e291eec4a68519b15b3bd9364f6ee39f82efcfcdf5a50b9503716feb74685e60
4
- data.tar.gz: febfb716cde67d02e88b9f2ec5d819a40a961ab2a467e76dd9201ddaec58562c
3
+ metadata.gz: d31c97986b5166e4bd1fa34d329ea5a6b8f7c355a9ab952f010100ba8ed33f63
4
+ data.tar.gz: e88cce63f52489de5fed02e3c5119f4ff17cb5ca07fba05472b15d5cfcfdd814
5
5
  SHA512:
6
- metadata.gz: d7ababb553f86b947c43c9b25ce0f7afcb6469477c1777c0f641e687f90b11da385a92f40859f02ec474b61324d23851f6a05695f53a7858f7079704c141cc7f
7
- data.tar.gz: b99b47de7953cca44d41430184d0fc92b6520638674ed02096ee8e45d24676fe55c84d14ac8f8e6224ddf3a05b6e76d3a4b2facae078c3dad652c0791fbec24c
6
+ metadata.gz: 405aa9bb4a51b937c3c551af74327774078418ed01e96b13340806c0dca6dc6fc1bd9824147d3472f65aec8bdc8db49d9dfe5903215e87ee17f3958aefa3f518
7
+ data.tar.gz: d6058d78e87602fdfbb7639e0e66628c691edd6c22c1823c6697343a8ede5359d09da98c3daa729f146c2e608cc1bf66045cad9785c228d01e1b69ce4b60d55f
@@ -67,8 +67,8 @@ module ActiveStorageAuthorization
67
67
  # If we are authorized on any attached record, permit the download
68
68
  return true if @blob.attachments.any? { |attachment| authorized_attachment_download?(attachment) }
69
69
 
70
- # Otherwise raise a 403 Forbidden and block the download
71
- head(:forbidden, 'X-Robots-Tag': 'noindex')
70
+ # Otherwise raise a 404 Not Found and block the download
71
+ head(:not_found)
72
72
 
73
73
  # Raise an exception to log unauthorized request
74
74
  raise_exception()
@@ -47,8 +47,55 @@ module ActiveStorageBlobExtension
47
47
  save!
48
48
  end
49
49
 
50
+ # The purge! command is not part of the regular ActiveStorage::Blob class
51
+ # This is the command called by the admin/storage datatable
52
+ # When config.never_delete_active_storage is enabled, this is the only way to delete a Blob
53
+ # And they will not be deleted in the background.
50
54
  def purge!
51
- purge
55
+ before = EffectiveStorage.never_delete
56
+
57
+ begin
58
+ EffectiveStorage.never_delete = false
59
+ purge
60
+ ensure
61
+ EffectiveStorage.never_delete = before
62
+ end
63
+ end
64
+
65
+ def delete
66
+ if EffectiveStorage.never_delete?
67
+ Rails.logger.info "[effective_storage] Skipping ActiveStorage::Blob delete"
68
+ return
69
+ end
70
+
71
+ super
72
+ end
73
+
74
+ def destroy
75
+ if EffectiveStorage.never_delete?
76
+ Rails.logger.info "[effective_storage] Skipping ActiveStorage::Blob destroy"
77
+ return
78
+ end
79
+
80
+ super
81
+ end
82
+
83
+ def purge
84
+ if EffectiveStorage.never_delete?
85
+ Rails.logger.info "[effective_storage] Skipping ActiveStorage::Blob purge"
86
+ return
87
+ end
88
+
89
+ super
90
+ end
91
+
92
+ def purge_later
93
+ if EffectiveStorage.never_delete?
94
+ Rails.logger.info "[effective_storage] Skipping ActiveStorage::Blob purge_later"
95
+ return
96
+ end
97
+
98
+ super
52
99
  end
53
100
 
54
101
  end
@@ -6,4 +6,7 @@ EffectiveStorage.setup do |config|
6
6
  # Perform authorization on ActiveStorage downloads
7
7
  # When false any request will be permitted (the default)
8
8
  config.authorize_active_storage = true
9
+
10
+ # Do not delete ActiveStorage::Blobs
11
+ config.never_delete = true
9
12
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveStorage
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -6,7 +6,7 @@ require 'effective_storage/version'
6
6
  module EffectiveStorage
7
7
 
8
8
  def self.config_keys
9
- [:layout, :authorize_active_storage]
9
+ [:layout, :authorize_active_storage, :never_delete]
10
10
  end
11
11
 
12
12
  include EffectiveGem
@@ -15,4 +15,8 @@ module EffectiveStorage
15
15
  authorize_active_storage == true
16
16
  end
17
17
 
18
+ def self.never_delete?
19
+ never_delete == true
20
+ end
21
+
18
22
  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.3.1
4
+ version: 0.4.0
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-02-15 00:00:00.000000000 Z
11
+ date: 2023-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails