active_admin_paranoia_2 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 94f32bf654d0593e2bfb6e6a3f0baeec0a2800857e88a0d2cb22e5d459c81852
4
+ data.tar.gz: 1f3769efa267dab4798018af0bc738b644fbd37bedc8bdf0702152bded3a6a38
5
+ SHA512:
6
+ metadata.gz: 5cce74fe3b773f15c8b60256c0a8749a5d8cba5cf950a922aa65ba8f1e843844f624467c275056cb94c5957bbb58fa9d2ee4fe0c02da0c86bd7eae3628e4db80
7
+ data.tar.gz: 5cc77c08d83280cca2f64cc2bc15651b2c551705acef9f06928483b37d68eb7d2b5f13c5ef1e93d3219711079ffeb3ddd4719f514d512d414570420515d0c9b4
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ /.idea
37
+ /.ruby-version
38
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_admin_paranoia.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Miah Raihan Mahmud Arman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # active_admin_paranoia
2
+ This gem extends ActiveAdmin so that batch restore and batch archive actions will be available in resource index page. Also 'All' and 'Archived' scope will be available for resource index page. 'All' scope will show non archived resources and 'Archived' scope will show deleted or archived resources.
3
+
4
+ # Installation
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
+
7
+ ```ruby
8
+ gem "active_admin_paranoia" , '~> 1.0.11'
9
+
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ # Usages
17
+
18
+ ```ruby
19
+ ActiveAdmin.register Post do
20
+ active_admin_paranoia
21
+ end
22
+ ```
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler"
2
+ require 'rake'
3
+ Bundler.setup
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ # Import all our rake tasks
7
+ FileList['tasks/**/*.rake'].each { |task| import task }
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/active_admin_paranoia/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'active_admin_paranoia_2'
6
+ gem.version = ActiveAdminParanoia::VERSION
7
+ gem.license = 'MIT'
8
+ gem.authors = ['Miah Raihan Mahmud Arman']
9
+ gem.email = ['raihan2006i@gmail.com']
10
+ gem.description = %q{This gem extends ActiveAdmin so that batch restore and batch archive actions will be available in resource index page. Also 'All' and 'Archived' scope will be available for resource index page. 'All' scope will show non archived resources and 'Archived' scope will show deleted or archived resources.}
11
+ gem.summary = %q{Paranoia extension for ActiveAdmin}
12
+ gem.homepage = 'https://github.com/raihan2006i/active_admin_paranoia'
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = %w(lib)
18
+
19
+ gem.add_dependency 'rails'
20
+ gem.add_dependency 'paranoia'
21
+ end
@@ -0,0 +1,24 @@
1
+ en:
2
+ active_admin:
3
+ delete_model: "Archive %{model}"
4
+ delete: "Archive"
5
+ delete_confirmation: "Are you sure you want to archive this?"
6
+ batch_actions:
7
+ delete_confirmation: "Are you sure you want to archive these %{plural_model}?"
8
+ succesfully_destroyed:
9
+ one: "Successfully archived 1 %{model}"
10
+ other: "Successfully archived %{count} %{plural_model}"
11
+ labels:
12
+ destroy: "Archive"
13
+ active_admin_paranoia:
14
+ batch_actions:
15
+ restore_confirmation: "Are you sure you want to restore these %{plural_model}?"
16
+ succesfully_restored:
17
+ one: "Successfully restored 1 %{model}"
18
+ other: "Successfully restored %{count} %{plural_model}"
19
+ archived: "Archived"
20
+ non_archived: "Non Archived"
21
+ restore_model: "Restore %{model}"
22
+ restore: "Restore"
23
+ restore_confirmation: "Are you sure you want to restore this?"
24
+ something_wrong: "Something went wrong. Please try again"
@@ -0,0 +1,9 @@
1
+ module ActiveAdminParanoia
2
+ # Default Authorization permission for ActiveAdminParanoia
3
+ module Authorization
4
+ RESTORE = :restore
5
+ PERMANENT_DELETE = :permanent_delete
6
+ end
7
+
8
+ Auth = Authorization
9
+ end
@@ -0,0 +1,73 @@
1
+ module ActiveAdminParanoia
2
+ module DSL
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
9
+
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) }
13
+ # For more info, see here: https://github.com/rails/rails/pull/22506
14
+ if Rails::VERSION::MAJOR >= 5
15
+ redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(options))
16
+ else
17
+ redirect_to :back, options
18
+ end
19
+ end
20
+
21
+ 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) }
24
+ # For more info, see here: https://github.com/rails/rails/pull/22506
25
+ if Rails::VERSION::MAJOR >= 5
26
+ redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(options))
27
+ else
28
+ redirect_to :back, options
29
+ end
30
+ end
31
+
32
+ action_item :restore, only: :show do
33
+ 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
+ end
35
+
36
+ member_action :restore, method: :put, confirm: proc{ I18n.t('active_admin_paranoia.restore_confirmation') }, if: proc{ authorized?(ActiveAdminParanoia::Auth::RESTORE, resource_class) } do
37
+ 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) }
39
+ # For more info, see here: https://github.com/rails/rails/pull/22506
40
+ if Rails::VERSION::MAJOR >= 5
41
+ redirect_back({ fallback_location: ActiveAdmin.application.root_to }.merge(options))
42
+ else
43
+ redirect_to :back, options
44
+ end
45
+ end
46
+
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) }
49
+ end
50
+ end
51
+ end
52
+
53
+ module ActiveAdmin
54
+ module Views
55
+ class IndexAsTable < ActiveAdmin::Component
56
+ class IndexTableFor < ::ActiveAdmin::Views::TableFor
57
+ alias_method :orig_defaults, :defaults
58
+
59
+ def defaults(resource, options = {})
60
+ if resource.respond_to?(:deleted?) && resource.deleted?
61
+ if controller.action_methods.include?('restore') && authorized?(ActiveAdminParanoia::Auth::RESTORE, resource)
62
+ # TODO: find a way to use the correct path helper
63
+ item I18n.t('active_admin_paranoia.restore'), "#{resource_path(resource)}/restore", method: :put, class: "restore_link #{options[:css_class]}",
64
+ data: {confirm: I18n.t('active_admin_paranoia.restore_confirmation')}
65
+ end
66
+ else
67
+ orig_defaults(resource, options)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails'
2
+
3
+ module ActiveAdminParanoia
4
+ class Engine < ::Rails::Engine
5
+
6
+ config.mount_at = '/'
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveAdminParanoia
2
+ VERSION = '1.1.0'
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'active_admin'
2
+ require 'active_admin_paranoia/version'
3
+ require 'active_admin_paranoia/engine'
4
+ require 'active_admin_paranoia/dsl'
5
+ require 'active_admin_paranoia/authorization'
6
+ ::ActiveAdmin::DSL.send(:include, ActiveAdminParanoia::DSL)
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin_paranoia_2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Miah Raihan Mahmud Arman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: paranoia
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This gem extends ActiveAdmin so that batch restore and batch archive
42
+ actions will be available in resource index page. Also 'All' and 'Archived' scope
43
+ will be available for resource index page. 'All' scope will show non archived resources
44
+ and 'Archived' scope will show deleted or archived resources.
45
+ email:
46
+ - raihan2006i@gmail.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - Gemfile
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - active_admin_paranoia.gemspec
57
+ - config/locales/en.yml
58
+ - lib/active_admin_paranoia.rb
59
+ - lib/active_admin_paranoia/authorization.rb
60
+ - lib/active_admin_paranoia/dsl.rb
61
+ - lib/active_admin_paranoia/engine.rb
62
+ - lib/active_admin_paranoia/version.rb
63
+ homepage: https://github.com/raihan2006i/active_admin_paranoia
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.2.32
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Paranoia extension for ActiveAdmin
86
+ test_files: []