can_can_dry 0.3.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/can_can_dry_helper.rb +59 -0
- data/lib/can_can_dry.rb +4 -4
- data/lib/can_can_dry/ability_mapping.rb +50 -13
- data/lib/can_can_dry/ability_mapping/action_mapping_not_found.rb +3 -1
- data/lib/can_can_dry/ability_mapping/path_mapping_not_found.rb +5 -3
- data/lib/can_can_dry/ability_mapping_sets/active_scaffold.rb +5 -4
- data/lib/can_can_dry/ability_mapping_sets/devise.rb +6 -0
- data/lib/can_can_dry/ability_mapping_sets/devise_invitable.rb +3 -0
- data/lib/can_can_dry/controller_authorization.rb +8 -4
- data/lib/can_can_dry/engine.rb +5 -0
- data/lib/can_can_dry/no_controller_can_can_additions.rb +30 -0
- data/lib/can_can_dry/path_recognizer.rb +57 -32
- data/lib/can_can_dry/railtie.rb +2 -0
- data/lib/can_can_dry/version.rb +3 -1
- data/lib/tasks/can_can_dry.rake +1 -0
- data/spec/lib/can_can_dry/path_recognizer_spec.rb +17 -0
- data/spec/lib/rubocop_check_spec.rb +7 -0
- data/spec/spec_helper.rb +100 -0
- metadata +37 -23
- data/Rakefile +0 -17
- data/lib/can_can_dry/helpers/can_can_dry_helper.rb +0 -54
- data/test/can_can_dry_test.rb +0 -8
- data/test/lib/can_can_dry/path_recognizer_test.rb +0 -16
- data/test/test_helper.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4815527015549ba0d6cf2f3679ad8d44ac7753b9d34831d9ea7552b900d73fe
|
4
|
+
data.tar.gz: e5dff2e70c55ed2e5eb3240a305861142626795c823bd7088f310f583cf0d1df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ced8842ccc57776aa32462fc71096e22c0456313cb3d27bd115fb765859ea870ca1766af955bdf885c332928ee91945174da58e7fc261b1906291812114036aa
|
7
|
+
data.tar.gz: ab0814157bf16844ee3ad07a95f694a0e8eea7c15771194fd914b575cbecc9f8fd1442e15fac2614995f41f09c01237c2a0ca4bb1c29bd34c8d041145db05ea4
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CanCanDryHelper
|
4
|
+
def ability_mapping
|
5
|
+
@ability_mapping ||= ::AbilityMapping.new # rubocop:disable Rails/HelperInstanceVariable
|
6
|
+
end
|
7
|
+
|
8
|
+
def can_by_path?(path, method = :get)
|
9
|
+
can_by_can_args(ability_mapping.can_args_by_path(main_app.root_path, path, method))
|
10
|
+
end
|
11
|
+
|
12
|
+
def can_by_path_hash?(path_hash)
|
13
|
+
can_by_can_args(ability_mapping.can_args_by_path_hash(path_hash))
|
14
|
+
end
|
15
|
+
|
16
|
+
def link_or_text(name = nil, options = nil, html_options = nil)
|
17
|
+
link_or_default(name, name, options, html_options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def link_or_nil(name = nil, options = nil, html_options = nil)
|
21
|
+
link_or_default(name, nil, options, html_options)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def link_or_default(name, default, options, html_options)
|
27
|
+
if can_by_link_options?(options, html_options)
|
28
|
+
link_to(name, options, html_options)
|
29
|
+
else
|
30
|
+
default
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def can_by_link_options?(options, html_options)
|
35
|
+
can_by_path?(url_for(options), link_method(options, html_options))
|
36
|
+
end
|
37
|
+
|
38
|
+
def link_method(*hashs)
|
39
|
+
hashs.each do |h|
|
40
|
+
return h[:method] if h.is_a?(Hash) && h[:method]
|
41
|
+
end
|
42
|
+
:get
|
43
|
+
end
|
44
|
+
|
45
|
+
def can_by_can_args(can_args_args)
|
46
|
+
assert_can_method
|
47
|
+
can_args_args.each do |c|
|
48
|
+
next if c.empty?
|
49
|
+
return true if can?(*c)
|
50
|
+
end
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
def assert_can_method
|
55
|
+
return if respond_to?('can?')
|
56
|
+
|
57
|
+
singleton_class.include(::CanCanDry::NoControllerCanCanAdditions)
|
58
|
+
end
|
59
|
+
end
|
data/lib/can_can_dry.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/dependencies'
|
2
4
|
require 'cancancan'
|
3
5
|
|
@@ -10,9 +12,7 @@ module CanCanDry
|
|
10
12
|
require_dependency 'can_can_dry/ability_mapping'
|
11
13
|
require_dependency 'can_can_dry/ability_mapping/path_mapping_not_found'
|
12
14
|
require_dependency 'can_can_dry/ability_mapping/action_mapping_not_found'
|
13
|
-
require_dependency 'can_can_dry/
|
15
|
+
require_dependency 'can_can_dry/engine'
|
16
|
+
require_dependency 'can_can_dry/no_controller_can_can_additions'
|
14
17
|
require_dependency 'can_can_dry/path_recognizer'
|
15
|
-
|
16
|
-
require_dependency 'action_view'
|
17
|
-
ActionView::Base.send :include, CanCanDry::Helpers::CanCanDryHelper
|
18
18
|
end
|
@@ -1,11 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
1
5
|
module CanCanDry
|
2
6
|
module AbilityMapping
|
3
7
|
RESOURCES_ACTION_MAPPING = {
|
4
|
-
read: %w
|
5
|
-
create: %w
|
6
|
-
update: %w
|
7
|
-
destroy: %w
|
8
|
-
}
|
8
|
+
read: %w[index show],
|
9
|
+
create: %w[new create],
|
10
|
+
update: %w[update edit],
|
11
|
+
destroy: %w[destroy]
|
12
|
+
}.freeze
|
9
13
|
ALL_ACTION = 'ALL'
|
10
14
|
|
11
15
|
def mapping
|
@@ -38,6 +42,7 @@ module CanCanDry
|
|
38
42
|
if can_args.count == 1
|
39
43
|
raise "\"can_args\" deve ter 0 ou 2 ou mais elementos (can_args.count=#{can_args.count})"
|
40
44
|
end
|
45
|
+
|
41
46
|
mapping[controller] ||= {}
|
42
47
|
mapping[controller][action] ||= []
|
43
48
|
mapping[controller][action] << can_args
|
@@ -45,8 +50,8 @@ module CanCanDry
|
|
45
50
|
|
46
51
|
def can_args_by_path(root_path, path, method)
|
47
52
|
can_args_by_path_hash(recognize_path(root_path, path, method))
|
48
|
-
rescue ActionMappingNotFound =>
|
49
|
-
raise PathMappingNotFound.new(path, method,
|
53
|
+
rescue ActionMappingNotFound => e
|
54
|
+
raise PathMappingNotFound.new(path, method, e)
|
50
55
|
end
|
51
56
|
|
52
57
|
def can_args_by_path_hash(path_hash)
|
@@ -59,7 +64,7 @@ module CanCanDry
|
|
59
64
|
def replace_model_by_record(can_args_args, id)
|
60
65
|
can_args_args.map do |can_args|
|
61
66
|
ca = can_args.dup
|
62
|
-
ca[1] = ca[1].
|
67
|
+
ca[1] = ca[1].find_by(id: id) if id && ca[1].respond_to?(:find_by_id)
|
63
68
|
ca
|
64
69
|
end
|
65
70
|
end
|
@@ -70,15 +75,47 @@ module CanCanDry
|
|
70
75
|
end
|
71
76
|
|
72
77
|
def find_can_args_list(controller, action)
|
73
|
-
|
74
|
-
raise ActionMappingNotFound.new(controller, action) unless mapping[controller]
|
75
|
-
return mapping[controller][action] if mapping[controller][action]
|
76
|
-
return mapping[controller][ALL_ACTION] if mapping[controller][ALL_ACTION]
|
77
|
-
raise ActionMappingNotFound.new(controller, action)
|
78
|
+
FindCanArgsList.new(mapping, controller, action).find
|
78
79
|
end
|
79
80
|
|
80
81
|
def recognize_path(root_path, path, method)
|
81
82
|
::CanCanDry::PathRecognizer.recognize(root_path, path, method: method)
|
82
83
|
end
|
84
|
+
|
85
|
+
class FindCanArgsList
|
86
|
+
ALL_ACTION = ::CanCanDry::AbilityMapping::ALL_ACTION
|
87
|
+
common_constructor :mapping, :controller, :action
|
88
|
+
|
89
|
+
set_callback :initialize, :after do
|
90
|
+
@controller = ::ActiveSupport::Inflector.camelize(controller)
|
91
|
+
end
|
92
|
+
|
93
|
+
def find
|
94
|
+
validate
|
95
|
+
find_by_action || find_by_all_action || raise_mapping_not_found
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def find_by_action
|
101
|
+
return mapping[controller][action] if mapping[controller][action]
|
102
|
+
end
|
103
|
+
|
104
|
+
def find_by_all_action
|
105
|
+
return mapping[controller][ALL_ACTION] if mapping[controller][ALL_ACTION]
|
106
|
+
end
|
107
|
+
|
108
|
+
def mapping_has_controller?
|
109
|
+
mapping[controller]
|
110
|
+
end
|
111
|
+
|
112
|
+
def raise_mapping_not_found
|
113
|
+
raise(ActionMappingNotFound.new(controller, action))
|
114
|
+
end
|
115
|
+
|
116
|
+
def validate
|
117
|
+
raise ActionMappingNotFound.new(controller, action) unless mapping_has_controller?
|
118
|
+
end
|
119
|
+
end
|
83
120
|
end
|
84
121
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CanCanDry
|
2
4
|
module AbilityMapping
|
3
|
-
class ActionMappingNotFound <
|
5
|
+
class ActionMappingNotFound < RuntimeError
|
4
6
|
def initialize(controller, action)
|
5
7
|
super('Nenhum mapeamento de controle de acesso encontrado ' \
|
6
8
|
"para a action \"#{controller}##{action}\"")
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CanCanDry
|
2
4
|
module AbilityMapping
|
3
|
-
class PathMappingNotFound <
|
4
|
-
def initialize(path, method,
|
5
|
-
super("Falha ao tentar recuperar mapeamento \"#{path}\", método=#{method}: #{
|
5
|
+
class PathMappingNotFound < RuntimeError
|
6
|
+
def initialize(path, method, error)
|
7
|
+
super("Falha ao tentar recuperar mapeamento \"#{path}\", método=#{method}: #{error}")
|
6
8
|
end
|
7
9
|
end
|
8
10
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module CanCanDry
|
3
4
|
module AbilityMappingSets
|
4
5
|
module ActiveScaffold
|
5
6
|
ACTIVE_SCAFFOLD_MAPPING = {
|
6
|
-
read: [
|
7
|
-
create: [
|
8
|
-
update: [
|
9
|
-
destroy: [
|
7
|
+
read: %i[browse index mark render_field show show_search],
|
8
|
+
create: %i[create new],
|
9
|
+
update: %i[add_existing edit edit_associated new_existing update update_column],
|
10
|
+
destroy: %i[destroy destroy_existing]
|
10
11
|
}.freeze
|
11
12
|
|
12
13
|
def map_active_scaffold(controller, entity)
|
@@ -1,9 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CanCanDry
|
2
4
|
module AbilityMappingSets
|
3
5
|
module Devise
|
4
6
|
def map_devise
|
7
|
+
map_resources 'Devise::Confirmation'
|
8
|
+
map_resources 'Devise::OmniauthCallback'
|
9
|
+
map_resources 'Devise::Registration'
|
5
10
|
map_resources 'Devise::Session'
|
6
11
|
map_resources 'Devise::Password'
|
12
|
+
map_resources 'Devise::Unlock'
|
7
13
|
end
|
8
14
|
end
|
9
15
|
end
|
@@ -1,18 +1,22 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module CanCanDry
|
4
4
|
module ControllerAuthorization
|
5
|
-
|
5
|
+
extend ::ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
include ::CanCanDryHelper
|
9
|
+
end
|
6
10
|
|
7
11
|
def authorize_by_ability_mapping
|
8
|
-
|
12
|
+
raise CanCan::AccessDenied, "Falhou ao tentar acessar #{path_hash}" unless
|
9
13
|
can_by_path_hash?(path_hash)
|
10
14
|
end
|
11
15
|
|
12
16
|
private
|
13
17
|
|
14
18
|
def path_hash
|
15
|
-
params.select { |k, _v| %w
|
19
|
+
params.select { |k, _v| %w[controller action id].include?(k) }
|
16
20
|
end
|
17
21
|
|
18
22
|
def ability_mapping
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CanCanDry
|
4
|
+
# A substitute for CanCan::ControllerAdditions when no controller is present.
|
5
|
+
module NoControllerCanCanAdditions
|
6
|
+
extend ::ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
include ::CanCan::ControllerAdditions
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_reader :current_user
|
14
|
+
|
15
|
+
def with_current_user(user)
|
16
|
+
old_user = @current_user
|
17
|
+
begin
|
18
|
+
@current_user = user
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
@current_user = old_user
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def current_user
|
27
|
+
::CanCanDry::NoControllerCanCanAdditions.current_user
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,51 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
1
5
|
module CanCanDry
|
2
6
|
# Copiado de https://github.com/appirits/awesome_admin_layout
|
3
7
|
# /lib/awesome_admin_layout/recognize_path.rb
|
4
|
-
|
8
|
+
class PathRecognizer
|
5
9
|
class << self
|
6
10
|
def recognize(root_path, path, options = {})
|
7
|
-
|
8
|
-
return Rails.application.routes.recognize_path(path, options)
|
9
|
-
rescue ActionController::RoutingError
|
10
|
-
Rails::Engine.subclasses.each do |engine|
|
11
|
-
recognized_path = engine_recognize(engine, path, options)
|
12
|
-
return recognized_path if recognized_path
|
13
|
-
end
|
14
|
-
raise "Path not recognized: \"#{path}\" (Options: #{options})"
|
11
|
+
new(root_path, path, options).recognize_or_raise
|
15
12
|
end
|
16
13
|
|
17
|
-
private
|
18
|
-
|
19
14
|
def remove_root_path(root_path, path)
|
20
15
|
path = path.gsub(/\A#{Regexp.quote(root_path)}/, '')
|
21
16
|
path.gsub(%r{\A/*}, '/')
|
22
17
|
end
|
18
|
+
end
|
19
|
+
|
20
|
+
common_constructor :root_path, :path, :options do
|
21
|
+
self.path = self.class.remove_root_path(root_path, path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def recognize_or_raise
|
25
|
+
recognize || raise("Path not recognized: \"#{path}\" (Options: #{options})")
|
26
|
+
end
|
27
|
+
|
28
|
+
def recognize
|
29
|
+
core_recognize || engines_recognize
|
30
|
+
end
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
private
|
33
|
+
|
34
|
+
def core_recognize
|
35
|
+
Rails.application.routes.recognize_path(path, options)
|
36
|
+
rescue ActionController::RoutingError
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def engines_recognize
|
41
|
+
Rails::Engine.subclasses.each do |engine|
|
42
|
+
recognized_path = engine_recognize(engine)
|
43
|
+
return recognized_path if recognized_path
|
33
44
|
end
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def engine_recognize(engine)
|
49
|
+
engine_path = path_for_engine(engine.instance.class)
|
50
|
+
return unless engine_path
|
34
51
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
52
|
+
begin
|
53
|
+
return engine.instance.routes.recognize_path(engine_path, options)
|
54
|
+
rescue ActionController::RoutingError => e
|
55
|
+
Rails.logger.debug "[#{engine}] ActionController::RoutingError: #{e.message}"
|
39
56
|
end
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def path_for_engine(engine_class)
|
61
|
+
engine_route = Rails.application.routes.routes.find { |r| app_class_for(r) == engine_class }
|
62
|
+
return unless engine_route
|
63
|
+
|
64
|
+
path.gsub(/^#{engine_route.path.spec}/, '')
|
65
|
+
end
|
40
66
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
67
|
+
def app_class_for(route)
|
68
|
+
if Rails.version >= '4.2'
|
69
|
+
# for Rails 4.2
|
70
|
+
route.app.app
|
71
|
+
else
|
72
|
+
# for Rails 4.1, 4.0, 3.2
|
73
|
+
route.app
|
49
74
|
end
|
50
75
|
end
|
51
76
|
end
|
data/lib/can_can_dry/railtie.rb
CHANGED
data/lib/can_can_dry/version.rb
CHANGED
data/lib/tasks/can_can_dry.rake
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'can_can_dry/path_recognizer'
|
4
|
+
|
5
|
+
RSpec.describe ::CanCanDry::PathRecognizer do
|
6
|
+
describe '#remove_root_path' do
|
7
|
+
[%w[/path/to/action /prefix/ /prefix/path/to/action],
|
8
|
+
%w[/path/to/action /prefix /prefix/path/to/action],
|
9
|
+
%w[/path / /path],
|
10
|
+
['/path', '', '/path'],
|
11
|
+
%w[/unknown/path /abc /unknown/path]].each do |s|
|
12
|
+
it do
|
13
|
+
expect(described_class.send(:remove_root_path, s[1], s[2])).to eq(s[0])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
6
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
7
|
+
# files.
|
8
|
+
#
|
9
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
10
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
11
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
12
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
13
|
+
# a separate helper file that requires the additional dependencies and performs
|
14
|
+
# the additional setup, and require it from the spec files that actually need
|
15
|
+
# it.
|
16
|
+
#
|
17
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
18
|
+
RSpec.configure do |config|
|
19
|
+
# rspec-expectations config goes here. You can use an alternate
|
20
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
21
|
+
# assertions if you prefer.
|
22
|
+
config.expect_with :rspec do |expectations|
|
23
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
24
|
+
# and `failure_message` of custom matchers include text for helper methods
|
25
|
+
# defined using `chain`, e.g.:
|
26
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
27
|
+
# # => "be bigger than 2 and smaller than 4"
|
28
|
+
# ...rather than:
|
29
|
+
# # => "be bigger than 2"
|
30
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
31
|
+
end
|
32
|
+
|
33
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
34
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
35
|
+
config.mock_with :rspec do |mocks|
|
36
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
37
|
+
# a real object. This is generally recommended, and will default to
|
38
|
+
# `true` in RSpec 4.
|
39
|
+
mocks.verify_partial_doubles = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
43
|
+
# have no way to turn it off -- the option exists only for backwards
|
44
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
45
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
46
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
47
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
48
|
+
|
49
|
+
# The settings below are suggested to provide a good initial experience
|
50
|
+
# with RSpec, but feel free to customize to your heart's content.
|
51
|
+
# # This allows you to limit a spec run to individual examples or groups
|
52
|
+
# # you care about by tagging them with `:focus` metadata. When nothing
|
53
|
+
# # is tagged with `:focus`, all examples get run. RSpec also provides
|
54
|
+
# # aliases for `it`, `describe`, and `context` that include `:focus`
|
55
|
+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
56
|
+
# config.filter_run_when_matching :focus
|
57
|
+
#
|
58
|
+
# # Allows RSpec to persist some state between runs in order to support
|
59
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
60
|
+
# # you configure your source control system to ignore this file.
|
61
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
62
|
+
#
|
63
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
64
|
+
# # recommended. For more details, see:
|
65
|
+
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
66
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
67
|
+
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
68
|
+
# config.disable_monkey_patching!
|
69
|
+
#
|
70
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
71
|
+
# # be too noisy due to issues in dependencies.
|
72
|
+
# config.warnings = true
|
73
|
+
#
|
74
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
75
|
+
# # file, and it's useful to allow more verbose output when running an
|
76
|
+
# # individual spec file.
|
77
|
+
# if config.files_to_run.one?
|
78
|
+
# # Use the documentation formatter for detailed output,
|
79
|
+
# # unless a formatter has already been configured
|
80
|
+
# # (e.g. via a command-line flag).
|
81
|
+
# config.default_formatter = "doc"
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# # Print the 10 slowest examples and example groups at the
|
85
|
+
# # end of the spec run, to help surface which specs are running
|
86
|
+
# # particularly slow.
|
87
|
+
# config.profile_examples = 10
|
88
|
+
#
|
89
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
90
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
91
|
+
# # the seed, which is printed after each run.
|
92
|
+
# # --seed 1234
|
93
|
+
# config.order = :random
|
94
|
+
#
|
95
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
96
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
97
|
+
# # test failures related to randomization by passing the same `--seed` value
|
98
|
+
# # as the one that triggered the failure.
|
99
|
+
# Kernel.srand config.seed
|
100
|
+
end
|
metadata
CHANGED
@@ -1,64 +1,78 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: can_can_dry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: cancancan
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.13.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: 1.13.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: eac_ruby_utils
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.46'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.46'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 4.2.1
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 4.2.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: eac_ruby_gem_support
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: '0.1'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: '0.1'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
executables: []
|
58
72
|
extensions: []
|
59
73
|
extra_rdoc_files: []
|
60
74
|
files:
|
61
|
-
-
|
75
|
+
- app/helpers/can_can_dry_helper.rb
|
62
76
|
- lib/can_can_dry.rb
|
63
77
|
- lib/can_can_dry/ability_mapping.rb
|
64
78
|
- lib/can_can_dry/ability_mapping/action_mapping_not_found.rb
|
@@ -67,14 +81,15 @@ files:
|
|
67
81
|
- lib/can_can_dry/ability_mapping_sets/devise.rb
|
68
82
|
- lib/can_can_dry/ability_mapping_sets/devise_invitable.rb
|
69
83
|
- lib/can_can_dry/controller_authorization.rb
|
70
|
-
- lib/can_can_dry/
|
84
|
+
- lib/can_can_dry/engine.rb
|
85
|
+
- lib/can_can_dry/no_controller_can_can_additions.rb
|
71
86
|
- lib/can_can_dry/path_recognizer.rb
|
72
87
|
- lib/can_can_dry/railtie.rb
|
73
88
|
- lib/can_can_dry/version.rb
|
74
89
|
- lib/tasks/can_can_dry.rake
|
75
|
-
-
|
76
|
-
-
|
77
|
-
-
|
90
|
+
- spec/lib/can_can_dry/path_recognizer_spec.rb
|
91
|
+
- spec/lib/rubocop_check_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
78
93
|
homepage: https://github.com/esquilo-azul/can_can_dry
|
79
94
|
licenses: []
|
80
95
|
metadata:
|
@@ -94,12 +109,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
109
|
- !ruby/object:Gem::Version
|
95
110
|
version: '0'
|
96
111
|
requirements: []
|
97
|
-
|
98
|
-
rubygems_version: 2.7.7
|
112
|
+
rubygems_version: 3.0.8
|
99
113
|
signing_key:
|
100
114
|
specification_version: 4
|
101
115
|
summary: DRY authorization with CanCanCan.
|
102
116
|
test_files:
|
103
|
-
-
|
104
|
-
-
|
105
|
-
-
|
117
|
+
- spec/lib/can_can_dry/path_recognizer_spec.rb
|
118
|
+
- spec/lib/rubocop_check_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
data/Rakefile
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'bundler/setup'
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
6
|
-
|
7
|
-
Bundler::GemHelper.install_tasks
|
8
|
-
require 'rake/testtask'
|
9
|
-
|
10
|
-
Rake::TestTask.new(:test) do |t|
|
11
|
-
t.libs << 'lib'
|
12
|
-
t.libs << 'test'
|
13
|
-
t.pattern = 'test/**/*_test.rb'
|
14
|
-
t.verbose = false
|
15
|
-
end
|
16
|
-
|
17
|
-
task default: :test
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module CanCanDry
|
2
|
-
module Helpers
|
3
|
-
module CanCanDryHelper
|
4
|
-
def ability_mapping
|
5
|
-
@ability_mapping ||= ::AbilityMapping.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def can_by_path?(path, method = :get)
|
9
|
-
can_by_can_args(ability_mapping.can_args_by_path(main_app.root_path, path, method))
|
10
|
-
end
|
11
|
-
|
12
|
-
def can_by_path_hash?(path_hash)
|
13
|
-
can_by_can_args(ability_mapping.can_args_by_path_hash(path_hash))
|
14
|
-
end
|
15
|
-
|
16
|
-
def link_or_text(name = nil, options = nil, html_options = nil)
|
17
|
-
link_or_default(name, name, options, html_options)
|
18
|
-
end
|
19
|
-
|
20
|
-
def link_or_nil(name = nil, options = nil, html_options = nil)
|
21
|
-
link_or_default(name, nil, options, html_options)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def link_or_default(name, default, options, html_options)
|
27
|
-
if can_by_link_options?(options, html_options)
|
28
|
-
link_to(name, options, html_options)
|
29
|
-
else
|
30
|
-
default
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def can_by_link_options?(options, html_options)
|
35
|
-
can_by_path?(url_for(options), link_method(options, html_options))
|
36
|
-
end
|
37
|
-
|
38
|
-
def link_method(*hashs)
|
39
|
-
hashs.each do |h|
|
40
|
-
return h[:method] if h.is_a?(Hash) && h[:method]
|
41
|
-
end
|
42
|
-
:get
|
43
|
-
end
|
44
|
-
|
45
|
-
def can_by_can_args(can_args_args)
|
46
|
-
can_args_args.each do |c|
|
47
|
-
next if c.empty?
|
48
|
-
return true if can?(*c)
|
49
|
-
end
|
50
|
-
false
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/test/can_can_dry_test.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
module CanCanDry
|
5
|
-
class PathRecognizerTest < ActiveSupport::TestCase
|
6
|
-
test 'remove_root_path' do
|
7
|
-
[%w(/path/to/action /prefix/ /prefix/path/to/action),
|
8
|
-
%w(/path/to/action /prefix /prefix/path/to/action),
|
9
|
-
%w(/path / /path),
|
10
|
-
['/path', '', '/path'],
|
11
|
-
%w(/unknown/path /abc /unknown/path)].each do |s|
|
12
|
-
assert_equal s[0], ::CanCanDry::PathRecognizer.send(:remove_root_path, s[1], s[2]), s
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/test/test_helper.rb
DELETED