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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 90216d115aad9b5d601ab5a9ae4c3c890d41467f
4
- data.tar.gz: a9e51b014d5e077cecb05fcb136a37396395c62d
2
+ SHA256:
3
+ metadata.gz: 551cba3e0dd8ee2f2f1f3f33dff704266e1632c41a0a9be9a745ca94e7f3b9d6
4
+ data.tar.gz: ff18025529636321a5463e47d8c6d9439422558a7c761153a151c599879406a0
5
5
  SHA512:
6
- metadata.gz: 4587181367aa4b8eb8f81037dfe2107f9e8a3e2bebe9b210bf4e4762a4aa6752565083e1b08b140defb89e2724dc8273c7e9801d69f366222ab98fd7e667009c
7
- data.tar.gz: 81952d5af6365ac77374b5eb95afc28fe3af7eddfb005b8f8859a37390de413d59c284aedfa43e28d44a04f5bd1487c5761ea18e651686e8e964bb4aed8652f4
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.10'
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
+ ```
@@ -1,17 +1,13 @@
1
1
  en:
2
- active_admin:
3
- delete_model: "Archive %{model}"
4
- delete: "Archive"
5
- delete_confirmation: "Are you sure you want to archive this?"
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
- delete_confirmation: "Are you sure you want to archive these %{plural_model}?"
8
- succesfully_destroyed:
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,6 +1,7 @@
1
1
  module ActiveAdminParanoia
2
2
  # Default Authorization permission for ActiveAdminParanoia
3
3
  module Authorization
4
+ ARCHIVE = :do_archive
4
5
  RESTORE = :restore
5
6
  PERMANENT_DELETE = :permanent_delete
6
7
  end
@@ -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.to_s.camelize.constantize.with_deleted.where(id: params[:id]).first!
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, confirm: proc{ I18n.t('active_admin.batch_actions.delete_confirmation', plural_model: resource_class.to_s.downcase.pluralize) }, if: proc{ authorized?(ActiveAdmin::Auth::DESTROY, resource_class) && params[:scope] != 'archived' } do |ids|
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.to_s.camelize.constantize.restore(ids, recursive: true)
17
- redirect_to :back, notice: I18n.t('active_admin_paranoia.batch_actions.succesfully_restored', count: ids.count, model: resource_class.to_s.camelize.constantize.model_name, plural_model: resource_class.to_s.downcase.pluralize)
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
- redirect_to :back, notice: I18n.t('active_admin_paranoia.batch_actions.succesfully_restored', count: 1, model: resource_class.to_s.camelize.constantize.model_name, plural_model: resource_class.to_s.downcase.pluralize)
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(resource_class.to_s.camelize.constantize.paranoia_column => resource_class.to_s.camelize.constantize.paranoia_sentinel_value) }
30
- scope(I18n.t('active_admin_paranoia.archived')) { |scope| scope.unscope(:where => resource_class.to_s.camelize.constantize.paranoia_column).where.not(resource_class.to_s.camelize.constantize.paranoia_column => resource_class.to_s.camelize.constantize.paranoia_sentinel_value) }
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
@@ -1,3 +1,3 @@
1
1
  module ActiveAdminParanoia
2
- VERSION = '1.0.10'
2
+ VERSION = '1.0.12'
3
3
  end
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.10
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: 2017-06-29 00:00:00.000000000 Z
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
- rubyforge_project:
83
- rubygems_version: 2.2.5
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: []