active_admin_paranoia 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +14 -0
- data/config/locales/en.yml +6 -10
- data/lib/active_admin_paranoia/authorization.rb +1 -0
- data/lib/active_admin_paranoia/dsl.rb +44 -19
- data/lib/active_admin_paranoia/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 551cba3e0dd8ee2f2f1f3f33dff704266e1632c41a0a9be9a745ca94e7f3b9d6
|
4
|
+
data.tar.gz: ff18025529636321a5463e47d8c6d9439422558a7c761153a151c599879406a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1759ec05951777f9f933fb9bc976fb55c0a02fbd6e56827ca4d8af7153d337053f896c25c64164b32e3fbfd12224c57a095e58c93a8015a182f6f474527595c3
|
7
|
+
data.tar.gz: 32259512a954d3171bdf9e04d4da9411dfceb92450bbe80539025538688e39d036f08c2f0dcbaed76dfce7f3e46985f45754043458200ab241f3ffe56194456e
|
data/README.md
CHANGED
@@ -20,3 +20,17 @@ ActiveAdmin.register Post do
|
|
20
20
|
active_admin_paranoia
|
21
21
|
end
|
22
22
|
```
|
23
|
+
|
24
|
+
# Archiving (soft delete) vs Deleting (hard delete)
|
25
|
+
|
26
|
+
The "Archive" button will call `#destroy` to soft delete the resource by setting the `deleted_at` column to the current time.
|
27
|
+
The "Delete" button will call `#really_destroy!` to hard delete the resource (by removing the records from the database).
|
28
|
+
|
29
|
+
You can disable hard deletion by removing the `:destroy` action:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
ActiveAdmin.register Post do
|
33
|
+
active_admin_paranoia
|
34
|
+
actions :all, except: [:destroy]
|
35
|
+
end
|
36
|
+
```
|
data/config/locales/en.yml
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
en:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
active_admin_paranoia:
|
3
|
+
archive_model: "Archive %{model}"
|
4
|
+
archive: "Archive"
|
5
|
+
archive_confirmation: "Are you sure you want to archive this?"
|
6
6
|
batch_actions:
|
7
|
-
|
8
|
-
|
7
|
+
archive_confirmation: "Are you sure you want to archive these %{plural_model}?"
|
8
|
+
succesfully_archived:
|
9
9
|
one: "Successfully archived 1 %{model}"
|
10
10
|
other: "Successfully archived %{count} %{plural_model}"
|
11
|
-
labels:
|
12
|
-
destroy: "Archive"
|
13
|
-
active_admin_paranoia:
|
14
|
-
batch_actions:
|
15
11
|
restore_confirmation: "Are you sure you want to restore these %{plural_model}?"
|
16
12
|
succesfully_restored:
|
17
13
|
one: "Successfully restored 1 %{model}"
|
@@ -1,51 +1,76 @@
|
|
1
1
|
module ActiveAdminParanoia
|
2
2
|
module DSL
|
3
3
|
def active_admin_paranoia
|
4
|
-
|
5
|
-
|
6
|
-
resource_class.to_s.camelize.constantize.with_deleted.where(id: params[:id]).first!
|
7
|
-
end
|
8
|
-
end
|
4
|
+
archived_at_column = config.resource_class.paranoia_column
|
5
|
+
not_archived_value = config.resource_class.paranoia_sentinel_value
|
9
6
|
|
10
|
-
|
11
|
-
resource_class.
|
12
|
-
options = { notice: I18n.t('
|
7
|
+
do_archive = proc do |ids, resource_class, controller|
|
8
|
+
resource_class.where(id: ids).destroy_all
|
9
|
+
options = { notice: I18n.t('active_admin_paranoia.batch_actions.succesfully_archived', count: ids.count, model: resource_class.model_name, plural_model: resource_class.to_s.downcase.pluralize) }
|
13
10
|
# For more info, see here: https://github.com/rails/rails/pull/22506
|
14
11
|
if Rails::VERSION::MAJOR >= 5
|
15
|
-
redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(options))
|
12
|
+
controller.redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(**options))
|
16
13
|
else
|
17
|
-
redirect_to :back, options
|
14
|
+
controller.redirect_to :back, options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
controller do
|
19
|
+
def find_resource
|
20
|
+
resource_class.with_deleted.public_send(method_for_find, params[:id])
|
18
21
|
end
|
22
|
+
|
23
|
+
# The "Delete" button should now really destroy the resource. (Click "Archive" to soft delete.)
|
24
|
+
# Remove the delete button with the following line:
|
25
|
+
# actions :all, except: [:destroy]
|
26
|
+
def destroy_resource(object)
|
27
|
+
object.really_destroy!
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
batch_action :archive, confirm: proc{ I18n.t('active_admin_paranoia.batch_actions.archive_confirmation', plural_model: resource_class.to_s.downcase.pluralize) }, if: proc{ authorized?(ActiveAdminParanoia::Auth::ARCHIVE, resource_class) && params[:scope] != 'archived' } do |ids|
|
32
|
+
do_archive.call(ids, resource_class, self)
|
33
|
+
end
|
34
|
+
|
35
|
+
batch_action :destroy, if: proc { false } do
|
19
36
|
end
|
20
37
|
|
21
38
|
batch_action :restore, confirm: proc{ I18n.t('active_admin_paranoia.batch_actions.restore_confirmation', plural_model: resource_class.to_s.downcase.pluralize) }, if: proc{ authorized?(ActiveAdminParanoia::Auth::RESTORE, resource_class) && params[:scope] == 'archived' } do |ids|
|
22
|
-
resource_class.
|
23
|
-
options = { notice: I18n.t('active_admin_paranoia.batch_actions.succesfully_restored', count: ids.count, model: resource_class.
|
39
|
+
resource_class.restore(ids, recursive: true)
|
40
|
+
options = { notice: I18n.t('active_admin_paranoia.batch_actions.succesfully_restored', count: ids.count, model: resource_class.model_name, plural_model: resource_class.to_s.downcase.pluralize) }
|
24
41
|
# For more info, see here: https://github.com/rails/rails/pull/22506
|
25
42
|
if Rails::VERSION::MAJOR >= 5
|
26
|
-
redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(options))
|
43
|
+
redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(**options))
|
27
44
|
else
|
28
45
|
redirect_to :back, options
|
29
46
|
end
|
30
47
|
end
|
31
48
|
|
32
|
-
action_item :
|
49
|
+
action_item :archive, only: :show, if: proc { !resource.send(archived_at_column) } do
|
50
|
+
link_to(I18n.t('active_admin_paranoia.archive_model', model: resource_class.to_s.titleize), "#{resource_path(resource)}/archive", method: :put, data: { confirm: I18n.t('active_admin_paranoia.archive_confirmation') }) if authorized?(ActiveAdminParanoia::Auth::ARCHIVE, resource)
|
51
|
+
end
|
52
|
+
|
53
|
+
action_item :restore, only: :show, if: proc { resource.send(archived_at_column) } do
|
33
54
|
link_to(I18n.t('active_admin_paranoia.restore_model', model: resource_class.to_s.titleize), "#{resource_path(resource)}/restore", method: :put, data: { confirm: I18n.t('active_admin_paranoia.restore_confirmation') }) if authorized?(ActiveAdminParanoia::Auth::RESTORE, resource)
|
34
55
|
end
|
35
56
|
|
57
|
+
member_action :archive, method: :put, confirm: proc{ I18n.t('active_admin_paranoia.archive_confirmation') }, if: proc{ authorized?(ActiveAdminParanoia::Auth::ARCHIVE, resource_class) } do
|
58
|
+
do_archive.call([resource.id], resource_class, self)
|
59
|
+
end
|
60
|
+
|
36
61
|
member_action :restore, method: :put, confirm: proc{ I18n.t('active_admin_paranoia.restore_confirmation') }, if: proc{ authorized?(ActiveAdminParanoia::Auth::RESTORE, resource_class) } do
|
37
62
|
resource.restore(recursive: true)
|
38
|
-
options = { notice: I18n.t('active_admin_paranoia.batch_actions.succesfully_restored', count: 1, model: resource_class.
|
63
|
+
options = { notice: I18n.t('active_admin_paranoia.batch_actions.succesfully_restored', count: 1, model: resource_class.model_name, plural_model: resource_class.to_s.downcase.pluralize) }
|
39
64
|
# For more info, see here: https://github.com/rails/rails/pull/22506
|
40
65
|
if Rails::VERSION::MAJOR >= 5
|
41
|
-
redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(options))
|
66
|
+
redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(**options))
|
42
67
|
else
|
43
68
|
redirect_to :back, options
|
44
69
|
end
|
45
70
|
end
|
46
71
|
|
47
|
-
scope(I18n.t('active_admin_paranoia.non_archived'), default: true) { |scope| scope.where(
|
48
|
-
scope(I18n.t('active_admin_paranoia.archived')) { |scope| scope.unscope(:where =>
|
72
|
+
scope(I18n.t('active_admin_paranoia.non_archived'), default: true, show_count: false) { |scope| scope.unscope(:where => archived_at_column).where(archived_at_column => not_archived_value) }
|
73
|
+
scope(I18n.t('active_admin_paranoia.archived'), show_count: false) { |scope| scope.unscope(:where => archived_at_column).where.not(archived_at_column => not_archived_value) }
|
49
74
|
end
|
50
75
|
end
|
51
76
|
end
|
@@ -56,7 +81,7 @@ module ActiveAdmin
|
|
56
81
|
class IndexTableFor < ::ActiveAdmin::Views::TableFor
|
57
82
|
alias_method :orig_defaults, :defaults
|
58
83
|
|
59
|
-
def defaults(resource, options
|
84
|
+
def defaults(resource, **options)
|
60
85
|
if resource.respond_to?(:deleted?) && resource.deleted?
|
61
86
|
if controller.action_methods.include?('restore') && authorized?(ActiveAdminParanoia::Auth::RESTORE, resource)
|
62
87
|
# TODO: find a way to use the correct path helper
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_admin_paranoia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miah Raihan Mahmud Arman
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -64,7 +64,7 @@ homepage: https://github.com/raihan2006i/active_admin_paranoia
|
|
64
64
|
licenses:
|
65
65
|
- MIT
|
66
66
|
metadata: {}
|
67
|
-
post_install_message:
|
67
|
+
post_install_message:
|
68
68
|
rdoc_options: []
|
69
69
|
require_paths:
|
70
70
|
- lib
|
@@ -79,9 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
|
-
|
83
|
-
|
84
|
-
signing_key:
|
82
|
+
rubygems_version: 3.4.19
|
83
|
+
signing_key:
|
85
84
|
specification_version: 4
|
86
85
|
summary: Paranoia extension for ActiveAdmin
|
87
86
|
test_files: []
|