active_admin_paranoia 1.0.11 → 1.1.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
- SHA1:
3
- metadata.gz: cec3ccee649c706e1af5a3886157a05724d49c6e
4
- data.tar.gz: 3b032c0e20e70919ee52239b4d5fa28d6c35b251
2
+ SHA256:
3
+ metadata.gz: 055f9b72d90db702ba38dd087081760cda800b33a9879ae1df282c7557176913
4
+ data.tar.gz: 129ed49e2a62ca78b0292682cae42bad0560f333207cac8e4c9042eb2c325f80
5
5
  SHA512:
6
- metadata.gz: 3ccd4997e8c4725618b57111682ba767eb8f33b1260cfa9f4e8c9c4db9cec8ec9be35183138f27b04a18e33bc2c2edd27459b4eba38935e1ec771166c3aef783
7
- data.tar.gz: 0f12c674b89af8789e83ee36ffe02df227c25c348e548309bf6703d6a9a410923dbe720b53ac1c26e31bc7d7f4de6c3dedca00f6c88db221edf54f65585d21aa
6
+ metadata.gz: 69bb0814bad755e5550fff43ab190ceb939058a460c9eed5d19b32082a73ed0e0d62fc47a29567e41c069538deabb99baa4b8fb2660b14fa9de91d01cdc57ae8
7
+ data.tar.gz: 7ec37543fb199d9afb1cc3fb444918cef7af4c2da1f97b8a84870759a50d4441dcebea59da6b1ad4eb0b2c3a52e36833187ab9760c85be093337de9d77d63294
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
+ ```
@@ -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,51 +1,76 @@
1
1
  module ActiveAdminParanoia
2
2
  module DSL
3
3
  def active_admin_paranoia
4
- controller do
5
- def find_resource
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
- 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
- options = { 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) }
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.to_s.camelize.constantize.restore(ids, recursive: true)
23
- options = { 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) }
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 :restore, only: :show do
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.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) }
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(resource_class.to_s.camelize.constantize.paranoia_column => resource_class.to_s.camelize.constantize.paranoia_sentinel_value) }
48
- 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) }
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
@@ -1,3 +1,3 @@
1
1
  module ActiveAdminParanoia
2
- VERSION = '1.0.11'
2
+ VERSION = '1.1.0'
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.11
4
+ version: 1.1.0
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-07-25 00:00:00.000000000 Z
11
+ date: 2023-11-28 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: []