Class: Authz::ControllerAction

Inherits:
Authz.selfself::ApplicationRecord
  • Object
show all
Defined in:
app/models/authz/controller_action.rb

Overview

Represents a single reachable controller action from the host application’s router, including all library internal routes.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.engine_reachable_controller_actionsHash

Returns reachable controller actions declared in the Engine’s router.

Returns:

  • (Hash)

    reachable controller actions declared in the Engine’s router



42
43
44
# File 'app/models/authz/controller_action.rb', line 42

def self.engine_reachable_controller_actions
  extract_reachable_controller_actions(Authz::Engine)
end

.main_app_reachable_controller_actionsHash

Returns reachable controller actions declared in the host app’s router.

Returns:

  • (Hash)

    reachable controller actions declared in the host app’s router



37
38
39
# File 'app/models/authz/controller_action.rb', line 37

def self.main_app_reachable_controller_actions
  extract_reachable_controller_actions(Rails.application)
end

.pendingArray<Hash<controller_name, action_name>>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns controller actions reachable from the router but not present in the database.

Returns:

  • (Array<Hash<controller_name, action_name>>)

    controller actions reachable from the router but not present in the database

See Also:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/authz/controller_action.rb', line 64

def self.pending
  # TODO: Refactor and test
  ca_pairs = []
  reachable_controller_actions.each do | c_name, action_arr |
    action_arr.each do |a_name|
      ca_pairs << { controller: c_name, action: a_name }
    end
  end

  pending = []
  ca_pairs.each do |route|
    ca = find_by(controller: route[:controller], action: route[:action])
    pending << route unless ca
  end

  pending
end

.reachable_controller_actionsHash

Combines the reachable controller actions from the engine and the main app giving precedence to the main app in case of overwrite

Returns:

  • (Hash)

    reachable controller actions

See Also:



51
52
53
54
55
56
57
58
# File 'app/models/authz/controller_action.rb', line 51

def self.reachable_controller_actions
  app_cas = main_app_reachable_controller_actions
  engine_cas =  engine_reachable_controller_actions
  repeated_keys = app_cas.keys & engine_cas.keys
  res = engine_cas.merge(app_cas)
  repeated_keys.each { |rk| res[rk] = app_cas[rk] | engine_cas[rk] }
  res
end

.staleArray<Authz::ControllerAction>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns controller actions that are created in the database that are no longer reachable from the router.

Returns:

  • (Array<Authz::ControllerAction>)

    controller actions that are created in the database that are no longer reachable from the router

See Also:



86
87
88
89
90
91
92
93
94
# File 'app/models/authz/controller_action.rb', line 86

def self.stale
  # TODO: Refactor and test
  stale = []
  find_each do |ca|
    is_included = reachable_controller_actions[ca.controller].try(:include?, ca.action)
    stale << ca unless is_included
  end
  stale
end

Instance Method Details

#to_sString

Returns concatenation of controller#action-id.

Returns:

  • (String)

    concatenation of controller#action-id



100
101
102
# File 'app/models/authz/controller_action.rb', line 100

def to_s
  "#{controller}##{action}-#{id}"
end