Class: CurrentErpUsersController
Instance Method Summary
collapse
#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token
Instance Method Details
#available_navigation ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/current_erp_users_controller.rb', line 19
def available_navigation
records = NavigationGroup
.order(:order)
.includes(navigation_headers: :navigation_items)
.all
.as_json(include: {
navigation_headers: {
include: :navigation_items
}
})
records = records.select do |record|
record['system_record'] == false && record['navigation_headers'].select do ||
['system_record'] == false && ['navigation_items'].select do |item|
item['system_record'] == false
end
end
end
render json: {
data: records
}
end
|
#current ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'app/controllers/current_erp_users_controller.rb', line 6
def current
current_user_json = current_user.as_json(include:
{
tenant: { only: %i[tenant_id tenant_name] }
})
current_user_json['company'] = current_company.as_json(only: %i[company_id company_name_e logo_path])
current_user_json['companies'] = accessible_companies.as_json(only: %i[company_id company_name_e logo_path])
render json: {
data: current_user_json
}
end
|
#employee_id ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'app/controllers/current_erp_users_controller.rb', line 74
def employee_id
if current_user.system_record
return render json: {
message: 'System record does not have employee id'
}, status: :bad_request
end
employee_id = current_user.employee_ids.first
render json: {
data: {
employee_id: employee_id
}
}
end
|
#home_path ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/controllers/current_erp_users_controller.rb', line 56
def home_path
if !current_company.onboarded?(app_mode: @app_mode) && @app_mode.onboardable?
return render(
status: :bad_request,
json: { redirect_to: current_company.onboarding_path(app_mode: @app_mode) }
)
end
if current_user.system_record
return render json: { data: @app_mode.system_record_home_path }
end
navigation_configuration = current_user.navigation_configuration
render json: {
data: navigation_configuration.home_path
}
end
|
#navigation ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/controllers/current_erp_users_controller.rb', line 43
def navigation
navigation_configuration = if current_user.system_record
@app_mode.system_user_navigation_configuration
else
current_user.navigation_configuration
end
return render json: { data: [] } unless navigation_configuration&.active
data = navigation_configuration.navigation_data
render json: { data: data }
end
|
#switch_locale ⇒ Object
90
91
92
93
94
95
|
# File 'app/controllers/current_erp_users_controller.rb', line 90
def switch_locale
locale = params[:locale]
language = Language.from_locale(locale)
current_user.update(user_language: language.value)
render json: { data: language.locale }
end
|