Class: NavigationConfigurationsController
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
#create ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/navigation_configurations_controller.rb', line 26
def create
record = NavigationConfiguration.new
ActiveRecord::Base.transaction do
record.update!(
label: params[:label],
active: !!params[:active]
)
record.associate_from_checkbox_tree_data(params[:modules], current_user.system_record)
end
render json: {}, status: :ok
rescue ActiveRecord::RecordInvalid => e
render json: {
errors: e.record.errors,
message: e.record.errors.full_messages.join(', ')
}, status: :bad_request
end
|
#deactivate ⇒ Object
82
83
84
85
86
87
88
89
90
91
|
# File 'app/controllers/navigation_configurations_controller.rb', line 82
def deactivate
record = NavigationConfiguration.find(params[:id])
return render json: {}, status: :forbidden if record.is_essential
record.update!(active: false)
render json: {
message: I18n.t('messages.navigation_configuration_deactivated'),
data: record
}, status: :ok
end
|
#destroy ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/controllers/navigation_configurations_controller.rb', line 65
def destroy
record = NavigationConfiguration.find(params[:id])
return render json: {}, status: :forbidden if record.is_essential
if record.erp_users.where(system_record: false).any?
return render json: {
message: I18n.t('messages.navigation_configuration_has_users')
}, status: :bad_request
end
record.destroy!
render json: {
message: I18n.t('messages.navigation_configuration_deleted'),
data: record
}, status: :ok
end
|
#index ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/navigation_configurations_controller.rb', line 6
def index
records = NavigationConfiguration
.includes(:erp_users)
.order(is_essential: :desc, active: :desc, id: :asc)
.all
.map do |navigation_configuration|
nc_json = navigation_configuration.as_json
nc_json['navigation_groups'] = navigation_configuration.navigation_data
nc_json['erp_users'] = navigation_configuration
.erp_users
.where(system_record: false)
.select(:erp_user_id, :user_name, :email).as_json
nc_json
end
render json: {
data: records
}
end
|
#options ⇒ Object
93
94
95
96
97
98
99
|
# File 'app/controllers/navigation_configurations_controller.rb', line 93
def options
records = NavigationConfiguration.order(active: :desc, id: :asc).select(:id, :label, :active)
render json: {
data: records
}
end
|
#update ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/controllers/navigation_configurations_controller.rb', line 45
def update
record = NavigationConfiguration.find(params[:id])
return render json: {}, status: :forbidden if record.is_essential
ActiveRecord::Base.transaction do
record.update!(
label: params[:label],
active: !!params[:active]
)
record.associate_from_checkbox_tree_data(params[:modules], current_user.system_record)
end
render json: {}, status: :ok
rescue ActiveRecord::RecordInvalid => e
render json: {
errors: e.record.errors,
message: e.record.errors.full_messages.join(', ')
}, status: :bad_request
end
|