effective_trash 0.2.6 → 0.3.0
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 +4 -4
- data/MIT-LICENSE +1 -1
- data/app/controllers/admin/trash_controller.rb +6 -12
- data/app/controllers/effective/trash_controller.rb +12 -16
- data/app/datatables/effective_trash_datatable.rb +31 -33
- data/app/helpers/effective_trash_helper.rb +1 -1
- data/app/models/effective/trash.rb +4 -2
- data/app/views/admin/trash/_actions.html.haml +9 -13
- data/app/views/effective/trash/_trash.html.haml +8 -3
- data/app/views/effective/trash/index.html.haml +1 -4
- data/lib/effective_trash/set_current_user.rb +4 -5
- data/lib/effective_trash/version.rb +1 -1
- data/lib/effective_trash.rb +13 -3
- metadata +4 -19
- data/app/models/effective/datatables/trash.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a76939023ec96d1a1a7616553bb4c985518e1f8
|
4
|
+
data.tar.gz: c1af33bc21f015d7eb486e5ba2b5e068b69bc222
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0431a81ded3b5a6b0b17a487fe47e9c013f671e1fc0add41a35e60f45e8815dfcc53950cfc7d5d3c29f5a14158aa1bdd1065d569a1cd6ca109c96aa8df20b559
|
7
|
+
data.tar.gz: 89576b17f5547c5949d86edd7eb9d7f78816c861b4a2ae34e66d9860370766234d7e8682aafbc1610cf8414a80aa2553e04ed5f79cc2a3add70f988943ac8a0d
|
data/MIT-LICENSE
CHANGED
@@ -2,31 +2,25 @@
|
|
2
2
|
|
3
3
|
module Admin
|
4
4
|
class TrashController < ApplicationController
|
5
|
-
|
5
|
+
before_action :authenticate_user!
|
6
6
|
|
7
7
|
layout (EffectiveTrash.layout.kind_of?(Hash) ? EffectiveTrash.layout[:admin_trash] : EffectiveTrash.layout)
|
8
8
|
|
9
|
-
helper EffectiveTrashHelper
|
10
|
-
|
11
9
|
def index
|
12
|
-
|
13
|
-
@datatable = Effective::Datatables::Trash.new
|
14
|
-
else
|
15
|
-
@datatable = EffectiveTrashDatatable.new(self)
|
16
|
-
end
|
10
|
+
@datatable = EffectiveTrashDatatable.new(self)
|
17
11
|
|
18
12
|
@page_title = 'Trash'
|
19
13
|
|
20
|
-
EffectiveTrash.
|
21
|
-
EffectiveTrash.
|
14
|
+
EffectiveTrash.authorize!(self, :index, Effective::Trash)
|
15
|
+
EffectiveTrash.authorize!(self, :admin, :effective_trash)
|
22
16
|
end
|
23
17
|
|
24
18
|
def show
|
25
19
|
@trash = Effective::Trash.all.find(params[:id])
|
26
20
|
@page_title = "Trash item - #{@trash.trashed_to_s}"
|
27
21
|
|
28
|
-
EffectiveTrash.
|
29
|
-
EffectiveTrash.
|
22
|
+
EffectiveTrash.authorize!(self, :show, @trash)
|
23
|
+
EffectiveTrash.authorize!(self, :admin, :effective_trash)
|
30
24
|
end
|
31
25
|
end
|
32
26
|
end
|
@@ -1,23 +1,14 @@
|
|
1
1
|
module Effective
|
2
2
|
class TrashController < ApplicationController
|
3
|
-
|
4
|
-
before_action :authenticate_user!
|
5
|
-
else
|
6
|
-
before_filter :authenticate_user!
|
7
|
-
end
|
3
|
+
before_action :authenticate_user!
|
8
4
|
|
9
5
|
# This is the User index event
|
10
6
|
def index
|
11
|
-
|
12
|
-
if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
13
|
-
@datatable = Effective::Datatables::Trash.new(user_id: current_user.id)
|
14
|
-
else
|
15
|
-
@datatable = EffectiveTrashDatatable.new(self, user_id: current_user.id)
|
16
|
-
end
|
7
|
+
@datatable = EffectiveTrashDatatable.new(self, user_id: current_user.id)
|
17
8
|
|
18
9
|
@page_title = 'Trash'
|
19
10
|
|
20
|
-
EffectiveTrash.
|
11
|
+
EffectiveTrash.authorize!(self, :index, Effective::Trash.new(user_id: current_user.id))
|
21
12
|
end
|
22
13
|
|
23
14
|
# This is the User show event
|
@@ -25,12 +16,12 @@ module Effective
|
|
25
16
|
@trash = Effective::Trash.where(user_id: current_user.id).find(params[:id])
|
26
17
|
@page_title = "Trash item - #{@trash.to_s}"
|
27
18
|
|
28
|
-
EffectiveTrash.
|
19
|
+
EffectiveTrash.authorize!(self, :show, @trash)
|
29
20
|
end
|
30
21
|
|
31
22
|
def restore
|
32
|
-
@trash = Effective::Trash.
|
33
|
-
EffectiveTrash.
|
23
|
+
@trash = Effective::Trash.find(params[:id])
|
24
|
+
EffectiveTrash.authorize!(self, :update, @trash)
|
34
25
|
|
35
26
|
Effective::Trash.transaction do
|
36
27
|
begin
|
@@ -42,7 +33,12 @@ module Effective
|
|
42
33
|
end
|
43
34
|
end
|
44
35
|
|
45
|
-
|
36
|
+
if request.referer.to_s.include?(effective_trash.admin_trash_index_path)
|
37
|
+
redirect_to effective_trash.admin_trash_index_path
|
38
|
+
else
|
39
|
+
redirect_to effective_trash.trash_index_path
|
40
|
+
end
|
41
|
+
|
46
42
|
end
|
47
43
|
|
48
44
|
end
|
@@ -1,47 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
order :created_at, :desc
|
1
|
+
class EffectiveTrashDatatable < Effective::Datatable
|
2
|
+
datatable do
|
3
|
+
order :created_at, :desc
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
col :created_at, label: 'Destroyed at'
|
6
|
+
col :id, visible: false
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
col :trashed_type, label: 'Type'
|
14
|
-
col :trashed_id, label: 'Original Id', visible: false
|
15
|
-
col :trashed_to_s, label: 'Item'
|
8
|
+
unless attributes[:user_id] || attributes[:user] || (attributes[:user] == false)
|
9
|
+
col :user, label: 'Destroyed by'
|
10
|
+
end
|
16
11
|
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
col :trashed_type, label: 'Type'
|
13
|
+
col :trashed_id, label: 'Original Id', visible: false
|
14
|
+
col :trashed_to_s, label: 'Item'
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
16
|
+
col :details, visible: false do |trash|
|
17
|
+
tableize_hash(trash.details)
|
24
18
|
end
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
20
|
+
unless attributes[:actions] == false
|
21
|
+
actions_col partial: 'admin/trash/actions', partial_as: :trash
|
22
|
+
end
|
23
|
+
end
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
# A nil attributes[:log_id] means give me all the top level log entries
|
26
|
+
# If we set a log_id then it's for sub trash
|
27
|
+
collection do
|
28
|
+
collection = Effective::Trash.deep.all
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
if attributes[:user_id].present?
|
31
|
+
collection = collection.where(user_id: attributes[:user_id])
|
32
|
+
end
|
38
33
|
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
if attributes[:user].present?
|
35
|
+
collection = collection.where(user: attributes[:user])
|
36
|
+
end
|
42
37
|
|
43
|
-
|
38
|
+
if attributes[:trashed_id] && attributes[:trashed_type]
|
39
|
+
collection = collection.where(trashed_id: attributes[:trashed_id], trashed_type: attributes[:trashed_type])
|
44
40
|
end
|
45
41
|
|
42
|
+
collection
|
46
43
|
end
|
44
|
+
|
47
45
|
end
|
@@ -3,7 +3,7 @@ module Effective
|
|
3
3
|
self.table_name = EffectiveTrash.trash_table_name.to_s
|
4
4
|
|
5
5
|
belongs_to :trashed, polymorphic: true # The original item type and id. Note that this object will never exist as it's deleted.
|
6
|
-
belongs_to :user
|
6
|
+
belongs_to :user # The user that destroyed the original resource
|
7
7
|
|
8
8
|
# Attributes
|
9
9
|
# trashed_type :string
|
@@ -16,7 +16,8 @@ module Effective
|
|
16
16
|
|
17
17
|
serialize :details, Hash
|
18
18
|
|
19
|
-
|
19
|
+
scope :deep, -> { includes(:user, :trashed) }
|
20
|
+
scope :sorted, -> { order(:id) }
|
20
21
|
|
21
22
|
def to_s
|
22
23
|
trashed_to_s.presence || [trashed_type, trashed_id].join(' ').presence || 'New Trash item'
|
@@ -49,6 +50,7 @@ module Effective
|
|
49
50
|
# When we delete ourselves, we restore this trash item first
|
50
51
|
def restore!
|
51
52
|
to_object.save!(validate: false)
|
53
|
+
destroy!
|
52
54
|
end
|
53
55
|
|
54
56
|
end
|
@@ -1,15 +1,11 @@
|
|
1
|
-
:
|
2
|
-
show_path =
|
3
|
-
if datatable.try(:admin_namespace?)
|
4
|
-
effective_trash.admin_trash_path(trash)
|
5
|
-
elsif datatables_admin_path?
|
6
|
-
effective_trash.admin_trash_path(trash)
|
7
|
-
else
|
8
|
-
effective_trash.trash_path(trash)
|
9
|
-
end
|
1
|
+
- show_path = (datatable.admin_namespace? ? effective_trash.admin_trash_path(trash) : effective_trash.trash_path(trash))
|
10
2
|
|
11
|
-
|
12
|
-
|
3
|
+
- if defined?(EffectiveBootstrap)
|
4
|
+
= show_icon_to(show_path)
|
5
|
+
= icon_to('repeat', effective_trash.restore_trash_path(trash), title: 'Restore', data: { confirm: 'Restore this item?'})
|
6
|
+
- else
|
7
|
+
= link_to show_path, title: 'view' do
|
8
|
+
%span.glyphicon.glyphicon-eye-open
|
13
9
|
|
14
|
-
= link_to effective_trash.restore_trash_path(trash), title: 'Restore', data: {confirm: 'Restore this item?'} do
|
15
|
-
|
10
|
+
= link_to effective_trash.restore_trash_path(trash), title: 'Restore', data: {confirm: 'Restore this item?'} do
|
11
|
+
%span.glyphicon.glyphicon-retweet
|
@@ -1,7 +1,12 @@
|
|
1
|
-
.panel.panel-default
|
2
|
-
.panel-
|
3
|
-
|
1
|
+
.panel.panel-default.card
|
2
|
+
.panel-heading.card-header
|
3
|
+
.row
|
4
|
+
.col-md-10
|
5
|
+
%p= trash.trashed_to_s
|
6
|
+
.col-md-2.text-right
|
7
|
+
= link_to 'Restore', effective_trash.restore_trash_path(trash), class: 'btn btn-primary', data: { confirm: 'Restore this item?'}
|
4
8
|
|
9
|
+
.panel-body.card-body
|
5
10
|
- if trash.trashed_extra.present?
|
6
11
|
%p= trash.trashed_extra
|
7
12
|
|
@@ -2,12 +2,11 @@ module EffectiveTrash
|
|
2
2
|
module SetCurrentUser
|
3
3
|
module ActionController
|
4
4
|
|
5
|
+
# Add me to your ApplicationController
|
6
|
+
# before_action :set_effective_trash_current_user
|
7
|
+
|
5
8
|
def set_effective_trash_current_user
|
6
|
-
|
7
|
-
EffectiveTrash.current_user = current_user
|
8
|
-
else
|
9
|
-
raise "(effective_trash) set_effective_trash_current_user expects a current_user() method to be available"
|
10
|
-
end
|
9
|
+
EffectiveTrash.current_user = current_user
|
11
10
|
end
|
12
11
|
|
13
12
|
end
|
data/lib/effective_trash.rb
CHANGED
@@ -16,10 +16,20 @@ module EffectiveTrash
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.authorized?(controller, action, resource)
|
19
|
-
if
|
20
|
-
|
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
|
21
28
|
end
|
22
|
-
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.authorize!(controller, action, resource)
|
32
|
+
raise Effective::AccessDenied unless authorized?(controller, action, resource)
|
23
33
|
end
|
24
34
|
|
25
35
|
# This is set by the "set_effective_trash_current_user" before_filter.
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: effective_datatables
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: coffee-rails
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: devise
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +81,6 @@ files:
|
|
95
81
|
- app/helpers/effective_trash_helper.rb
|
96
82
|
- app/models/concerns/acts_as_trashable.rb
|
97
83
|
- app/models/effective/access_denied.rb
|
98
|
-
- app/models/effective/datatables/trash.rb
|
99
84
|
- app/models/effective/trash.rb
|
100
85
|
- app/views/admin/trash/_actions.html.haml
|
101
86
|
- app/views/admin/trash/index.html.haml
|
@@ -1,53 +0,0 @@
|
|
1
|
-
if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
2
|
-
module Effective
|
3
|
-
module Datatables
|
4
|
-
class Trash < Effective::Datatable
|
5
|
-
include EffectiveTrashHelper
|
6
|
-
|
7
|
-
datatable do
|
8
|
-
default_order :created_at, :desc
|
9
|
-
|
10
|
-
table_column :created_at, label: 'Destroyed at'
|
11
|
-
table_column :id, visible: false
|
12
|
-
|
13
|
-
unless attributes[:user_id] || attributes[:user] || (attributes[:user] == false)
|
14
|
-
table_column :user, label: 'Destroyed by'
|
15
|
-
end
|
16
|
-
|
17
|
-
table_column :trashed_type, label: 'Type'
|
18
|
-
table_column :trashed_id, label: 'Original Id', visible: false
|
19
|
-
table_column :trashed_to_s, label: 'Item'
|
20
|
-
|
21
|
-
table_column :details, visible: false, sortable: false do |trash|
|
22
|
-
tableize_hash(trash.details, th: true, sub_th: false, width: '100%')
|
23
|
-
end
|
24
|
-
|
25
|
-
unless attributes[:actions] == false
|
26
|
-
actions_column partial: 'admin/trash/actions', partial_local: :trash
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# A nil attributes[:log_id] means give me all the top level log entries
|
31
|
-
# If we set a log_id then it's for sub trash
|
32
|
-
def collection
|
33
|
-
collection = Effective::Trash.all.includes(:user)
|
34
|
-
|
35
|
-
if attributes[:user_id].present?
|
36
|
-
collection = collection.where(user_id: attributes[:user_id])
|
37
|
-
end
|
38
|
-
|
39
|
-
if attributes[:user].present?
|
40
|
-
collection = collection.where(user: attributes[:user])
|
41
|
-
end
|
42
|
-
|
43
|
-
if attributes[:trashed_id] && attributes[:trashed_type]
|
44
|
-
collection = collection.where(trashed_id: attributes[:trashed_id], trashed_type: attributes[:trashed_type])
|
45
|
-
end
|
46
|
-
|
47
|
-
collection
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|