effective_trash 0.3.2 → 0.4.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: fd64b9818e00706023f8e7756ceaa5dcdfd6ef01
4
- data.tar.gz: afd0d089858ce9067dfc015e4df141d55f808411
2
+ SHA256:
3
+ metadata.gz: 9af7c36500a43728404435cf41766d2b49835ded249048d04302eb99f76e55aa
4
+ data.tar.gz: 5e943b5ddf135a9bd2c93bf4c7e1e05e3cb3a20996b53d4afe2e64f271729b7b
5
5
  SHA512:
6
- metadata.gz: b6c67bc50bda291c33831e20fc0a2680929abe593d2d6515a2311ff9867cb6492901a159467b4e3261bf326488d4432516c3548f92d3a3fd43fba8a85484dc72
7
- data.tar.gz: 9b5d9185ff36a93efacd8eca43777901e89ce07dfad4cbe19f1747edd4fc086b0656ac080f6a049d6dfdb8709d71dd5b923fef20c6252d0a5ab89d0c92da6028
6
+ metadata.gz: 75c2bce4d510729ac5a54d584dc8ef645d6fde9d819014d1ac346190a453a4a37c696a3493751481f43461b616df5597088c5400c14dd45f096753d5a296c9a8
7
+ data.tar.gz: b3050933b150df392b026c14312b5b063c0579442e682d2794d27af924bc5aa53f82990f24d79a6becacc0f3e3188c41d80f8ab40f0cb72fc308a55f4754c3c0
@@ -11,16 +11,16 @@ module Admin
11
11
 
12
12
  @page_title = 'Trash'
13
13
 
14
- EffectiveTrash.authorize!(self, :index, Effective::Trash)
15
- EffectiveTrash.authorize!(self, :admin, :effective_trash)
14
+ EffectiveResources.authorize!(self, :index, Effective::Trash)
15
+ EffectiveResources.authorize!(self, :admin, :effective_trash)
16
16
  end
17
17
 
18
18
  def show
19
19
  @trash = Effective::Trash.all.find(params[:id])
20
20
  @page_title = "Trash item - #{@trash.trashed_to_s}"
21
21
 
22
- EffectiveTrash.authorize!(self, :show, @trash)
23
- EffectiveTrash.authorize!(self, :admin, :effective_trash)
22
+ EffectiveResources.authorize!(self, :show, @trash)
23
+ EffectiveResources.authorize!(self, :admin, :effective_trash)
24
24
  end
25
25
  end
26
26
  end
@@ -8,7 +8,7 @@ module Effective
8
8
 
9
9
  @page_title = 'Trash'
10
10
 
11
- EffectiveTrash.authorize!(self, :index, Effective::Trash.new(user_id: current_user.id))
11
+ EffectiveResources.authorize!(self, :index, Effective::Trash.new(user_id: current_user.id))
12
12
  end
13
13
 
14
14
  # This is the User show event
@@ -16,12 +16,12 @@ module Effective
16
16
  @trash = Effective::Trash.where(user_id: current_user.id).find(params[:id])
17
17
  @page_title = "Trash item - #{@trash.to_s}"
18
18
 
19
- EffectiveTrash.authorize!(self, :show, @trash)
19
+ EffectiveResources.authorize!(self, :show, @trash)
20
20
  end
21
21
 
22
22
  def restore
23
23
  @trash = Effective::Trash.find(params[:id])
24
- EffectiveTrash.authorize!(self, :update, @trash)
24
+ EffectiveResources.authorize!(self, :update, @trash)
25
25
 
26
26
  Effective::Trash.transaction do
27
27
  begin
@@ -6,7 +6,11 @@ module ActsAsTrashable
6
6
  @acts_as_trashable_options = options.try(:first) || {}
7
7
 
8
8
  unless @acts_as_trashable_options.kind_of?(Hash)
9
- raise ArgumentError.new("invalid arguments passed to (effective_trash) acts_as_trashable. Expecting no options.")
9
+ raise ArgumentError.new("invalid arguments passed to (effective_trash) acts_as_trashable.")
10
+ end
11
+
12
+ if (unknown = (@acts_as_trashable_options.keys - [:only, :except])).present?
13
+ raise ArgumentError.new("unknown keyword: #{unknown.join(', ')}")
10
14
  end
11
15
 
12
16
  include ::ActsAsTrashable
@@ -22,20 +26,17 @@ module ActsAsTrashable
22
26
 
23
27
  # Parse Options
24
28
  acts_as_trashable_options = {
25
- only: Array(@acts_as_trashable_options[:only]).map { |attribute| attribute.to_s },
26
- except: Array(@acts_as_trashable_options[:except]).map { |attribute| attribute.to_s },
27
- additionally: Array(@acts_as_trashable_options[:additionally]).map { |attribute| attribute.to_s },
28
- include_associated: @acts_as_trashable_options.fetch(:include_associated, true),
29
- include_nested: @acts_as_trashable_options.fetch(:include_nested, true)
29
+ only: Array(@acts_as_trashable_options[:only]),
30
+ except: Array(@acts_as_trashable_options[:except]),
30
31
  }
31
32
 
32
33
  self.send(:define_method, :acts_as_trashable_options) { acts_as_trashable_options }
33
34
  end
34
35
 
35
36
  module ClassMethods
