Class: HrLite::ApprovalStep
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- HrLite::ApprovalStep
- Defined in:
- app/models/hr_lite/approval_step.rb
Overview
One rung. The approver is named by RULE, not by person, so a flow survives somebody leaving the company — the rule is resolved against the subject at the moment the request is raised.
Constant Summary collapse
- RULES =
%w[manager manager_of_manager permission user].freeze
Instance Method Summary collapse
-
#approvers_for(subject) ⇒ Object
Everybody who must (or may) decide this rung for
subject. - #label ⇒ Object
Instance Method Details
#approvers_for(subject) ⇒ Object
Everybody who must (or may) decide this rung for subject. Empty means
nobody fits — ApprovalRoute treats that as a rung to skip rather than
a request nobody can ever answer.
Array(...) rather than an else arm: approver_rule is held to the
four RULES by a validation AND a database check constraint, so an
unmatched case cannot happen — and a defensive branch nothing can
reach is a line that never gets tested and quietly rots.
24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/hr_lite/approval_step.rb', line 24 def approvers_for(subject) Array( case approver_rule when "manager" then manager_of(subject.user_id) when "manager_of_manager" then manager_of(manager_of(subject.user_id)&.id) when "permission" then HrLite.users_holding(approver_key, scope: :all).to_a when "user" then HrLite.user_klass.find_by(id: approver_key) end ) end |
#label ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'app/models/hr_lite/approval_step.rb', line 35 def label case approver_rule when "manager" then "Their manager" when "manager_of_manager" then "Their manager's manager" when "permission" then "Anyone who can #{Permissions.description(approver_key).downcase}" when "user" then HrLite.display_name(HrLite.user_klass.find_by(id: approver_key)) end end |