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,
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/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/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/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/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/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/attendances_controller.rb,
app/controllers/hr_lite/admin/leave_types_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/salary_structures_controller.rb,
app/controllers/hr_lite/admin/designation_changes_controller.rb

Defined Under Namespace

Modules: Admin, AmountInWords, ApplicationHelper, AttendanceSummary, Audited, Calculators, EncryptedMoney, Generators, Geo, LeaveDayCounter, MentionParser, Money, Notifications, PdfRenderer, Seeds, StatutoryRateCard Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Appraisal, AppraisalsController, AttendanceController, AttendancePuncher, AttendanceRecord, AuditLog, CalendarController, CareerController, Configuration, Current, DailyDigestJob, DayStatus, DesignationChange, EmployeeProfile, EmployeeProfilesController, Engine, EventMailer, Holiday, HolidaysController, HomeController, Kudo, KudoMention, KudosController, LeaveBalance, LeaveBalancesController, LeaveRequest, LeaveRequestsController, LeaveType, LeaveYearRolloverJob, OfficeLocation, OverviewQuery, PayrollAutoDraftJob, PayrollRun, PayrollRunProcessor, Resignation, ResignationsController, SalarySlip, SalarySlipsController, SalaryStructure, Setting, SlipBuilder, UsersController, WorkingCalendar

Constant Summary collapse

VERSION =
"0.2.1"

Class Method Summary collapse

Class Method Details

.admin?(user) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/hr_lite.rb', line 32

def admin?(user)
  user.present? && !!config.admin_check.call(user)
end

.admin_usersObject



50
51
52
# File 'lib/hr_lite.rb', line 50

def admin_users
  user_klass.all.select { |u| admin?(u) }
end

.configObject



15
16
17
# File 'lib/hr_lite.rb', line 15

def config
  @config ||= Configuration.new
end

.config=(configuration) ⇒ Object

Test-only escape hatch: swap the whole configuration object.



24
25
26
# File 'lib/hr_lite.rb', line 24

def config=(configuration)
  @config = configuration
end

.configure {|config| ... } ⇒ Object

Yields:



19
20
21
# File 'lib/hr_lite.rb', line 19

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.



72
73
74
75
76
77
78
79
80
# File 'lib/hr_lite/configuration.rb', line 72

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



60
61
62
63
64
65
66
67
68
69
# File 'lib/hr_lite.rb', line 60

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

.employeesObject

Everyone HR tracks (host-overridable to exclude bots/test accounts), sorted by display name for team screens.



56
57
58
# File 'lib/hr_lite.rb', line 56

def employees
  config.employees_scope.call.sort_by { |u| display_name(u).downcase }
end

.leadership?(user) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/hr_lite.rb', line 36

def leadership?(user)
  user.present? && !!config.leadership_check.call(user)
end

.leadership_usersObject

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.



43
44
45
46
47
48
# File 'lib/hr_lite.rb', line 43

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.



98
99
100
101
102
103
# File 'lib/hr_lite.rb', line 98

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.message}")
  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.



75
76
77
78
79
80
# File 'lib/hr_lite.rb', line 75

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).

Returns:

  • (Boolean)


85
86
87
88
89
90
91
92
93
94
# File 'lib/hr_lite.rb', line 85

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

.user_klassObject



28
29
30
# File 'lib/hr_lite.rb', line 28

def user_klass
  config.user_class.constantize
end