rabarber 1.4.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rabarber
4
- module Missing
5
- class Base
6
- attr_reader :controller
7
-
8
- def initialize(controller = nil)
9
- @controller = controller
10
- end
11
-
12
- def handle
13
- check_controller_rules
14
- check_action_rules
15
-
16
- return if missing_list.empty?
17
-
18
- missing_list.each do |item|
19
- context = item.action ? { controller: item.controller, action: item.action } : { controller: item.controller }
20
- Rabarber::Configuration.instance.public_send(configuration_name).call(item.missing, context)
21
- end
22
- end
23
-
24
- private
25
-
26
- def check_controller_rules
27
- raise NotImplementedError
28
- end
29
-
30
- def check_action_rules
31
- raise NotImplementedError
32
- end
33
-
34
- def configuration_name
35
- raise NotImplementedError
36
- end
37
-
38
- def missing_list
39
- @missing_list ||= []
40
- end
41
-
42
- def controller_rules
43
- if controller
44
- Rabarber::Core::Permissions.controller_rules.slice(controller)
45
- else
46
- Rabarber::Core::Permissions.controller_rules
47
- end
48
- end
49
-
50
- def action_rules
51
- if controller
52
- Rabarber::Core::Permissions.action_rules.slice(controller)
53
- else
54
- Rabarber::Core::Permissions.action_rules
55
- end
56
- end
57
- end
58
-
59
- Item = Struct.new(:missing, :controller, :action)
60
- end
61
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rabarber
4
- module Missing
5
- class Roles < Rabarber::Missing::Base
6
- private
7
-
8
- def check_controller_rules
9
- controller_rules.each do |controller, controller_rule|
10
- missing_roles = controller_rule.roles - all_roles
11
- missing_list << Rabarber::Missing::Item.new(missing_roles, controller, nil) unless missing_roles.empty?
12
- end
13
- end
14
-
15
- def check_action_rules
16
- action_rules.each do |controller, controller_action_rules|
17
- controller_action_rules.each do |action_rule|
18
- missing_roles = action_rule.roles - all_roles
19
- missing_list << Rabarber::Missing::Item.new(missing_roles, controller, action_rule.action) if missing_roles.any?
20
- end
21
- end
22
- end
23
-
24
- def configuration_name
25
- :when_roles_missing
26
- end
27
-
28
- def all_roles
29
- @all_roles ||= Rabarber::Cache.fetch(
30
- Rabarber::Cache::ALL_ROLES_KEY, expires_in: 1.day, race_condition_ttl: 10.seconds
31
- ) { Rabarber::Role.names }
32
- end
33
- end
34
- end
35
- end