verbose_cancancan 0.0.3 → 0.0.5
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/lib/verbose_cancancan/ability.rb +18 -15
- data/lib/verbose_cancancan/controller_resource.rb +17 -9
- data/lib/verbose_cancancan/railtie.rb +6 -5
- data/lib/verbose_cancancan/rule.rb +9 -5
- data/lib/verbose_cancancan.rb +9 -15
- metadata +38 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a27a597ae004b18049c897a0cc3d9f15cd3904cda76b8ab9b46c453bd0e72c32
|
4
|
+
data.tar.gz: 16705a72c86087a22ec04e6a7d62ab1c7fb6e4e590b81ecb10a2f93e28ffa33e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f11a9e2e8c94b67ab2613c06a21bc933ebf75bc2e4ee55b83d9a4a49a0005b5c485d69d79c56bb2ec7ad7124876db566b8282baff414a4b4ca6a1f851b4bf03f
|
7
|
+
data.tar.gz: '08db0bc76b33bd8d0657ea415ab8dbcbd5891116b3a4ec2eb389b5daee483ec5a6509b1f379e1ebd7725e32d96433765664efd9cedbe3fe94ff168b5144a60de'
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module VerboseCancancan
|
2
|
+
module Ability
|
2
3
|
|
4
|
+
extend ActiveSupport::Concern
|
3
5
|
|
4
|
-
|
6
|
+
prepended do
|
7
|
+
delegate :colourize, :logger, to: VerboseCancancan, prefix: :verb
|
8
|
+
end
|
5
9
|
|
6
10
|
def can?(action, subject, attribute = nil, *extra_args)
|
7
11
|
match = extract_subjects(subject).lazy.map do |a_subject|
|
@@ -15,17 +19,16 @@ module VerboseCancancan
|
|
15
19
|
match ? match.base_behavior : false
|
16
20
|
end
|
17
21
|
|
18
|
-
# Only logged the rule if authorize! or load_and_authorize! is called, to avoid cluttering the terminal
|
22
|
+
# Only logged the rule if authorize! or load_and_authorize! is called, to avoid cluttering the terminal due to can? checks.
|
19
23
|
def log_rule? = caller.find { |path| path.include?('authorize!') }
|
20
24
|
|
21
|
-
|
22
25
|
def log_rule(matched_rule, action, subject)
|
23
26
|
subject = pretty_subject(subject)
|
24
27
|
|
25
28
|
if matched_rule
|
26
|
-
|
29
|
+
verb_logger.info matched_rule_info(matched_rule, subject, action)
|
27
30
|
else
|
28
|
-
|
31
|
+
verb_logger.info no_rule_matched(subject, action)
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -33,32 +36,32 @@ module VerboseCancancan
|
|
33
36
|
auth_status = rule.base_behavior ? auth_success : auth_failed
|
34
37
|
rule_type = rule.base_behavior ? 'Can' : 'Cannot'
|
35
38
|
|
36
|
-
"#{auth_status} #{rule_type}
|
39
|
+
"#{auth_status} Rule of #{rule_type} type applied for #{verb_colourize(subject, :magenta)} (Action: #{verb_colourize(action, :green)})\n ↳ #{rule.path}"
|
37
40
|
end
|
38
41
|
|
39
42
|
def no_rule_matched(subject, action)
|
40
|
-
"#{auth_failed} No matching rule for #{
|
43
|
+
"#{auth_failed} No matching rule for #{verb_colourize(subject, :magenta)} (Action: #{verb_colourize(action, :green)})"
|
41
44
|
end
|
42
45
|
|
43
46
|
def pretty_subject(subject)
|
44
47
|
if subject.is_a?(ActiveRecord::Base)
|
48
|
+
# In case of member actions subject is `ActiveRecord::Base`
|
49
|
+
|
45
50
|
"#{subject.class.name} (ID: #{subject.id})"
|
46
51
|
else
|
52
|
+
# In case of Collection actions subject can be
|
53
|
+
# 1. Hash if resources are being loaded through parent. => { parent_resource => resource_class }
|
54
|
+
# 2. ActiveRecord::Model if if resources are not loaded through parent.
|
55
|
+
|
47
56
|
orignal_subject = subject.is_a?(Hash) ? subject.values.first : subject
|
48
57
|
|
49
58
|
orignal_subject.respond_to?(:name) ? orignal_subject.name : orignal_subject
|
50
59
|
end
|
51
60
|
end
|
52
61
|
|
53
|
-
def auth_failed
|
54
|
-
colourize('[❌ AUTHORIZATION FAILED]', :red)
|
55
|
-
end
|
56
|
-
|
57
|
-
def auth_success
|
58
|
-
colourize('[✅ AUTHORIZATION SUCCESS]', :green)
|
59
|
-
end
|
62
|
+
def auth_failed = verb_colourize('[❌ AUTHORIZATION FAILED]', :red)
|
60
63
|
|
61
|
-
def
|
64
|
+
def auth_success = verb_colourize('[✅ AUTHORIZATION SUCCESS]', :green)
|
62
65
|
|
63
66
|
end
|
64
67
|
end
|
@@ -1,15 +1,23 @@
|
|
1
1
|
module VerboseCancancan
|
2
2
|
module ControllerResource
|
3
3
|
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
prepended do
|
7
|
+
delegate :cleaner_backtrace, :logger, :colourize, to: VerboseCancancan, prefix: :verb
|
8
|
+
end
|
9
|
+
|
4
10
|
def add_before_action(controller_class, method, *args)
|
5
11
|
options = args.extract_options!
|
6
12
|
resource_name = args.first
|
7
13
|
before_action_method = before_callback_name(options)
|
8
|
-
bk_trace =
|
14
|
+
bk_trace = verb_cleaner_backtrace(caller).first
|
9
15
|
|
10
16
|
controller_class.send(before_action_method, options.slice(:only, :except, :if, :unless)) do |controller|
|
11
17
|
|
12
|
-
|
18
|
+
controller.class
|
19
|
+
.cancan_resource_class
|
20
|
+
.log_hook_added(method, controller_class, resource_name, bk_trace)
|
13
21
|
|
14
22
|
|
15
23
|
controller.class.cancan_resource_class
|
@@ -17,15 +25,15 @@ module VerboseCancancan
|
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
20
|
-
def
|
21
|
-
|
22
|
-
end
|
28
|
+
def log_hook_added(method, controller_class, resource_name, bk_trace)
|
29
|
+
return if method.to_s.exclude? 'authorize_resource'
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
log_msg = [verb_colourize('[⏳ CanCan Hook Added]', :orange), "(#{method})"]
|
32
|
+
log_msg << "for #{resource_name}" if resource_name
|
33
|
+
log_msg += ["on #{controller_class}", "\n ↳ #{bk_trace}"]
|
27
34
|
|
28
|
-
|
35
|
+
verb_logger.info log_msg.join(' ')
|
36
|
+
end
|
29
37
|
|
30
38
|
end
|
31
39
|
end
|
@@ -1,15 +1,16 @@
|
|
1
|
+
require 'verbose_cancancan/ability'
|
2
|
+
require 'verbose_cancancan/rule'
|
3
|
+
require 'verbose_cancancan/controller_resource'
|
4
|
+
|
1
5
|
module VerboseCancancan
|
2
6
|
class Railtie < Rails::Railtie
|
3
|
-
initializer "my_gem.configure_rails_initialization" do
|
4
|
-
# some initialization behavior
|
5
|
-
puts "\n\n\nhola\n\n\n"
|
6
7
|
|
8
|
+
initializer 'verbose_cancancan.patch_cancancan' do
|
7
9
|
CanCan::Rule.prepend(Rule)
|
8
10
|
CanCan::Ability.prepend(Ability)
|
9
11
|
|
10
12
|
CanCan::ControllerResource.singleton_class.prepend(VerboseCancancan::ControllerResource)
|
11
|
-
|
12
|
-
|
13
13
|
end
|
14
|
+
|
14
15
|
end
|
15
16
|
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
module VerboseCancancan
|
2
|
-
|
3
2
|
module Rule
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
prepended do
|
6
|
+
attr_reader :path
|
7
|
+
|
8
|
+
delegate :cleaner_backtrace, to: VerboseCancancan, prefix: :verb
|
9
|
+
end
|
10
|
+
|
4
11
|
def initialize(...)
|
5
|
-
@path =
|
12
|
+
@path = verb_cleaner_backtrace(caller).first
|
6
13
|
super
|
7
14
|
end
|
8
|
-
|
9
|
-
def path = @path
|
10
15
|
end
|
11
|
-
|
12
16
|
end
|
data/lib/verbose_cancancan.rb
CHANGED
@@ -1,19 +1,10 @@
|
|
1
|
-
require 'verbose_cancancan/ability'
|
2
|
-
require 'verbose_cancancan/rule'
|
3
|
-
require 'verbose_cancancan/controller_resource'
|
4
1
|
require 'verbose_cancancan/railtie'
|
5
2
|
|
6
3
|
module VerboseCancancan
|
7
4
|
|
8
5
|
class << self
|
9
6
|
|
10
|
-
def logger
|
11
|
-
logger = Logger.new(STDOUT)
|
12
|
-
|
13
|
-
logger.formatter = proc { |_, _, _, msg| "#{msg}\n\n" }
|
14
|
-
|
15
|
-
logger
|
16
|
-
end
|
7
|
+
def logger = Rails.logger
|
17
8
|
|
18
9
|
def cleaner_backtrace(locations)
|
19
10
|
bk_trace = ActiveSupport::BacktraceCleaner.new
|
@@ -23,13 +14,16 @@ module VerboseCancancan
|
|
23
14
|
bk_trace.clean(locations)
|
24
15
|
end
|
25
16
|
|
17
|
+
# TODO: Refactor Coloring approch.
|
26
18
|
def colourize(msg, color)
|
27
19
|
colors = {
|
28
|
-
clear:
|
29
|
-
red:
|
30
|
-
green:
|
31
|
-
|
32
|
-
|
20
|
+
clear: "\e[0m",
|
21
|
+
red: "\e[1;31m",
|
22
|
+
green: "\e[1;92m",
|
23
|
+
magenta: "\e[1;95m",
|
24
|
+
yellow: "\e[1;93m",
|
25
|
+
orange: "\e[1;38;5;214m",
|
26
|
+
cyan: "\e[1;96m"
|
33
27
|
}
|
34
28
|
|
35
29
|
"#{colors[color]}#{msg}#{colors[:clear]}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verbose_cancancan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zain Iftikhar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cancancan
|
@@ -24,8 +24,37 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
|
28
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6.0'
|
55
|
+
description: 'This CanCanCan extension displays the location where selected rule for
|
56
|
+
authorization was defined and also prints the locations where load_and_authorize_resource
|
57
|
+
and authorize! hooks are defined.
|
29
58
|
|
30
59
|
'
|
31
60
|
email:
|
@@ -39,10 +68,13 @@ files:
|
|
39
68
|
- lib/verbose_cancancan/controller_resource.rb
|
40
69
|
- lib/verbose_cancancan/railtie.rb
|
41
70
|
- lib/verbose_cancancan/rule.rb
|
42
|
-
homepage:
|
71
|
+
homepage:
|
43
72
|
licenses:
|
44
73
|
- MIT
|
45
|
-
metadata:
|
74
|
+
metadata:
|
75
|
+
bug_tracker_uri: https://github.com/ZainIftikhar7vals/verbose_cancancan/issues
|
76
|
+
documentation_uri: https://github.com/ZainIftikhar7vals/verbose_cancancan
|
77
|
+
homepage_uri: https://github.com/ZainIftikhar7vals/verbose_cancancan
|
46
78
|
post_install_message: Thanks for installing!
|
47
79
|
rdoc_options: []
|
48
80
|
require_paths:
|