effective_trash 0.3.3 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -2
- data/app/controllers/admin/trash_controller.rb +4 -4
- data/app/controllers/effective/trash_controller.rb +3 -3
- data/app/models/concerns/acts_as_trashable.rb +1 -1
- data/config/effective_trash.rb +0 -21
- data/lib/effective_trash/set_current_user.rb +6 -2
- data/lib/effective_trash/version.rb +1 -1
- data/lib/effective_trash.rb +8 -27
- metadata +6 -8
- data/app/models/effective/access_denied.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a74c78184cb3ec900ce2336bd3cc00b2f4db31df0743aae8f0c0e81345cc262e
|
4
|
+
data.tar.gz: 1e79f5bfacebcda566c36b5f11ce271be53e5f975294fb49babd82e349c98f0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85d54f6faddf75ef480bd44c6a81c12013aca4ca3f63c81a64f228be7cda2cf8720a6743d2871c0f7d191c70431837ebe07086e3aff5fb0c56f70459219b365b
|
7
|
+
data.tar.gz: 3bc56877b4ec4abd95d7958aa945375c64ff16463b244514c0fef3dd9c2c2210e46a67c14e2a25921c1ad8871e278972fdfac1e8d87fd9aa0aedfa1966f55ccd
|
data/README.md
CHANGED
@@ -46,7 +46,7 @@ and to your contoller:
|
|
46
46
|
|
47
47
|
```ruby
|
48
48
|
class ApplicationController < ActionController::Base
|
49
|
-
|
49
|
+
around_action :set_effective_trash_current_user
|
50
50
|
end
|
51
51
|
```
|
52
52
|
|
@@ -114,4 +114,3 @@ MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
|
114
114
|
4. Push to the branch (`git push origin my-new-feature`)
|
115
115
|
5. Bonus points for test coverage
|
116
116
|
6. Create new Pull Request
|
117
|
-
|
@@ -11,16 +11,16 @@ module Admin
|
|
11
11
|
|
12
12
|
@page_title = 'Trash'
|
13
13
|
|
14
|
-
|
15
|
-
|
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
|
-
|
23
|
-
|
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
|
-
|
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
|
-
|
19
|
+
EffectiveResources.authorize!(self, :show, @trash)
|
20
20
|
end
|
21
21
|
|
22
22
|
def restore
|
23
23
|
@trash = Effective::Trash.find(params[:id])
|
24
|
-
|
24
|
+
EffectiveResources.authorize!(self, :update, @trash)
|
25
25
|
|
26
26
|
Effective::Trash.transaction do
|
27
27
|
begin
|
data/config/effective_trash.rb
CHANGED
@@ -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
|
|
@@ -6,10 +6,14 @@ module EffectiveTrash
|
|
6
6
|
# before_action :set_effective_trash_current_user
|
7
7
|
|
8
8
|
def set_effective_trash_current_user
|
9
|
-
|
9
|
+
begin
|
10
|
+
EffectiveTrash.current_user = current_user
|
11
|
+
yield
|
12
|
+
ensure
|
13
|
+
EffectiveTrash.current_user = nil
|
14
|
+
end
|
10
15
|
end
|
11
16
|
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
15
|
-
|
data/lib/effective_trash.rb
CHANGED
@@ -4,33 +4,13 @@ require 'effective_trash/version'
|
|
4
4
|
|
5
5
|
module EffectiveTrash
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
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)
|
@@ -45,13 +25,14 @@ module EffectiveTrash
|
|
45
25
|
# This is run in a before_destroy, or through a script.
|
46
26
|
def self.trash!(obj)
|
47
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])
|
48
29
|
|
49
30
|
trash = Effective::Trash.new(
|
50
31
|
trashed: obj,
|
51
32
|
user: EffectiveTrash.current_user,
|
52
33
|
trashed_to_s: obj.to_s,
|
53
|
-
trashed_extra:
|
54
|
-
details:
|
34
|
+
trashed_extra: obj.try(:trashed_extra),
|
35
|
+
details: details
|
55
36
|
).save!
|
56
37
|
end
|
57
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.
|
4
|
+
version: 0.4.1
|
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:
|
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
|
-
|
121
|
-
|
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
|