37
+ def acts_as_trashable?; true; end
36
38
  end
37
39
 
38
40
  # Regular instance methods
39
41
 
40
42
  end
41
-
@@ -2,27 +2,6 @@ EffectiveTrash.setup do |config|
2
2
  # Configure Database Table
3
3
  config.trash_table_name = :trash
4
4
 
5
- # Authorization Method
6
- #
7
- # This method is called by all controller actions with the appropriate action and resource
8
- # If the method returns false, an Effective::AccessDenied Error will be raised (see README.md for complete info)
9
- #
10
- # Use via Proc (and with CanCan):
11
- # config.authorization_method = Proc.new { |controller, action, resource| can?(action, resource) }
12
- #
13
- # Use via custom method:
14
- # config.authorization_method = :my_authorization_method
15
- #
16
- # And then in your application_controller.rb:
17
- #
18
- # def my_authorization_method(action, resource)
19
- # current_user.is?(:admin)
20
- # end
21
- #
22
- # Or disable the check completely:
23
- # config.authorization_method = false
24
- config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) } # CanCanCan
25
-
26
5
  # Admin Screens Layout Settings
27
6
  config.layout = 'application' # All EffectiveTrash controllers will use this layout
28
7
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveTrash
2
- VERSION = '0.3.2'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -4,33 +4,13 @@ require 'effective_trash/version'
4
4
 
5
5
  module EffectiveTrash
6
6
 
7
- # The following are all valid config keys
8
- mattr_accessor :trash_table_name
9
-
10
- mattr_accessor :authorization_method
11
- mattr_accessor :layout
12
- mattr_accessor :routes_enabled
13
-
14
- def self.setup
15
- yield self
7
+ def self.config_keys
8
+ [
9
+ :trash_table_name, :layout, :routes_enabled
10
+ ]
16
11
  end
17
12
 
18
- def self.authorized?(controller, action, resource)
19
- @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
20
-
21
- return !!authorization_method unless authorization_method.respond_to?(:call)
22
- controller = controller.controller if controller.respond_to?(:controller)
23
-
24
- begin
25
- !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
26
- rescue *@_exceptions
27
- false
28
- end
29
- end
30
-
31
- def self.authorize!(controller, action, resource)
32
- raise Effective::AccessDenied unless authorized?(controller, action, resource)
33
- end
13
+ include EffectiveGem
34
14
 
35
15
  # This is set by the "set_effective_trash_current_user" before_filter.
36
16
  def self.current_user=(user)
@@ -44,18 +24,15 @@ module EffectiveTrash
44
24
  # Trash it - Does not delete the original object.
45
25
  # This is run in a before_destroy, or through a script.
46
26
  def self.trash!(obj)
47
- args = if obj.respond_to?(:acts_as_trashable_options)
48
- obj.acts_as_trashable_options.slice(:include_associated, :include_nested)
49
- else
50
- { include_associated: true, include_nested: true }
51
- end
27
+ args = (obj.respond_to?(:acts_as_trashable_options) ? obj.acts_as_trashable_options : {})
28
+ details = Effective::Resource.new(obj).instance_attributes(only: args[:only], except: args[:except])
52
29
 
53
30
  trash = Effective::Trash.new(
54
31
  trashed: obj,
55
32
  user: EffectiveTrash.current_user,
56
33
  trashed_to_s: obj.to_s,
57
- trashed_extra: (trashed_extra if obj.respond_to?(:trashed_extra)),
58
- details: Effective::Resource.new(obj).instance_attributes(args)
34
+ trashed_extra: obj.try(:trashed_extra),
35
+ details: details
59
36
  ).save!
60
37
  end
61
38
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_trash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-19 00:00:00.000000000 Z
11
+ date: 2023-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,7 +80,6 @@ files:
80
80
  - app/datatables/effective_trash_datatable.rb
81
81
  - app/helpers/effective_trash_helper.rb
82
82
  - app/models/concerns/acts_as_trashable.rb
83
- - app/models/effective/access_denied.rb
84
83
  - app/models/effective/trash.rb
85
84
  - app/views/admin/trash/_actions.html.haml
86
85
  - app/views/admin/trash/index.html.haml
@@ -102,7 +101,7 @@ homepage: https://github.com/code-and-effect/effective_trash
102
101
  licenses:
103
102
  - MIT
104
103
  metadata: {}
105
- post_install_message:
104
+ post_install_message:
106
105
  rdoc_options: []
107
106
  require_paths:
108
107
  - lib
@@ -117,9 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
116
  - !ruby/object:Gem::Version
118
117
  version: '0'
119
118
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.4.5.1
122
- signing_key:
119
+ rubygems_version: 3.1.2
120
+ signing_key:
123
121
  specification_version: 4
124
122
  summary: Trash and Restore any Active Record object.
125
123
  test_files: []
@@ -1,17 +0,0 @@
1
- unless defined?(Effective::AccessDenied)
2
- module Effective
3
- class AccessDenied < StandardError
4
- attr_reader :action, :subject
5
-
6
- def initialize(message = nil, action = nil, subject = nil)
7
- @message = message
8
- @action = action
9
- @subject = subject
10
- end
11
-
12
- def to_s
13
- @message || I18n.t(:'unauthorized.default', :default => 'Access Denied')
14
- end
15
- end
16
- end
17
- end