Module: HrLite
- Defined in:
- lib/hr_lite.rb,
lib/hr_lite/geo.rb,
lib/hr_lite/money.rb,
lib/hr_lite/seeds.rb,
lib/hr_lite/engine.rb,
lib/hr_lite/current.rb,
lib/hr_lite/version.rb,
lib/hr_lite/leave_year.rb,
app/models/hr_lite/kudo.rb,
lib/hr_lite/configuration.rb,
lib/hr_lite/notifications.rb,
app/models/hr_lite/holiday.rb,
app/models/hr_lite/setting.rb,
lib/hr_lite/mention_parser.rb,
lib/hr_lite/amount_in_words.rb,
app/models/hr_lite/appraisal.rb,
app/models/hr_lite/audit_log.rb,
app/models/hr_lite/leave_type.rb,
app/services/hr_lite/team_day.rb,
app/models/hr_lite/payroll_run.rb,
app/models/hr_lite/resignation.rb,
app/models/hr_lite/salary_slip.rb,
app/models/hr_lite/kudo_mention.rb,
app/services/hr_lite/day_status.rb,
lib/hr_lite/statutory_rate_card.rb,
app/jobs/hr_lite/application_job.rb,
app/mailers/hr_lite/event_mailer.rb,
app/models/hr_lite/leave_balance.rb,
app/models/hr_lite/leave_request.rb,
app/jobs/hr_lite/daily_digest_job.rb,
app/services/hr_lite/pdf_renderer.rb,
app/services/hr_lite/slip_builder.rb,
app/models/hr_lite/office_location.rb,
app/models/concerns/hr_lite/audited.rb,
app/models/hr_lite/comp_off_request.rb,
app/models/hr_lite/employee_profile.rb,
app/models/hr_lite/salary_structure.rb,
app/services/hr_lite/calculators/pf.rb,
app/services/hr_lite/overview_query.rb,
app/models/hr_lite/attendance_record.rb,
app/services/hr_lite/calculators/esi.rb,
app/services/hr_lite/calculators/tds.rb,
app/models/hr_lite/application_record.rb,
app/models/hr_lite/designation_change.rb,
app/services/hr_lite/working_calendar.rb,
app/controllers/hr_lite/org_controller.rb,
app/helpers/hr_lite/application_helper.rb,
app/mailers/hr_lite/application_mailer.rb,
app/services/hr_lite/leave_day_counter.rb,
app/controllers/hr_lite/home_controller.rb,
app/controllers/hr_lite/team_controller.rb,
app/jobs/hr_lite/payroll_auto_draft_job.rb,
app/services/hr_lite/attendance_puncher.rb,
app/services/hr_lite/attendance_summary.rb,
app/controllers/hr_lite/kudos_controller.rb,
app/controllers/hr_lite/users_controller.rb,
app/jobs/hr_lite/leave_year_rollover_job.rb,
app/controllers/hr_lite/career_controller.rb,
app/models/hr_lite/regularization_request.rb,
app/services/hr_lite/calculators/proration.rb,
app/services/hr_lite/payroll_run_processor.rb,
app/controllers/hr_lite/calendar_controller.rb,
app/controllers/hr_lite/holidays_controller.rb,
app/models/concerns/hr_lite/encrypted_money.rb,
app/controllers/hr_lite/admin/base_controller.rb,
app/controllers/hr_lite/appraisals_controller.rb,
app/controllers/hr_lite/attendance_controller.rb,
app/controllers/hr_lite/application_controller.rb,
app/controllers/hr_lite/resignations_controller.rb,
app/controllers/hr_lite/salary_slips_controller.rb,
lib/generators/hr_lite/install/install_generator.rb,
app/controllers/hr_lite/admin/holidays_controller.rb,
app/controllers/hr_lite/admin/overview_controller.rb,
app/controllers/hr_lite/admin/settings_controller.rb,
app/controllers/hr_lite/leave_balances_controller.rb,
app/controllers/hr_lite/leave_requests_controller.rb,
app/services/hr_lite/calculators/professional_tax.rb,
app/controllers/hr_lite/admin/employees_controller.rb,
app/controllers/hr_lite/admin/appraisals_controller.rb,
app/controllers/hr_lite/admin/audit_logs_controller.rb,
app/controllers/hr_lite/admin/leadership_controller.rb,
app/controllers/hr_lite/admin/superadmin_controller.rb,
app/controllers/hr_lite/admin/attendances_controller.rb,
app/controllers/hr_lite/admin/leave_types_controller.rb,
app/controllers/hr_lite/comp_off_requests_controller.rb,
app/controllers/hr_lite/employee_profiles_controller.rb,
app/controllers/hr_lite/admin/payroll_runs_controller.rb,
app/controllers/hr_lite/admin/resignations_controller.rb,
app/controllers/hr_lite/admin/salary_slips_controller.rb,
app/controllers/hr_lite/admin/leave_balances_controller.rb,
app/controllers/hr_lite/admin/leave_requests_controller.rb,
app/controllers/hr_lite/admin/office_locations_controller.rb,
app/controllers/hr_lite/admin/comp_off_requests_controller.rb,
app/controllers/hr_lite/admin/salary_structures_controller.rb,
app/controllers/hr_lite/regularization_requests_controller.rb,
app/controllers/hr_lite/admin/designation_changes_controller.rb,
app/controllers/hr_lite/admin/regularization_requests_controller.rb
Defined Under Namespace
Modules: Admin, AmountInWords, ApplicationHelper, AttendanceSummary, Audited, Calculators, EncryptedMoney, Generators, Geo, LeaveDayCounter, LeaveYear, MentionParser, Money, Notifications, PdfRenderer, Seeds, StatutoryRateCard Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Appraisal, AppraisalsController, AttendanceController, AttendancePuncher, AttendanceRecord, AuditLog, CalendarController, CareerController, CompOffRequest, CompOffRequestsController, Configuration, Current, DailyDigestJob, DayStatus, DesignationChange, EmployeeProfile, EmployeeProfilesController, Engine, EventMailer, Holiday, HolidaysController, HomeController, Kudo, KudoMention, KudosController, LeaveBalance, LeaveBalancesController, LeaveRequest, LeaveRequestsController, LeaveType, LeaveYearRolloverJob, OfficeLocation, OrgController, OverviewQuery, PayrollAutoDraftJob, PayrollRun, PayrollRunProcessor, RegularizationRequest, RegularizationRequestsController, Resignation, ResignationsController, SalarySlip, SalarySlipsController, SalaryStructure, Setting, SlipBuilder, TeamController, TeamDay, UsersController, WorkingCalendar
Constant Summary collapse
- VERSION =
"0.5.0"
Class Method Summary collapse
-
.active_employees(on: Date.current) ⇒ Object
employees minus anyone whose profile says they have exited — user accounts outlive employment (slip access), broadcasts must not.
- .admin?(user) ⇒ Boolean
- .admin_users ⇒ Object
- .config ⇒ Object
-
.config=(configuration) ⇒ Object
Test-only escape hatch: swap the whole configuration object.
- .configure {|config| ... } ⇒ Object
-
.default_mentionable_users(query) ⇒ Object
Default @mention source: name/email prefix match on the host user table.
- .display_name(user) ⇒ Object
-
.employees ⇒ Object
Everyone HR tracks (host-overridable to exclude bots/test accounts), sorted by display name for team screens.
- .leadership?(user) ⇒ Boolean
-
.leadership_users ⇒ Object
Leadership members resolvable to actual user records (for bell notifications).
-
.notify(user:, kind:, title:, body: nil, path: nil) ⇒ Object
Host bell hook.
-
.public_url(path = "/") ⇒ Object
Absolute public URL for an engine-relative path, from config.public_url_base.
-
.public_url?(candidate) ⇒ Boolean
True when the given absolute URL points at the configured public HR host — the allowlist check for hosts that follow stored notification links (an open-redirect guard stays intact on their side).
- .superadmin?(user) ⇒ Boolean
- .user_klass ⇒ Object
Class Method Details
.active_employees(on: Date.current) ⇒ Object
employees minus anyone whose profile says they have exited — user accounts outlive employment (slip access), broadcasts must not.
67 68 69 70 |
# File 'lib/hr_lite.rb', line 67 def active_employees(on: Date.current) exits = HrLite::EmployeeProfile.where.not(date_of_exit: nil).pluck(:user_id, :date_of_exit).to_h employees.select { |u| exits[u.id].nil? || exits[u.id] >= on } end |
.admin?(user) ⇒ Boolean
33 34 35 |
# File 'lib/hr_lite.rb', line 33 def admin?(user) user.present? && !!config.admin_check.call(user) end |
.admin_users ⇒ Object
55 56 57 |
# File 'lib/hr_lite.rb', line 55 def admin_users user_klass.all.select { |u| admin?(u) } end |
.config ⇒ Object
16 17 18 |
# File 'lib/hr_lite.rb', line 16 def config @config ||= Configuration.new end |
.config=(configuration) ⇒ Object
Test-only escape hatch: swap the whole configuration object.
25 26 27 |
# File 'lib/hr_lite.rb', line 25 def config=(configuration) @config = configuration end |
.configure {|config| ... } ⇒ Object
20 21 22 |
# File 'lib/hr_lite.rb', line 20 def configure yield config end |
.default_mentionable_users(query) ⇒ Object
Default @mention source: name/email prefix match on the host user table. Uses LOWER(...) LIKE so it works on sqlite and postgres alike; hosts with pg_trgm or scopes of their own override config.mentionable_users.
94 95 96 97 98 99 100 101 102 |
# File 'lib/hr_lite/configuration.rb', line 94 def default_mentionable_users(query) q = "%#{ActiveRecord::Base.sanitize_sql_like(query.to_s.downcase)}%" klass = user_klass columns = %w[name email].select { |c| klass.column_names.include?(c) } return klass.none if columns.empty? where_sql = columns.map { |c| "LOWER(#{klass.table_name}.#{c}) LIKE :q" }.join(" OR ") klass.where(where_sql, q: q).order(:id).limit(8) end |
.display_name(user) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hr_lite.rb', line 72 def display_name(user) return "" if user.nil? [ config.display_name_method, :display_name, :name, :email ].each do |m| next unless m && user.respond_to?(m) value = user.public_send(m).presence return value if value end "User ##{user.id}" end |
.employees ⇒ Object
Everyone HR tracks (host-overridable to exclude bots/test accounts), sorted by display name for team screens.
61 62 63 |
# File 'lib/hr_lite.rb', line 61 def employees config.employees_scope.call.sort_by { |u| display_name(u).downcase } end |
.leadership?(user) ⇒ Boolean
37 38 39 |
# File 'lib/hr_lite.rb', line 37 def leadership?(user) user.present? && !!config.leadership_check.call(user) end |
.leadership_users ⇒ Object
Leadership members resolvable to actual user records (for bell notifications). Emails configured but absent from the user table are still reachable by email — see Notifications.
48 49 50 51 52 53 |
# File 'lib/hr_lite.rb', line 48 def leadership_users emails = config.leadership_emails.map { |e| e.to_s.downcase.strip }.reject(&:empty?) return user_klass.none if emails.empty? user_klass.where("LOWER(#{user_klass.table_name}.email) IN (?)", emails) end |
.notify(user:, kind:, title:, body: nil, path: nil) ⇒ Object
Host bell hook. Never raises — a notification must not break the domain action that triggered it.
110 111 112 113 114 115 |
# File 'lib/hr_lite.rb', line 110 def notify(user:, kind:, title:, body: nil, path: nil) config.notify.call(user: user, kind: kind, title: title, body: body, path: path) rescue => e Rails.logger.error("[hr_lite] notify failed: #{e.class}: #{e.}") nil end |
.public_url(path = "/") ⇒ Object
Absolute public URL for an engine-relative path, from config.public_url_base. Nil when no base is configured — callers (and emails) then simply carry no link. Hosts use this to build bell deep-links and profile links without re-deriving the HR host.
87 88 89 90 91 92 |
# File 'lib/hr_lite.rb', line 87 def public_url(path = "/") base = config.public_url_base.to_s.chomp("/") return nil if base.empty? "#{base}#{path}" end |
.public_url?(candidate) ⇒ Boolean
True when the given absolute URL points at the configured public HR host — the allowlist check for hosts that follow stored notification links (an open-redirect guard stays intact on their side).
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hr_lite.rb', line 97 def public_url?(candidate) base = public_url return false if base.nil? candidate_uri = URI.parse(candidate.to_s) base_uri = URI.parse(base) %w[http https].include?(candidate_uri.scheme) && candidate_uri.host == base_uri.host rescue URI::InvalidURIError false end |
.superadmin?(user) ⇒ Boolean
41 42 43 |
# File 'lib/hr_lite.rb', line 41 def superadmin?(user) user.present? && !!config.superadmin_check.call(user) end |
.user_klass ⇒ Object
29 30 31 |
# File 'lib/hr_lite.rb', line 29 def user_klass config.user_class.constantize end |