Class: AppMode

Inherits:
Object
  • Object
show all
Defined in:
app/models/app_mode.rb

Constant Summary collapse

PAYROLL_MODE =
'payroll'
EDI_MODE =
'edi'
AI_PLATFORM_MODE =
'ai_platform'
PAYROLL_MODE_APP_ID =
1
EDI_MODE_APP_ID =
2
AI_PLATFORM_MODE_APP_ID =
3
ACCEPTABLE_MODES =
[PAYROLL_MODE, EDI_MODE, AI_PLATFORM_MODE].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode) ⇒ AppMode

Returns a new instance of AppMode.

Raises:

  • (ArgumentError)


44
45
46
47
48
# File 'app/models/app_mode.rb', line 44

def initialize(mode)
  raise ArgumentError, "Invalid mode: #{mode}" unless ACCEPTABLE_MODES.include?(mode)

  @mode = mode
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



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

def mode
  @mode
end

Class Method Details

.ai_platformObject



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

def ai_platform
  AppMode.new(AI_PLATFORM_MODE)
end

.ediObject



33
34
35
# File 'app/models/app_mode.rb', line 33

def edi
  AppMode.new(EDI_MODE)
end

.from_referer_host(host_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/app_mode.rb', line 15

def from_referer_host(host_name)
  if ['omni.edi2xml.com', 'app.paiehub.ca', 'dev.paiehub.ca'].include?(host_name)
    AppMode.new(PAYROLL_MODE)
  elsif ['app.edi2xml.com', 'devapp.edi2xml.com'].include?(host_name)
    AppMode.new(EDI_MODE)
  elsif ['askelixir.ai', 'ai.edi2xml.com', 'dev.askelixir.ai'].include?(host_name)
    AppMode.new(AI_PLATFORM_MODE)
  elsif Rails.env.local?
    AppMode.new(Rails.application.config.default_app_mode)
  else
    AppMode.new(PAYROLL_MODE)
  end
end

.payrollObject



29
30
31
# File 'app/models/app_mode.rb', line 29

def payroll
  AppMode.new(PAYROLL_MODE)
end

Instance Method Details

#agreement_file_pathObject



159
160
161
162
163
164
165
166
167
# File 'app/models/app_mode.rb', line 159

def agreement_file_path
  if payroll?
    Parameter.payroll_agreement_path
  elsif edi?
    Parameter.edi_agreement_path
  elsif ai_platform?
    Parameter.ai_platform_agreement_path
  end
end

#agreement_pathObject



129
130
131
132
133
134
135
136
137
# File 'app/models/app_mode.rb', line 129

def agreement_path
  if payroll?
    '/onboard/payroll/agreement'
  elsif edi?
    '/onboard/edi/agreement'
  elsif ai_platform?
    '/onboard/ai_platform/agreement'
  end
end

#agreement_typeObject



149
150
151
152
153
154
155
156
157
# File 'app/models/app_mode.rb', line 149

def agreement_type
  if payroll?
    CompanyAgreement::PAYROLL_TYPE
  elsif edi?
    CompanyAgreement::EDI_TYPE
  elsif ai_platform?
    CompanyAgreement::AI_PLATFORM_TYPE
  end
end

#application_idObject



50
51
52
53
54
55
56
57
58
59
# File 'app/models/app_mode.rb', line 50

def application_id
  case mode
  when PAYROLL_MODE
    PAYROLL_MODE_APP_ID
  when EDI_MODE
    EDI_MODE_APP_ID
  when AI_PLATFORM_MODE
    AI_PLATFORM_MODE_APP_ID
  end
end

#can_register?Boolean

Returns:

  • (Boolean)


189
190
191
# File 'app/models/app_mode.rb', line 189

def can_register?
  SpecialParameter.can_register?(application_id: application_id)
end

#company_details_pathObject



139
140
141
142
143
144
145
146
147
# File 'app/models/app_mode.rb', line 139

def company_details_path
  if payroll?
    '/onboard/payroll/company_details'
  elsif edi?
    '/onboard/edi/company_details'
  elsif ai_platform?
    '/onboard/ai_platform/company_details'
  end
end

#company_details_present?(company:) ⇒ Boolean

Returns:

  • (Boolean)


169
170
171
172
173
174
175
176
177
# File 'app/models/app_mode.rb', line 169

def company_details_present?(company:)
  if payroll?
    company.company_name_e.present?
  elsif edi?
    company.company_name_e.present?
  elsif ai_platform?
    company.company_name_e.present?
  end
end

#onboardable?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'app/models/app_mode.rb', line 115

def onboardable?
  payroll? || edi? || ai_platform?
end

#permission_groups_codesObject



102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/models/app_mode.rb', line 102

def permission_groups_codes
  case mode
  when PAYROLL_MODE
    [PermissionGroup::Codes::PAYROLL_ADMIN]
  when EDI_MODE
    [PermissionGroup::Codes::EDI]
  when AI_PLATFORM_MODE
    [PermissionGroup::Codes::AI_PLATFORM]
  else
    []
  end
end

#software_nameObject



119
120
121
122
123
124
125
126
127
# File 'app/models/app_mode.rb', line 119

def software_name
  if payroll?
    I18n.t('emails.by')
  elsif edi?
    'edi2xml'
  elsif ai_platform?
    'aiplatform'
  end
end

#supports_partner_by_company?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/app_mode.rb', line 87

def supports_partner_by_company?
  !payroll?
end

#system_record_home_pathObject



91
92
93
94
95
96
97
98
99
100
# File 'app/models/app_mode.rb', line 91

def system_record_home_path
  case mode
  when PAYROLL_MODE
    '/app/payroll'
  when EDI_MODE
    '/app/edi'
  when AI_PLATFORM_MODE
    '/app/ai/chat'
  end
end

#system_user_navigation_configurationObject



72
73
74
# File 'app/models/app_mode.rb', line 72

def system_user_navigation_configuration
  NavigationConfiguration.find(system_user_navigation_configuration_id)
end

#system_user_navigation_configuration_idObject



76
77
78
79
80
81
82
83
84
85
# File 'app/models/app_mode.rb', line 76

def system_user_navigation_configuration_id
  case mode
  when PAYROLL_MODE
    NavigationConfiguration::PAYROLL_SYSTEM_RECORD
  when EDI_MODE
    NavigationConfiguration::EDI_SYSTEM_RECORD
  when AI_PLATFORM_MODE
    NavigationConfiguration::AI_PLATFORM_SYSTEM_RECORD
  end
end

#user_navigation_configuration_idObject



61
62
63
64
65
66
67
68
69
70
# File 'app/models/app_mode.rb', line 61

def user_navigation_configuration_id
  case mode
  when PAYROLL_MODE
    NavigationConfiguration::PAYROLL
  when EDI_MODE
    NavigationConfiguration::EDI
  when AI_PLATFORM_MODE
    NavigationConfiguration::AI_PLATFORM_SYSTEM_RECORD
  end
end

#web_uriObject



179
180
181
182
183
184
185
186
187
# File 'app/models/app_mode.rb', line 179

def web_uri
  if payroll?
    Rails.application.config.payroll_web_ui_url
  elsif edi?
    Rails.application.config.edi_web_ui_url
  elsif ai_platform?
    Rails.application.config.ai_platform_web_ui_url
  end
end