lesli 5.0.10 → 5.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/config/lesli_manifest.js +0 -13
- data/app/assets/icons/lesli/engine-security.svg +1 -0
- data/app/assets/icons/lesli/engine-shield.svg +1 -0
- data/app/assets/images/lesli/lesli-logo.svg +4 -0
- data/app/assets/stylesheets/lesli/templates/application.css +21862 -209
- data/app/assets/stylesheets/lesli/templates/public.css +19098 -1
- data/app/assets/stylesheets/lesli/users/confirmations.css +19219 -0
- data/app/assets/stylesheets/lesli/users/passwords.css +19202 -0
- data/app/assets/stylesheets/lesli/users/registrations.css +19594 -0
- data/app/assets/stylesheets/lesli/users/sessions.css +19594 -1
- data/app/controllers/lesli/abouts_controller.rb +12 -18
- data/app/controllers/lesli/application_controller.rb +25 -25
- data/app/controllers/lesli/application_lesli_controller.rb +5 -6
- data/app/controllers/lesli/interfaces/application/authorization.rb +1 -1
- data/app/controllers/lesli/interfaces/application/customization.rb +1 -1
- data/app/controllers/lesli/interfaces/application/requester.rb +2 -2
- data/app/controllers/lesli/interfaces/application/responder.rb +8 -8
- data/app/controllers/lesli/interfaces/controllers/actions.rb +250 -0
- data/app/controllers/lesli/interfaces/controllers/activities.rb +215 -0
- data/app/controllers/lesli/interfaces/controllers/discussions.rb +270 -0
- data/app/controllers/lesli/interfaces/controllers/files.rb +467 -0
- data/app/controllers/lesli/interfaces/controllers/subscribers.rb +234 -0
- data/app/helpers/lesli/assets_helper.rb +4 -4
- data/app/helpers/lesli/navigation_helper.rb +38 -81
- data/app/lib/lesli/system.rb +4 -3
- data/app/models/concerns/account_initializer.rb +46 -42
- data/{lib/scss/devise/registrations.scss → app/models/lesli/account/detail.rb} +7 -3
- data/app/models/lesli/account.rb +12 -5
- data/app/models/lesli/cloud_object/action.rb +70 -0
- data/app/models/lesli/cloud_object/activity.rb +311 -0
- data/app/models/lesli/cloud_object/custom_field.rb +158 -0
- data/app/models/lesli/cloud_object/discussion.rb +219 -0
- data/app/models/lesli/cloud_object/subscriber.rb +186 -0
- data/app/models/lesli/shared/dashboard.rb +16 -5
- data/app/models/lesli/user/session.rb +0 -2
- data/app/models/lesli/user.rb +13 -13
- data/app/operators/lesli/user_registration_operator.rb +3 -3
- data/app/views/lesli/layouts/application-devise.html.erb +6 -6
- data/app/views/lesli/layouts/application-lesli.html.erb +1 -1
- data/app/views/lesli/partials/_application-data.html.erb +2 -1
- data/app/views/lesli/partials/_application-lesli-engines.html.erb +14 -39
- data/app/views/lesli/partials/_application-lesli-header.html.erb +4 -4
- data/app/views/lesli/partials/_application-lesli-icons.html.erb +1 -1
- data/app/views/lesli/partials/_application-lesli-panels.html.erb +7 -7
- data/app/views/lesli/wrappers/_application-devise.html.erb +5 -7
- data/config/initializers/devise.rb +335 -335
- data/config/initializers/lesli.rb +8 -2
- data/config/locales/translations.en.yml +4 -0
- data/config/locales/translations.es.yml +4 -0
- data/config/locales/translations.fr.yml +28 -0
- data/config/locales/translations.it.yml +28 -0
- data/config/locales/translations.pt.yml +28 -0
- data/config/routes.rb +1 -10
- data/db/migrate/{v1.0/0010003010_create_lesli_user_details.rb → v1/0010000110_create_lesli_accounts.rb} +19 -13
- data/db/migrate/{v1.0/0010000110_create_lesli_accounts.rb → v1/0010001010_create_lesli_account_details.rb} +5 -7
- data/db/migrate/{v1.0/0010001010_create_lesli_account_settings.rb → v1/0010001110_create_lesli_account_settings.rb} +2 -2
- data/db/seed/development/accounts.rb +10 -7
- data/db/seed/development/users.rb +20 -20
- data/db/seed/production/accounts.rb +10 -7
- data/db/seed/production/users.rb +7 -0
- data/db/seed/tools.rb +0 -1
- data/lib/lesli/engine.rb +2 -12
- data/lib/lesli/version.rb +2 -2
- data/lib/lesli.rb +0 -1
- data/lib/scss/cloud-objects/discussion.scss +8 -5
- data/lib/scss/layouts/application-header.scss +3 -1
- data/lib/scss/layouts/application-navbar.scss +2 -1
- data/lib/scss/{elements/msg.scss → overrides/notification.scss} +16 -18
- data/lib/scss/pages/devise-simple.scss +4 -2
- data/lib/scss/pages/devise.scss +111 -99
- data/lib/scss/panels/panel-notification.scss +1 -1
- data/lib/scss/panels/{panel-ticket.scss → panel-support-ticket.scss} +3 -4
- data/lib/scss/templates/application.scss +7 -5
- data/lib/tasks/lesli/controllers.rake +1 -1
- data/lib/tasks/lesli/db.rake +33 -31
- data/lib/tasks/lesli_tasks.rake +6 -6
- data/lib/vue/application.js +13 -12
- data/lib/vue/{refactor/shared/cloudobjects → cloudobjects}/discussion/content.vue +10 -8
- data/lib/vue/cloudobjects/discussion/element.vue +170 -0
- data/lib/vue/{refactor/shared/cloudobjects → cloudobjects}/discussion/filters.vue +1 -1
- data/lib/vue/{refactor/shared/cloudobjects → cloudobjects}/discussion/new.vue +20 -16
- data/lib/vue/{refactor/shared/cloudobjects → cloudobjects}/discussion.vue +25 -24
- data/lib/vue/{refactor/stores/cloudobjects → cloudobjects/stores}/discussion.js +7 -16
- data/lib/vue/layouts/application-header.vue +5 -5
- data/lib/vue/panels/{panel-notifications.vue → panel-bell-notifications.vue} +15 -19
- data/lib/vue/panels/panel-support-tickets.vue +161 -0
- data/lib/vue/panels/stores/bell-notifications.js +46 -0
- data/lib/vue/panels/stores/support-tickets.js +103 -0
- data/lib/vue/shared/dashboards/apps/edit.vue +10 -10
- data/lib/vue/shared/dashboards/components/form.vue +31 -40
- data/lib/vue/shared/stores/dashboard.js +2 -0
- data/lib/vue/shared/stores/layout.js +2 -1
- data/lib/{scss/devise/confirmations.scss → vue/shared/stores/users.js} +22 -21
- data/lib/vue/stores/translations.json +109 -2
- data/lib/webpack/base.js +9 -8
- data/lib/webpack/core.js +8 -6
- data/readme.md +16 -15
- metadata +49 -75
- data/app/assets/icons/lesli/engine-guard.svg +0 -1
- data/app/assets/javascripts/lesli/users/sessions.js +0 -1
- data/app/controllers/users/confirmations_controller.rb +0 -66
- data/app/controllers/users/omniauth_callbacks_controller.rb +0 -30
- data/app/controllers/users/passwords_controller.rb +0 -71
- data/app/controllers/users/registrations_controller.rb +0 -141
- data/app/controllers/users/sessions_controller.rb +0 -141
- data/app/controllers/users/unlocks_controller.rb +0 -30
- data/app/views/devise/confirmations/new.html.erb +0 -2
- data/app/views/devise/confirmations/show.html.erb +0 -63
- data/app/views/devise/mailer/confirmation_instructions.html.erb +0 -5
- data/app/views/devise/mailer/email_changed.html.erb +0 -7
- data/app/views/devise/mailer/password_change.html.erb +0 -3
- data/app/views/devise/mailer/reset_password_instructions.html.erb +0 -8
- data/app/views/devise/mailer/unlock_instructions.html.erb +0 -7
- data/app/views/devise/passwords/edit.html.erb +0 -79
- data/app/views/devise/passwords/new.html.erb +0 -75
- data/app/views/devise/registrations/edit.html.erb +0 -43
- data/app/views/devise/registrations/new.html.erb +0 -147
- data/app/views/devise/sessions/new.html.erb +0 -111
- data/app/views/devise/shared/_error_messages.html.erb +0 -15
- data/app/views/devise/shared/_links.html.erb +0 -96
- data/app/views/devise/unlocks/new.html.erb +0 -16
- data/db/migrate/v1.0/0010000210_create_lesli_roles.rb +0 -59
- data/db/migrate/v1.0/0010000310_create_lesli_users.rb +0 -97
- data/db/migrate/v1.0/0010003110_create_lesli_user_settings.rb +0 -44
- data/db/migrate/v1.0/0010003210_create_lesli_user_sessions.rb +0 -55
- data/db/migrate/v1.0/0010003410_create_lesli_user_powers.rb +0 -43
- data/db/migrate/v1.0/0010004010_create_lesli_user_logs.rb +0 -45
- data/db/migrate/v1.0/0010005010_create_lesli_descriptors.rb +0 -44
- data/db/migrate/v1.0/0010005110_create_lesli_descriptor_privileges.rb +0 -45
- data/db/migrate/v1.0/0010005210_create_lesli_descriptor_activities.rb +0 -49
- data/db/migrate/v1.0/0010005510_create_lesli_role_powers.rb +0 -51
- data/db/migrate/v1.0/0010005710_create_lesli_role_privileges.rb +0 -45
- data/lib/lesli/routing.rb +0 -26
- data/lib/scss/components/editor-richtext.scss +0 -88
- data/lib/scss/devise/oauth.scss +0 -34
- data/lib/scss/devise/passwords.scss +0 -33
- data/lib/scss/devise/sessions.scss +0 -35
- data/lib/scss/elements/avatar.scss +0 -48
- data/lib/scss/elements/calendar.scss +0 -47
- data/lib/scss/elements/toggle.scss +0 -102
- data/lib/vue/devise/confirmations.js +0 -33
- data/lib/vue/devise/passwords.js +0 -137
- data/lib/vue/devise/registrations.js +0 -157
- data/lib/vue/devise/sessions.js +0 -148
- data/lib/vue/panels/panel-tickets.vue +0 -181
- data/lib/vue/refactor/shared/cloudobjects/discussion/element.vue +0 -132
- data/lib/vue/shared/stores/account.js +0 -113
- /data/app/assets/icons/lesli/{engine-driver.svg → engine-calendar.svg} +0 -0
- /data/db/migrate/{v1.0 → v1}/0010000610_create_lesli_system_controllers.rb +0 -0
- /data/db/migrate/{v1.0 → v1}/0010000710_create_lesli_system_controller_actions.rb +0 -0
- /data/db/migrate/{v1.0 → v1}/0010001210_create_lesli_account_activities.rb +0 -0
- /data/db/migrate/{v1.0 → v1}/0010001410_create_lesli_account_logs.rb +0 -0
@@ -0,0 +1,467 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
Lesli
|
4
|
+
|
5
|
+
Copyright (c) 2023, Lesli Technologies, S. A.
|
6
|
+
|
7
|
+
This program is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the GNU General Public License as published by
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
This program is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
GNU General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU General Public License
|
18
|
+
along with this program. If not, see http://www.gnu.org/licenses/.
|
19
|
+
|
20
|
+
Lesli · Your Smart Business Assistant.
|
21
|
+
|
22
|
+
Made with ♥ by https://www.lesli.tech
|
23
|
+
Building a better future, one line of code at a time.
|
24
|
+
|
25
|
+
@contact hello@lesli.tech
|
26
|
+
@website https://lesli.tech
|
27
|
+
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
28
|
+
|
29
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
30
|
+
// ·
|
31
|
+
|
32
|
+
=end
|
33
|
+
|
34
|
+
module Lesli
|
35
|
+
module Interfaces
|
36
|
+
module Controllers
|
37
|
+
module Files
|
38
|
+
|
39
|
+
|
40
|
+
# @return [Json] Json that contains a list of all files related to a *cloud_object*
|
41
|
+
# @description Retrieves and returns all files associated to a *cloud_object*. The id of the
|
42
|
+
# *cloud_object* is within the *params* attribute. If the child class provides a block, the function is
|
43
|
+
# yielded sending the files as parameters. The block given *must* return the HTTP response
|
44
|
+
# @example
|
45
|
+
# # Executing this controller's action from javascript's frontend
|
46
|
+
# let ticket_id = 1;
|
47
|
+
# this.http.get(`127.0.0.1/help/tickets/${ticket_id}/files.json`);
|
48
|
+
def index
|
49
|
+
file_model = file_model() # If there is a custom file model, it must be returned in this method
|
50
|
+
cloud_object_model = file_model.cloud_object_model
|
51
|
+
account_model = cloud_object_model.reflect_on_association(:account).klass
|
52
|
+
|
53
|
+
#Get filters from http request
|
54
|
+
filters = params[:f]
|
55
|
+
|
56
|
+
#Get start and final date only if the request have filters
|
57
|
+
unless filters.blank?
|
58
|
+
file_type = filters[:file_type]
|
59
|
+
end
|
60
|
+
|
61
|
+
respond_to do |format|
|
62
|
+
format.json do
|
63
|
+
@files = file_model.where(
|
64
|
+
"#{cloud_object_model.table_name}_id".to_sym => params["#{cloud_object_model.name.demodulize.underscore}_id".to_sym]
|
65
|
+
)
|
66
|
+
|
67
|
+
# Filter results
|
68
|
+
unless file_type.blank?
|
69
|
+
@files = @files.where(file_type: file_type)
|
70
|
+
end
|
71
|
+
|
72
|
+
@files = @files
|
73
|
+
.order(id: :desc).map do |file|
|
74
|
+
file_attributes = file.attributes
|
75
|
+
file_attributes["user_creator_name"] = file.user_creator&.full_name
|
76
|
+
file_attributes["public_url"] = file.attachment_public.url if file.attachment_public
|
77
|
+
file_attributes["created_at_raw"] = file_attributes["created_at"]
|
78
|
+
file_attributes["created_at"] = LC::Date2.new(file_attributes["created_at"]).date_time.to_s
|
79
|
+
file_attributes["updated_at_raw"] = file_attributes["updated_at"]
|
80
|
+
file_attributes["updated_at"] = LC::Date2.new(file_attributes["updated_at"]).date_time.to_s
|
81
|
+
file_attributes["editable"] = file.is_editable_by?(current_user)
|
82
|
+
file_attributes
|
83
|
+
end
|
84
|
+
|
85
|
+
if block_given?
|
86
|
+
yield(@files)
|
87
|
+
else
|
88
|
+
respond_with_successful(@files)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
format.zip do
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
# @controller_action_param :attachment [File] The uploaded attachment
|
100
|
+
# @controller_action_param :name [String] The name to be displayed
|
101
|
+
# @controller_action_param :file_type [String] The file type of
|
102
|
+
# @return [Json] Json that contains wheter the creation of the file was successful or not.
|
103
|
+
# If it is not successful, it returs an error message
|
104
|
+
# @description Creates a new file associated to a *cloud_object*. The id of the
|
105
|
+
# *cloud_object* is within the *params* attribute. If the child class provides a block, the function is
|
106
|
+
# yielded sending the cloud_object as first param, and the file as second param.
|
107
|
+
# The block given *must* return the HTTP response
|
108
|
+
# @example
|
109
|
+
# # Executing this controller's action from javascript's frontend
|
110
|
+
# let ticket_id = 1;
|
111
|
+
# let data = {
|
112
|
+
# ticket_file: {
|
113
|
+
# file: FILE_CONTENT
|
114
|
+
# name: "contract_information"
|
115
|
+
# }
|
116
|
+
# };
|
117
|
+
# this.http.post(`127.0.0.1/help/tickets/${ticket_id}/files`, data);
|
118
|
+
def create
|
119
|
+
file_model = file_model() # If there is a custom file model, it must be returned in this method
|
120
|
+
cloud_object_model = file_model.cloud_object_model
|
121
|
+
|
122
|
+
set_cloud_object
|
123
|
+
new_file_params = file_params.merge(
|
124
|
+
user_creator: current_user,
|
125
|
+
cloud_object: @cloud_object
|
126
|
+
)
|
127
|
+
|
128
|
+
# Verifying the extension of the file. If it's valid, the block will be executed
|
129
|
+
decode_and_verify_file(new_file_params) do |verified_file_params|
|
130
|
+
file = file_model.new(verified_file_params)
|
131
|
+
|
132
|
+
if file.save
|
133
|
+
# Setting the file name in case it's blank and updating the file in case the filename changed
|
134
|
+
if file.name.blank?
|
135
|
+
file.update(
|
136
|
+
name: params["#{cloud_object_model.name.demodulize.underscore}_file".to_sym][:attachment].original_filename
|
137
|
+
)
|
138
|
+
else
|
139
|
+
file.update({})
|
140
|
+
end
|
141
|
+
|
142
|
+
cloud_object = file.cloud_object
|
143
|
+
|
144
|
+
# Setting up file uploader to upload in background
|
145
|
+
Files::AwsUploadJob.perform_later(file)
|
146
|
+
|
147
|
+
if block_given?
|
148
|
+
yield(cloud_object, file)
|
149
|
+
else
|
150
|
+
# Registering an activity in the cloud_object
|
151
|
+
cloud_object.activities.create(
|
152
|
+
user_creator: current_user,
|
153
|
+
category: "action_create_file",
|
154
|
+
description: "#{file.name} - #{file.attachment_identifier}"
|
155
|
+
)
|
156
|
+
|
157
|
+
# Returning the 200 HTTP response
|
158
|
+
respond_with_successful(file)
|
159
|
+
end
|
160
|
+
else
|
161
|
+
respond_with_error(file.errors.full_messages.to_sentence)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# @controller_action_param :attachment [File] The uploaded attachment
|
167
|
+
# @controller_action_param :name [String] The name to be displayed
|
168
|
+
# @controller_action_param :file_type [String] The file type of
|
169
|
+
# @return [Json] Json that contains wheter the creation of the file was successful or not.
|
170
|
+
# If it is not successful, it returs an error message
|
171
|
+
# @description Updates an existing file associated to a *cloud_object*. The id of the
|
172
|
+
# *cloud_object* is within the *params* attribute. If the child class provides a block, the function is
|
173
|
+
# yielded sending the cloud_object as first param, and the file as second param.
|
174
|
+
# The block given *must* return the HTTP response
|
175
|
+
# @example
|
176
|
+
# # Executing this controller's action from javascript's frontend
|
177
|
+
# let ticket_id = 1;
|
178
|
+
# let data = {
|
179
|
+
# ticket_file: {
|
180
|
+
# file: FILE_CONTENT
|
181
|
+
# name: "contract_information"
|
182
|
+
# }
|
183
|
+
# };
|
184
|
+
# this.http.put(`127.0.0.1/help/tickets/${ticket_id}/files`, data);
|
185
|
+
def update
|
186
|
+
set_file
|
187
|
+
return respond_with_not_found unless @file
|
188
|
+
|
189
|
+
# Verifying the extension of the file. If it's valid, the block will be executed
|
190
|
+
decode_and_verify_file(file_params) do |verified_file_params|
|
191
|
+
if @file.update(verified_file_params)
|
192
|
+
|
193
|
+
# Setting up file uploader to upload in background
|
194
|
+
Files::AwsUploadJob.perform_later(@file)
|
195
|
+
|
196
|
+
if block_given?
|
197
|
+
yield(@cloud_object, @file)
|
198
|
+
else
|
199
|
+
# Registering an activity in the cloud_object
|
200
|
+
@file.cloud_object.activities.create(
|
201
|
+
user_creator: current_user,
|
202
|
+
category: "action_update_file",
|
203
|
+
description: "#{@file.name} - #{@file.attachment_identifier}"
|
204
|
+
)
|
205
|
+
|
206
|
+
# Returning the 200 HTTP response
|
207
|
+
respond_with_successful(@file)
|
208
|
+
end
|
209
|
+
else
|
210
|
+
respond_with_error(@file.errors.full_messages.to_sentence)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# @return [void]
|
216
|
+
# @description Prepares the files for download and redirects the explorer to a new window,
|
217
|
+
# where they can view/download the file. The id of the
|
218
|
+
# *cloud_object* and the id of the *file* are within the *params* attribute
|
219
|
+
# @example
|
220
|
+
# # Executing this controller's action from javascript's frontend
|
221
|
+
# let ticket_id = 1;
|
222
|
+
# let file_id = 5;
|
223
|
+
# this.http.get(`127.0.0.1/help/tickets/${ticket_id}/files/${file_id}`);
|
224
|
+
def show
|
225
|
+
set_file
|
226
|
+
return respond_with_not_found unless @file
|
227
|
+
|
228
|
+
file_model = file_model()
|
229
|
+
|
230
|
+
disposition = "inline"
|
231
|
+
disposition = "attachment" if params["download"]
|
232
|
+
|
233
|
+
begin
|
234
|
+
# Sending file using CarrierWave
|
235
|
+
if @file.attachment_s3.file
|
236
|
+
|
237
|
+
# We either get the file from AWS and serve it ourselves or provide a direct AWS link with expiration time
|
238
|
+
if @file.size_mb && @file.size_mb > file_model.size_threshold
|
239
|
+
redirect_to(@file.refresh_external_url, allow_other_host: true)
|
240
|
+
else
|
241
|
+
send_data(@file.attachment_s3.read, filename: @file.attachment_s3_identifier, disposition: disposition, stream: "true")
|
242
|
+
end
|
243
|
+
elsif @file.attachment_public.file
|
244
|
+
redirect_to(@file.attachment_public_url, allow_other_host: true)
|
245
|
+
else
|
246
|
+
send_data(@file.attachment.read, filename: @file.attachment_identifier, disposition: disposition, stream: "true")
|
247
|
+
end
|
248
|
+
rescue => exception
|
249
|
+
# Logging the failure to retrieve the file
|
250
|
+
@file.cloud_object.activities.create(
|
251
|
+
user_creator: current_user,
|
252
|
+
category: "action_not_found_file",
|
253
|
+
description: "#{@file.name} - #{@file.attachment_identifier}"
|
254
|
+
)
|
255
|
+
|
256
|
+
# Returning a generic image in response if the file is not found on storage
|
257
|
+
redirect_to("/assets/global/generic.png")
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
# @return [Json] A response that contains wheter the file was deleted or not.
|
262
|
+
# If it is not successful, it returns an error message
|
263
|
+
# @description Deletes a file from the database based on the id of the *cloud_object* and its own id. If a block is given,
|
264
|
+
# the function is yielded with no arguments after the file is destroyed
|
265
|
+
# @example
|
266
|
+
# # Executing this controller's action from javascript's frontend
|
267
|
+
# let ticket_id = 1;
|
268
|
+
# let file_id = 22;
|
269
|
+
# this.http.delete(`127.0.0.1/help/tickets/${ticket_id}/files/${file_id}`);
|
270
|
+
def destroy
|
271
|
+
set_file
|
272
|
+
return respond_with_not_found unless @file
|
273
|
+
return respond_with_unauthorized unless @file.is_editable_by?(current_user)
|
274
|
+
|
275
|
+
if @file.destroy
|
276
|
+
if block_given?
|
277
|
+
yield(@cloud_object, @file)
|
278
|
+
else
|
279
|
+
# Registering an activity in the cloud_object
|
280
|
+
@file.cloud_object.activities.create(
|
281
|
+
user_creator: current_user,
|
282
|
+
category: "action_destroy_file",
|
283
|
+
description: @file.name
|
284
|
+
)
|
285
|
+
|
286
|
+
respond_with_successful
|
287
|
+
end
|
288
|
+
else
|
289
|
+
respond_with_error(@file.errors.full_messages.to_sentence)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
# @return [void]
|
294
|
+
# @description Returns a list of needed information in order to create a file.
|
295
|
+
# For the time being, it only returns a list of all file types
|
296
|
+
# @example
|
297
|
+
# # Executing this controller's action from javascript's frontend
|
298
|
+
# this.http.get('127.0.0.1/house/options/project/files')
|
299
|
+
def options
|
300
|
+
file_model = file_model() # If there is a custom file model, it must be returned in this method
|
301
|
+
respond_with_successful(file_model.options(@query))
|
302
|
+
end
|
303
|
+
|
304
|
+
# @return [void]
|
305
|
+
# @description Creates a zip file with all selected documents and sends it to the user. Note that files
|
306
|
+
# that don't belong to the current_user's account will be ignored. This method is deprecated, use
|
307
|
+
# the index method instead.
|
308
|
+
# @example
|
309
|
+
# # Executing this controller's action from javascript's frontend
|
310
|
+
# this.http.get('127.0.0.1/house/projects/1/resources/files-zip-download&ids=1,2,3,4');
|
311
|
+
def zip_download
|
312
|
+
|
313
|
+
end
|
314
|
+
|
315
|
+
protected
|
316
|
+
|
317
|
+
def decode_and_verify_file(file_params)
|
318
|
+
|
319
|
+
# Verifying the extension of the file
|
320
|
+
extension = ""
|
321
|
+
|
322
|
+
if file_params[:attachment]
|
323
|
+
|
324
|
+
# if attachment is a string, it means that it's a base64 encoded file
|
325
|
+
if file_params[:attachment].is_a? String
|
326
|
+
# Base64 images
|
327
|
+
|
328
|
+
if file_params[:name]
|
329
|
+
file_name = file_params[:name].downcase.gsub(" ","_")
|
330
|
+
elsif @file
|
331
|
+
file_name = @file.name.downcase.gsub(" ","_")
|
332
|
+
else
|
333
|
+
file_name = "file_#{DateTime.now.strftime("%Y%m%d%H%M%S")}"
|
334
|
+
end
|
335
|
+
|
336
|
+
img_from_base64 = Base64.decode64(file_params[:attachment])
|
337
|
+
|
338
|
+
begin
|
339
|
+
extension = /(png|jpg|jpeg|exif|jfif)/.match(img_from_base64[0,16].downcase)[0]
|
340
|
+
rescue
|
341
|
+
return respond_with_error(I18n.t("core.shared.messages_warning_files_extension_not_allowed"))
|
342
|
+
end
|
343
|
+
|
344
|
+
# Due a encode issue, jpeg images are sent as jfif
|
345
|
+
extension = "jpeg" if extension == "jfif"
|
346
|
+
extension = "png" if extension == "exif"
|
347
|
+
|
348
|
+
return respond_with_error(I18n.t("core.shared.messages_warning_files_extension_not_allowed")) unless file_model.verify_file_extension(extension)
|
349
|
+
|
350
|
+
file_path = Rails.root.join("public", "uploads", "tmp", file_name << '.' << extension)
|
351
|
+
File.open(file_path, 'wb') do|f|
|
352
|
+
f.write(img_from_base64)
|
353
|
+
end
|
354
|
+
|
355
|
+
file_params[:attachment] = File.open(Rails.root.join(file_path), "rb")
|
356
|
+
file_params[:size_mb] = file_params[:attachment].size.to_f / (1024*1024)
|
357
|
+
FileUtils.rm_rf(Rails.root.join(file_path))
|
358
|
+
else
|
359
|
+
extension = file_params[:attachment].original_filename
|
360
|
+
file_params[:size_mb] = file_params[:attachment].size.to_f / (1024*1024)
|
361
|
+
|
362
|
+
return respond_with_error(I18n.t("core.shared.messages_warning_files_extension_not_allowed")) unless file_model.verify_file_extension(extension)
|
363
|
+
end
|
364
|
+
|
365
|
+
file_params[:external_url] = nil
|
366
|
+
end
|
367
|
+
|
368
|
+
if block_given?
|
369
|
+
yield(file_params)
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
# @return [void]
|
374
|
+
# @description This function handles the zip download based on the type of attachment that the file has.
|
375
|
+
# If the attachment is local, it means that the file has not yet been uploaded to S3 and will be handled
|
376
|
+
# accordingly
|
377
|
+
# @example
|
378
|
+
# # Executing this controller's action from javascript's frontend
|
379
|
+
# this.http.get('127.0.0.1/house/options/project/1/files/zip&ids=1,2,3,4');
|
380
|
+
def handle_zip_download(files)
|
381
|
+
|
382
|
+
end
|
383
|
+
|
384
|
+
# @return [void]
|
385
|
+
# @descriptions Sets the variable @cloud_object based on the paremeters send in the URL. If no,
|
386
|
+
# cloud_object is found or it is not within the current_user's account, nil is used instead
|
387
|
+
# @example
|
388
|
+
# # Imagine you are inside CloudFocus::Task::FilesController
|
389
|
+
# puts @cloud_object # will display nil
|
390
|
+
# set_cloud_object
|
391
|
+
# puts @cloud_object # Will display an instance of CloudFocus::Task
|
392
|
+
def set_cloud_object
|
393
|
+
file_model = file_model() # If there is a custom file model, it must be returned in this method
|
394
|
+
cloud_object_model = file_model.cloud_object_model
|
395
|
+
account_model = cloud_object_model.reflect_on_association(:account).klass
|
396
|
+
|
397
|
+
@cloud_object = cloud_object_model.find_by(
|
398
|
+
id: params["#{cloud_object_model.name.demodulize.underscore}_id".to_sym],
|
399
|
+
"#{account_model.table_name}_id".to_sym => current_user.account.id
|
400
|
+
)
|
401
|
+
end
|
402
|
+
|
403
|
+
# @return [void]
|
404
|
+
# @description Sets the variable @file. The variable contains the file
|
405
|
+
# to be updated based on the id of the *cloud_object* and the id of the *file*. The variable
|
406
|
+
# will only be available if the file belongs to the current_user's account
|
407
|
+
# @example
|
408
|
+
# #suppose params[:ticket_id] = 1
|
409
|
+
# #suppose params[:id] = 44
|
410
|
+
# puts @file # will display nil
|
411
|
+
# set_file
|
412
|
+
# puts @file # will display an instance of CloudHelp:Ticket::File
|
413
|
+
def set_file
|
414
|
+
set_cloud_object
|
415
|
+
return unless @cloud_object
|
416
|
+
|
417
|
+
@file = @cloud_object.files.find_by(id: params[:id])
|
418
|
+
end
|
419
|
+
|
420
|
+
# @return [Parameters] Allowed parameters for the file
|
421
|
+
# @description Sanitizes the parameters received from an HTTP call to only allow the specified ones.
|
422
|
+
# Allowed params are _:name_, _:file_type_, _:attachment_
|
423
|
+
# @example
|
424
|
+
# # supose params contains {
|
425
|
+
# # "ticket_file": {
|
426
|
+
# # "id": 5,
|
427
|
+
# # "name": "User Contract",
|
428
|
+
# # "file": FILE_CONTENT,
|
429
|
+
# # "ticket_id": 55,
|
430
|
+
# # "word": false
|
431
|
+
# # }
|
432
|
+
# #}
|
433
|
+
# file_params = file_params
|
434
|
+
# puts file_params
|
435
|
+
# # will remove _id_ and _word_ fields and only print {
|
436
|
+
# # "ticket_file": {
|
437
|
+
# # "name": "User Contract",
|
438
|
+
# # "attachment": FILE_CONTENT
|
439
|
+
# # }
|
440
|
+
# #}
|
441
|
+
def file_params
|
442
|
+
file_model = file_model() # If there is a custom file model, it must be returned in this method
|
443
|
+
cloud_object_model = file_model.cloud_object_model
|
444
|
+
|
445
|
+
params.fetch(
|
446
|
+
"#{cloud_object_model.name.demodulize.underscore}_file".to_sym, {}
|
447
|
+
).permit(
|
448
|
+
:name,
|
449
|
+
:attachment,
|
450
|
+
:file_type
|
451
|
+
)
|
452
|
+
end
|
453
|
+
|
454
|
+
# @return [CloudObject::File] The file model that the controller will handle
|
455
|
+
# @descriptions Constantizes and returns the file model associated to this controller. This method
|
456
|
+
# can be overrided by the implementation in the child controller
|
457
|
+
# @example
|
458
|
+
# # Suppose you are inside CloudHelp::Ticket::FilesController
|
459
|
+
# puts file_model().new
|
460
|
+
# # This will display a new instance of CloudHelp::Ticket::File
|
461
|
+
def file_model
|
462
|
+
self.class.name.gsub("Controller","").singularize.constantize
|
463
|
+
end
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
end
|