active_admin_paranoia 1.0.10 → 1.0.12
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 +5 -5
- data/README.md +15 -1
- data/config/locales/en.yml +6 -10
- data/lib/active_admin_paranoia/authorization.rb +1 -0
- data/lib/active_admin_paranoia/dsl.rb +54 -11
- 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
@@ -5,7 +5,7 @@ This gem extends ActiveAdmin so that batch restore and batch archive actions wil
|
|
5
5
|
This gem assumes that you have already configured [paranoia](https://github.com/radar/paranoia) for you desire resource. Add this line to your application's Gemfile:
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
gem "active_admin_paranoia" , '~> 1.0.
|
8
|
+
gem "active_admin_paranoia" , '~> 1.0.11'
|
9
9
|
|
10
10
|
```
|
11
11
|
|
@@ -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,33 +1,76 @@
|
|
1
1
|
module ActiveAdminParanoia
|
2
2
|
module DSL
|
3
3
|
def active_admin_paranoia
|
4
|
+
archived_at_column = config.resource_class.paranoia_column
|
5
|
+
not_archived_value = config.resource_class.paranoia_sentinel_value
|
6
|
+
|
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) }
|
10
|
+
# For more info, see here: https://github.com/rails/rails/pull/22506
|
11
|
+
if Rails::VERSION::MAJOR >= 5
|
12
|
+
controller.redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(**options))
|
13
|
+
else
|
14
|
+
controller.redirect_to :back, options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
4
18
|
controller do
|
5
19
|
def find_resource
|
6
|
-
resource_class.
|
20
|
+
resource_class.with_deleted.public_send(method_for_find, params[:id])
|
7
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)
|
8
33
|
end
|
9
34
|
|
10
|
-
batch_action :destroy,
|
11
|
-
resource_class.to_s.camelize.constantize.where(id: ids).destroy_all
|
12
|
-
redirect_to :back, notice: I18n.t('active_admin.batch_actions.succesfully_destroyed', count: ids.count, model: resource_class.to_s.camelize.constantize.model_name, plural_model: resource_class.to_s.downcase.pluralize)
|
35
|
+
batch_action :destroy, if: proc { false } do
|
13
36
|
end
|
14
37
|
|
15
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|
|
16
|
-
resource_class.
|
17
|
-
|
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) }
|
41
|
+
# For more info, see here: https://github.com/rails/rails/pull/22506
|
42
|
+
if Rails::VERSION::MAJOR >= 5
|
43
|
+
redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(**options))
|
44
|
+
else
|
45
|
+
redirect_to :back, options
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
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)
|
18
51
|
end
|
19
52
|
|
20
|
-
action_item :restore, only: :show do
|
53
|
+
action_item :restore, only: :show, if: proc { resource.send(archived_at_column) } do
|
21
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)
|
22
55
|
end
|
23
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
|
+
|
24
61
|
member_action :restore, method: :put, confirm: proc{ I18n.t('active_admin_paranoia.restore_confirmation') }, if: proc{ authorized?(ActiveAdminParanoia::Auth::RESTORE, resource_class) } do
|
25
62
|
resource.restore(recursive: true)
|
26
|
-
|
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) }
|
64
|
+
# For more info, see here: https://github.com/rails/rails/pull/22506
|
65
|
+
if Rails::VERSION::MAJOR >= 5
|
66
|
+
redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(**options))
|
67
|
+
else
|
68
|
+
redirect_to :back, options
|
69
|
+
end
|
27
70
|
end
|
28
71
|
|
29
|
-
scope(I18n.t('active_admin_paranoia.non_archived'), default: true) { |scope| scope.where(
|
30
|
-
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) }
|
31
74
|
end
|
32
75
|
end
|
33
76
|
end
|
@@ -38,7 +81,7 @@ module ActiveAdmin
|
|
38
81
|
class IndexTableFor < ::ActiveAdmin::Views::TableFor
|
39
82
|
alias_method :orig_defaults, :defaults
|
40
83
|
|
41
|
-
def defaults(resource, options
|
84
|
+
def defaults(resource, **options)
|
42
85
|
if resource.respond_to?(:deleted?) && resource.deleted?
|
43
86
|
if controller.action_methods.include?('restore') && authorized?(ActiveAdminParanoia::Auth::RESTORE, resource)
|
44
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: []
|