rabarber 4.1.4 → 5.1.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.
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../logger"
4
-
5
- module Rabarber
6
- module Audit
7
- module Events
8
- class Base
9
- attr_reader :roleable, :specifics
10
-
11
- def self.trigger(roleable, specifics)
12
- new(roleable, specifics).send(:log)
13
- end
14
-
15
- private
16
-
17
- def initialize(roleable, specifics)
18
- @roleable = roleable
19
- @specifics = specifics
20
- end
21
-
22
- def log
23
- Rabarber::Audit::Logger.log(log_level, message)
24
- end
25
-
26
- def log_level
27
- raise NotImplementedError
28
- end
29
-
30
- def message
31
- raise NotImplementedError
32
- end
33
-
34
- def identity
35
- roleable.log_identity
36
- end
37
-
38
- def human_context
39
- case context
40
- in { context_type: nil, context_id: nil } then "Global"
41
- in { context_type:, context_id: nil } then context_type
42
- in { context_type:, context_id: } then "#{context_type}##{context_id}"
43
- else raise Rabarber::Error, "Unexpected context: #{context.inspect}"
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rabarber
4
- module Audit
5
- module Events
6
- class RolesAssigned < Base
7
- private
8
-
9
- def log_level
10
- :info
11
- end
12
-
13
- def message
14
- "[Role Assignment] #{identity} | context: #{human_context} | assigned: #{roles_to_assign} | current: #{current_roles}"
15
- end
16
-
17
- def context
18
- specifics.fetch(:context)
19
- end
20
-
21
- def roles_to_assign
22
- specifics.fetch(:roles_to_assign)
23
- end
24
-
25
- def current_roles
26
- specifics.fetch(:current_roles)
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rabarber
4
- module Audit
5
- module Events
6
- class RolesRevoked < Base
7
- private
8
-
9
- def log_level
10
- :info
11
- end
12
-
13
- def message
14
- "[Role Revocation] #{identity} | context: #{human_context} | revoked: #{roles_to_revoke} | current: #{current_roles}"
15
- end
16
-
17
- def context
18
- specifics.fetch(:context)
19
- end
20
-
21
- def roles_to_revoke
22
- specifics.fetch(:roles_to_revoke)
23
- end
24
-
25
- def current_roles
26
- specifics.fetch(:current_roles)
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rabarber
4
- module Audit
5
- module Events
6
- class UnauthorizedAttempt < Base
7
- private
8
-
9
- def log_level
10
- :warn
11
- end
12
-
13
- def message
14
- "[Unauthorized Attempt] #{identity} | request: #{request_method} #{path}"
15
- end
16
-
17
- def path
18
- specifics.fetch(:path)
19
- end
20
-
21
- def request_method
22
- specifics.fetch(:request_method)
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "singleton"
4
-
5
- module Rabarber
6
- module Audit
7
- class Logger
8
- include Singleton
9
-
10
- attr_reader :logger
11
-
12
- def initialize
13
- @logger = ::Logger.new(Rails.root.join("log/rabarber_audit.log"))
14
- end
15
-
16
- def self.log(log_level, message)
17
- return unless Rabarber::Configuration.instance.audit_trail_enabled
18
-
19
- instance.logger.public_send(log_level, message)
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rabarber
4
- module Core
5
- class NullRoleable
6
- def roles(context:) # rubocop:disable Lint/UnusedMethodArgument
7
- []
8
- end
9
-
10
- def all_roles
11
- {}
12
- end
13
-
14
- def has_role?(*role_names, context: nil) # rubocop:disable Lint/UnusedMethodArgument
15
- false
16
- end
17
-
18
- def log_identity
19
- "Unauthenticated #{Rabarber::HasRoles.roleable_class.model_name.human.downcase}"
20
- end
21
- end
22
- end
23
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rabarber
4
- module Core
5
- class PermissionsIntegrityChecker
6
- attr_reader :controller
7
-
8
- def initialize(controller = nil)
9
- @controller = controller
10
- end
11
-
12
- def run!
13
- return if missing_list.empty?
14
-
15
- raise(
16
- Rabarber::Error,
17
- "Following actions were passed to 'grant_access' method but are not defined in the controller:\n#{missing_list.to_yaml}"
18
- )
19
- end
20
-
21
- private
22
-
23
- def missing_list
24
- @missing_list ||= action_rules.each_with_object([]) do |(controller, hash), arr|
25
- missing_actions = hash.keys - controller.action_methods.map(&:to_sym)
26
- arr << { controller => missing_actions } if missing_actions.any?
27
- end
28
- end
29
-
30
- def action_rules
31
- rules = Rabarber::Core::Permissions.action_rules
32
- controller ? rules.slice(controller) : rules
33
- end
34
- end
35
- end
36
- end