effective_storage 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +11 -2
- data/app/controllers/admin/storage_controller.rb +1 -9
- data/app/controllers/effective/storage_controller.rb +12 -0
- data/app/datatables/admin/effective_storage_datatable.rb +53 -29
- data/app/models/concerns/active_storage_authorization.rb +3 -0
- data/app/models/concerns/{active_storage_attachment_extension.rb → active_storage_blob_extension.rb} +10 -4
- data/app/models/effective/active_storage_extension.rb +1 -1
- data/app/views/admin/storage/_datatable_actions.html.haml +8 -4
- data/config/routes.rb +8 -0
- data/db/migrate/01_create_effective_storage.rb.erb +1 -1
- data/lib/effective_storage/engine.rb +1 -1
- data/lib/effective_storage/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6b647a6cc8602078845e0112be3346f284705778fd081694deacf161a7ebf91
|
4
|
+
data.tar.gz: 1340ad269815fc10141936f997da57860a30ecdbb760658706fc84cb69281d64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c28337427ce9d4ef0782cf951a2b1bb6e5004b7ef3f4f7df842dfe54e2dc5dfe1578576a03d38bb55de85f0c504a5c1896b586a7f57f9c16768d75504f42f93
|
7
|
+
data.tar.gz: 307df9a832e70ae1709b0a24e6d665e1de1fedbad5d21d1b4347d8976ead29acd39682ffaac5eb83d0adc66f21c077139721df5d0e9707391b0996775e4c859e
|
data/README.md
CHANGED
@@ -61,14 +61,23 @@ All authorization checks are handled via the effective_resources gem found in th
|
|
61
61
|
The permissions you actually want to define are as follows (using CanCan):
|
62
62
|
|
63
63
|
```ruby
|
64
|
-
|
64
|
+
# Allow anyone to download a public file
|
65
|
+
can(:show, ActiveStorage::Blob) { |blob| blob.permission_public? }
|
65
66
|
|
66
67
|
if user.persisted?
|
67
68
|
end
|
68
69
|
|
69
70
|
if user.admin?
|
71
|
+
# This allows the admin to download any file
|
72
|
+
can :show, ActiveStorage::Blob
|
73
|
+
|
74
|
+
# Allows them to see the index screen
|
70
75
|
can :admin, :effective_storage
|
71
|
-
can :index, ActiveStorage::
|
76
|
+
can :index, ActiveStorage::Blob
|
77
|
+
|
78
|
+
# Admin screen actions
|
79
|
+
can(:mark_inherited, ActiveStorage::Blob) { |blob| !blob.permission_inherited? }
|
80
|
+
can(:mark_public, ActiveStorage::Blob) { |blob| !blob.permission_public? }
|
72
81
|
end
|
73
82
|
```
|
74
83
|
|
@@ -6,15 +6,7 @@ module Admin
|
|
6
6
|
include Effective::CrudController
|
7
7
|
|
8
8
|
page_title 'Storage'
|
9
|
-
|
10
|
-
resource_scope -> { ActiveStorage::Attachment.all }
|
9
|
+
resource_scope -> { ActiveStorage::Blob.all }
|
11
10
|
datatable -> { Admin::EffectiveStorageDatatable.new }
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def permitted_params
|
16
|
-
params.require(:active_storage_extension).permit!
|
17
|
-
end
|
18
|
-
|
19
11
|
end
|
20
12
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Effective
|
2
|
+
class StorageController < ApplicationController
|
3
|
+
include Effective::CrudController
|
4
|
+
|
5
|
+
resource_scope -> { ActiveStorage::Blob.all }
|
6
|
+
|
7
|
+
before_action(if: -> { params.key?(:id) }) do
|
8
|
+
@blob = ActiveStorage::Blob.find_signed(params[:id])
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -1,62 +1,86 @@
|
|
1
1
|
module Admin
|
2
2
|
class EffectiveStorageDatatable < Effective::Datatable
|
3
|
-
|
4
|
-
|
3
|
+
filters do
|
4
|
+
scope :all
|
5
|
+
scope :attached
|
6
|
+
scope :unattached
|
7
|
+
end
|
5
8
|
|
9
|
+
datatable do
|
6
10
|
col :created_at, as: :date
|
7
|
-
|
11
|
+
|
8
12
|
col :id, visible: false
|
13
|
+
col :key, visible: false
|
9
14
|
|
10
|
-
col :record_type, visible: false
|
11
|
-
|
15
|
+
col :record_type, visible: false do |blob|
|
16
|
+
blob.attachments.map do |attachment|
|
17
|
+
content_tag(:div, attachment.record_type, class: 'col-resource_item')
|
18
|
+
end.join.html_safe
|
19
|
+
end
|
20
|
+
|
21
|
+
col :record_id, visible: false do |blob|
|
22
|
+
blob.attachments.map do |attachment|
|
23
|
+
content_tag(:div, attachment.record_id, class: 'col-resource_item')
|
24
|
+
end.join.html_safe
|
25
|
+
end
|
12
26
|
|
13
|
-
col :related_type, visible: false do |
|
14
|
-
|
27
|
+
col :related_type, visible: false do |blob|
|
28
|
+
blob.attachments.map do |attachment|
|
29
|
+
content_tag(:div, attachment.record.try(:record_type), class: 'col-resource_item')
|
30
|
+
end.join.html_safe
|
15
31
|
end
|
16
32
|
|
17
|
-
col :related_id, label: 'Related Id'
|
18
|
-
|
33
|
+
col :related_id, visible: false, label: 'Related Id' do |blob|
|
34
|
+
blob.attachments.map do |attachment|
|
35
|
+
content_tag(:div, attachment.record.try(:record_id), class: 'col-resource_item')
|
36
|
+
end.join.html_safe
|
19
37
|
end
|
20
38
|
|
21
|
-
col :resource_type do |
|
22
|
-
|
39
|
+
col :resource_type do |blob|
|
40
|
+
blob.attachments.map do |attachment|
|
41
|
+
content_tag(:div, class: 'col-resource_item') do
|
42
|
+
(attachment.record.try(:record_type) || attachment.record_type)
|
43
|
+
end
|
44
|
+
end.join.html_safe
|
23
45
|
end
|
24
46
|
|
25
|
-
col :resource do |
|
26
|
-
|
27
|
-
|
47
|
+
col :resource do |blob|
|
48
|
+
blob.attachments.map do |attachment|
|
49
|
+
content_tag(:div, class: 'col-resource_item') do
|
50
|
+
record = attachment.record
|
51
|
+
record = attachment.record.record if record.respond_to?(:record) # ActionText::RichText will
|
28
52
|
|
29
|
-
|
30
|
-
|
53
|
+
url = Effective::Resource.new(record, namespace: :admin).action_path(:edit)
|
54
|
+
link_to(record, url, target: '_blank') if url
|
55
|
+
end
|
56
|
+
end.join.html_safe
|
31
57
|
end
|
32
58
|
|
33
|
-
col :filename, label: 'File' do |
|
59
|
+
col :filename, label: 'File' do |blob|
|
34
60
|
content_tag(:div, class: 'col-resource_item') do
|
35
|
-
link_to(
|
61
|
+
link_to(blob.filename, url_for(blob), target: '_blank')
|
36
62
|
end
|
37
63
|
end
|
38
64
|
|
39
|
-
col :permission, search: Effective::ActiveStorageExtension::PERMISSIONS do |
|
40
|
-
if
|
41
|
-
content_tag(:span,
|
65
|
+
col :permission, search: Effective::ActiveStorageExtension::PERMISSIONS do |blob|
|
66
|
+
if blob.permission_public?
|
67
|
+
content_tag(:span, blob.permission, class: 'badge badge-warning')
|
42
68
|
else
|
43
|
-
content_tag(:span,
|
69
|
+
content_tag(:span, blob.permission, class: 'badge badge-info')
|
44
70
|
end
|
45
71
|
end
|
46
72
|
|
47
|
-
col :content_type
|
48
|
-
attachment.blob.content_type
|
49
|
-
end
|
73
|
+
col :content_type
|
50
74
|
|
51
|
-
col :byte_size do |
|
52
|
-
number_to_human_size(
|
75
|
+
col :byte_size do |blob|
|
76
|
+
number_to_human_size(blob.byte_size)
|
53
77
|
end
|
54
78
|
|
55
|
-
actions_col partial: 'admin/storage/datatable_actions', partial_as: :
|
79
|
+
actions_col partial: 'admin/storage/datatable_actions', partial_as: :blob
|
56
80
|
end
|
57
81
|
|
58
82
|
collection do
|
59
|
-
ActiveStorage::
|
83
|
+
ActiveStorage::Blob.all.deep.left_outer_joins(:attachments)
|
60
84
|
end
|
61
85
|
|
62
86
|
end
|
@@ -55,6 +55,9 @@ module ActiveStorageAuthorization
|
|
55
55
|
def authorize_active_storage!
|
56
56
|
return unless @blob.present?
|
57
57
|
|
58
|
+
# If the blob has been given permission
|
59
|
+
return true if authorized?(@blob)
|
60
|
+
|
58
61
|
# If the blob is not attached to anything, permit the blob
|
59
62
|
return true if @blob.attachments.blank? && authorize_content_download?(@blob)
|
60
63
|
|
data/app/models/concerns/{active_storage_attachment_extension.rb → active_storage_blob_extension.rb}
RENAMED
@@ -1,12 +1,14 @@
|
|
1
1
|
# This is included into ActiveStorage::Attachment automatically by engine.rb
|
2
|
-
module
|
2
|
+
module ActiveStorageBlobExtension
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
has_many :active_storage_extensions, class_name: 'Effective::ActiveStorageExtension', inverse_of: :
|
6
|
+
has_many :active_storage_extensions, class_name: 'Effective::ActiveStorageExtension', inverse_of: :blob, dependent: :destroy
|
7
7
|
accepts_nested_attributes_for :active_storage_extensions, allow_destroy: true
|
8
8
|
|
9
|
-
scope :deep, -> { includes(:active_storage_extensions, :
|
9
|
+
scope :deep, -> { includes(:active_storage_extensions, attachments: [record: :record]) }
|
10
|
+
|
11
|
+
scope :attached, -> { joins(:attachments) }
|
10
12
|
end
|
11
13
|
|
12
14
|
module ClassMethods
|
@@ -15,7 +17,7 @@ module ActiveStorageAttachmentExtension
|
|
15
17
|
# Instance methods
|
16
18
|
|
17
19
|
def to_s
|
18
|
-
'
|
20
|
+
filename.presence || 'blob'
|
19
21
|
end
|
20
22
|
|
21
23
|
# Find or build
|
@@ -45,4 +47,8 @@ module ActiveStorageAttachmentExtension
|
|
45
47
|
save!
|
46
48
|
end
|
47
49
|
|
50
|
+
def purge!
|
51
|
+
purge
|
52
|
+
end
|
53
|
+
|
48
54
|
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
= dropdown(variation: :dropleft) do
|
2
|
-
- if EffectiveResources.authorized?(self, :mark_inherited,
|
3
|
-
= dropdown_link_to 'Mark as Inherited', effective_storage.mark_inherited_admin_storage_path(
|
2
|
+
- if EffectiveResources.authorized?(self, :mark_inherited, blob)
|
3
|
+
= dropdown_link_to 'Mark as Inherited', effective_storage.mark_inherited_admin_storage_path(blob),
|
4
4
|
data: { method: :post, remote: true, confirm: "Mark as Inherited Permission?" }
|
5
5
|
|
6
|
-
- if EffectiveResources.authorized?(self, :mark_public,
|
7
|
-
= dropdown_link_to 'Mark as Public', effective_storage.mark_public_admin_storage_path(
|
6
|
+
- if EffectiveResources.authorized?(self, :mark_public, blob)
|
7
|
+
= dropdown_link_to 'Mark as Public', effective_storage.mark_public_admin_storage_path(blob),
|
8
8
|
data: { method: :post, remote: true, confirm: "Mark as Public Permission?" }
|
9
|
+
|
10
|
+
- if EffectiveResources.authorized?(self, :purge, blob)
|
11
|
+
= dropdown_link_to 'Delete', effective_storage.purge_admin_storage_path(blob),
|
12
|
+
data: { method: :post, remote: true, confirm: "Really delete #{blob.to_s}?" }
|
data/config/routes.rb
CHANGED
@@ -5,13 +5,21 @@ Rails.application.routes.draw do
|
|
5
5
|
end
|
6
6
|
|
7
7
|
EffectiveStorage::Engine.routes.draw do
|
8
|
+
scope module: 'effective' do
|
9
|
+
resources :storage, only: [] do
|
10
|
+
post :mark_public, on: :member
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
namespace :admin do
|
9
15
|
resources :storage, only: [] do
|
10
16
|
post :mark_inherited, on: :member
|
11
17
|
post :mark_public, on: :member
|
18
|
+
post :purge, on: :member
|
12
19
|
end
|
13
20
|
|
14
21
|
get '/storage', to: 'storage#index', as: :storage
|
22
|
+
|
15
23
|
end
|
16
24
|
|
17
25
|
end
|
@@ -10,7 +10,7 @@ module EffectiveStorage
|
|
10
10
|
# Include active_storage_attachment_extension concern
|
11
11
|
initializer 'effective_storage.active_storage_attachment_extension' do |app|
|
12
12
|
app.config.to_prepare do
|
13
|
-
ActiveStorage::
|
13
|
+
ActiveStorage::Blob.include(ActiveStorageBlobExtension)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
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
|
+
version: 0.2.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: 2022-08-
|
11
|
+
date: 2022-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -133,10 +133,11 @@ files:
|
|
133
133
|
- README.md
|
134
134
|
- Rakefile
|
135
135
|
- app/controllers/admin/storage_controller.rb
|
136
|
+
- app/controllers/effective/storage_controller.rb
|
136
137
|
- app/datatables/admin/effective_storage_datatable.rb
|
137
138
|
- app/helpers/effective_storage_helper.rb
|
138
|
-
- app/models/concerns/active_storage_attachment_extension.rb
|
139
139
|
- app/models/concerns/active_storage_authorization.rb
|
140
|
+
- app/models/concerns/active_storage_blob_extension.rb
|
140
141
|
- app/models/effective/active_storage_extension.rb
|
141
142
|
- app/views/admin/storage/_datatable_actions.html.haml
|
142
143
|
- app/views/admin/storage/index.html.haml
|