lesli_security 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +38 -0
  3. data/app/assets/config/lesli_security_manifest.js +38 -0
  4. data/app/assets/images/lesli_security/security-logo.svg +57 -0
  5. data/app/assets/javascripts/lesli_security/application.js +5583 -0
  6. data/app/assets/stylesheets/lesli_security/application.css +95 -0
  7. data/app/controllers/lesli_security/accounts_controller.rb +60 -0
  8. data/app/controllers/lesli_security/application_controller.rb +37 -0
  9. data/app/controllers/lesli_security/dashboard/components_controller.rb +60 -0
  10. data/app/controllers/lesli_security/dashboards_controller.rb +36 -0
  11. data/app/controllers/lesli_security/descriptor/activities_controller.rb +122 -0
  12. data/app/controllers/lesli_security/descriptor/privileges_controller.rb +112 -0
  13. data/app/controllers/lesli_security/descriptors_controller.rb +129 -0
  14. data/app/controllers/lesli_security/role/activities_controller.rb +76 -0
  15. data/app/controllers/lesli_security/role/descriptors_controller.rb +97 -0
  16. data/app/controllers/lesli_security/role/privileges_controller.rb +47 -0
  17. data/app/controllers/lesli_security/roles_controller.rb +185 -0
  18. data/app/controllers/lesli_security/user/roles_controller.rb +98 -0
  19. data/app/controllers/lesli_security/user/sessions_controller.rb +71 -0
  20. data/app/controllers/lesli_security/users_controller.rb +206 -0
  21. data/app/helpers/lesli_security/accounts_helper.rb +4 -0
  22. data/app/helpers/lesli_security/application_helper.rb +4 -0
  23. data/app/helpers/lesli_security/dashboards_helper.rb +4 -0
  24. data/app/helpers/lesli_security/descriptor/activities_helper.rb +4 -0
  25. data/app/helpers/lesli_security/descriptor/privileges_helper.rb +4 -0
  26. data/app/helpers/lesli_security/descriptors_helper.rb +4 -0
  27. data/app/helpers/lesli_security/role/activities_helper.rb +4 -0
  28. data/app/helpers/lesli_security/role/descriptors_helper.rb +4 -0
  29. data/app/helpers/lesli_security/role/privileges_helper.rb +4 -0
  30. data/app/helpers/lesli_security/roles_helper.rb +4 -0
  31. data/app/jobs/lesli_security/application_job.rb +37 -0
  32. data/app/mailers/lesli_security/application_mailer.rb +39 -0
  33. data/app/models/lesli_security/account.rb +43 -0
  34. data/app/models/lesli_security/application_record.rb +37 -0
  35. data/app/models/lesli_security/dashboard/component.rb +42 -0
  36. data/app/models/lesli_security/dashboard.rb +58 -0
  37. data/app/models/lesli_security/descriptor/activity.rb +40 -0
  38. data/app/models/lesli_security/descriptor/privilege.rb +40 -0
  39. data/app/models/lesli_security/descriptor.rb +41 -0
  40. data/app/models/lesli_security/role/activity.rb +40 -0
  41. data/app/services/lesli_security/descriptor_privilege_service.rb +74 -0
  42. data/app/services/lesli_security/descriptor_service.rb +152 -0
  43. data/app/services/lesli_security/role_descriptor_service.rb +61 -0
  44. data/app/services/lesli_security/role_service.rb +215 -0
  45. data/app/services/lesli_security/user_service.rb +305 -0
  46. data/app/views/lesli_security/accounts/_account.html.erb +2 -0
  47. data/app/views/lesli_security/accounts/_form.html.erb +17 -0
  48. data/app/views/lesli_security/accounts/edit.html.erb +10 -0
  49. data/app/views/lesli_security/accounts/index.html.erb +14 -0
  50. data/app/views/lesli_security/accounts/new.html.erb +9 -0
  51. data/app/views/lesli_security/accounts/show.html.erb +10 -0
  52. data/app/views/lesli_security/dashboards/show.html.erb +1 -0
  53. data/app/views/lesli_security/descriptor/activities/_form.html.erb +32 -0
  54. data/app/views/lesli_security/descriptor/activities/edit.html.erb +34 -0
  55. data/app/views/lesli_security/descriptor/activities/index.html.erb +34 -0
  56. data/app/views/lesli_security/descriptor/activities/new.html.erb +34 -0
  57. data/app/views/lesli_security/descriptor/activities/show.html.erb +34 -0
  58. data/app/views/lesli_security/descriptor/privileges/_form.html.erb +32 -0
  59. data/app/views/lesli_security/descriptor/privileges/edit.html.erb +34 -0
  60. data/app/views/lesli_security/descriptor/privileges/index.html.erb +34 -0
  61. data/app/views/lesli_security/descriptor/privileges/new.html.erb +34 -0
  62. data/app/views/lesli_security/descriptor/privileges/show.html.erb +34 -0
  63. data/app/views/lesli_security/descriptors/_form.html.erb +32 -0
  64. data/app/views/lesli_security/descriptors/edit.html.erb +34 -0
  65. data/app/views/lesli_security/descriptors/index.html.erb +34 -0
  66. data/app/views/lesli_security/descriptors/new.html.erb +34 -0
  67. data/app/views/lesli_security/descriptors/show.html.erb +34 -0
  68. data/app/views/lesli_security/partials/_engine-navigation.html.erb +38 -0
  69. data/app/views/lesli_security/role/activities/_form.html.erb +32 -0
  70. data/app/views/lesli_security/role/activities/edit.html.erb +34 -0
  71. data/app/views/lesli_security/role/activities/index.html.erb +34 -0
  72. data/app/views/lesli_security/role/activities/new.html.erb +34 -0
  73. data/app/views/lesli_security/role/activities/show.html.erb +34 -0
  74. data/app/views/lesli_security/role/descriptors/_form.html.erb +32 -0
  75. data/app/views/lesli_security/role/descriptors/edit.html.erb +34 -0
  76. data/app/views/lesli_security/role/descriptors/index.html.erb +34 -0
  77. data/app/views/lesli_security/role/descriptors/new.html.erb +34 -0
  78. data/app/views/lesli_security/role/descriptors/show.html.erb +34 -0
  79. data/app/views/lesli_security/role/privileges/_form.html.erb +32 -0
  80. data/app/views/lesli_security/role/privileges/edit.html.erb +34 -0
  81. data/app/views/lesli_security/role/privileges/index.html.erb +34 -0
  82. data/app/views/lesli_security/role/privileges/new.html.erb +34 -0
  83. data/app/views/lesli_security/role/privileges/show.html.erb +34 -0
  84. data/app/views/lesli_security/roles/edit.html.erb +34 -0
  85. data/app/views/lesli_security/roles/index.html.erb +34 -0
  86. data/app/views/lesli_security/roles/new.html.erb +34 -0
  87. data/app/views/lesli_security/roles/show.html.erb +34 -0
  88. data/app/views/lesli_security/users/edit.html.erb +10 -0
  89. data/app/views/lesli_security/users/index.html.erb +34 -0
  90. data/app/views/lesli_security/users/new.html.erb +34 -0
  91. data/app/views/lesli_security/users/show.html.erb +1 -0
  92. data/config/locales/translations.en.yml +44 -0
  93. data/config/locales/translations.es.yml +44 -0
  94. data/config/locales/translations.fr.yml +44 -0
  95. data/config/locales/translations.it.yml +44 -0
  96. data/config/locales/translations.pt.yml +44 -0
  97. data/config/routes.rb +90 -0
  98. data/db/migrate/v1/0010000210_create_lesli_roles.rb +60 -0
  99. data/db/migrate/v1/0010000310_create_lesli_users.rb +97 -0
  100. data/db/migrate/v1/0010003010_create_lesli_user_details.rb +49 -0
  101. data/db/migrate/v1/0010003110_create_lesli_user_settings.rb +44 -0
  102. data/db/migrate/v1/0010003210_create_lesli_user_sessions.rb +55 -0
  103. data/db/migrate/v1/0010003410_create_lesli_user_powers.rb +43 -0
  104. data/db/migrate/v1/0010004010_create_lesli_user_logs.rb +45 -0
  105. data/db/migrate/v1/0010005010_create_lesli_descriptors.rb +44 -0
  106. data/db/migrate/v1/0010005110_create_lesli_descriptor_privileges.rb +45 -0
  107. data/db/migrate/v1/0010005210_create_lesli_descriptor_activities.rb +49 -0
  108. data/db/migrate/v1/0010005510_create_lesli_role_powers.rb +51 -0
  109. data/db/migrate/v1/0010005710_create_lesli_role_privileges.rb +45 -0
  110. data/db/migrate/v1/0802000110_create_lesli_security_accounts.rb +42 -0
  111. data/db/migrate/v1/0802050110_create_lesli_security_dashboards.rb +51 -0
  112. data/db/migrate/v1/0802050210_create_lesli_security_dashboard_components.rb +53 -0
  113. data/lib/lesli_security/engine.rb +18 -0
  114. data/lib/lesli_security/version.rb +4 -0
  115. data/lib/lesli_security.rb +6 -0
  116. data/lib/scss/application.scss +38 -0
  117. data/lib/scss/users.scss +67 -0
  118. data/lib/tasks/lesli_security_tasks.rake +50 -0
  119. data/lib/vue/application.js +112 -0
  120. data/lib/vue/apps/descriptors/components/form.vue +136 -0
  121. data/lib/vue/apps/descriptors/edit.vue +83 -0
  122. data/lib/vue/apps/descriptors/index.vue +113 -0
  123. data/lib/vue/apps/descriptors/new.vue +69 -0
  124. data/lib/vue/apps/descriptors/show.vue +233 -0
  125. data/lib/vue/apps/roles/components/descriptors.vue +81 -0
  126. data/lib/vue/apps/roles/components/form.vue +253 -0
  127. data/lib/vue/apps/roles/components/privilegeCustom.vue +86 -0
  128. data/lib/vue/apps/roles/components/privilegeStandard.vue +196 -0
  129. data/lib/vue/apps/roles/edit.vue +118 -0
  130. data/lib/vue/apps/roles/index.vue +168 -0
  131. data/lib/vue/apps/roles/logs.vue +110 -0
  132. data/lib/vue/apps/roles/new.vue +86 -0
  133. data/lib/vue/apps/roles/show.vue +109 -0
  134. data/lib/vue/apps/users/components/information-card.vue +104 -0
  135. data/lib/vue/apps/users/components/information-form.vue +176 -0
  136. data/lib/vue/apps/users/components/integrations-information.vue +61 -0
  137. data/lib/vue/apps/users/components/management-roles.vue +107 -0
  138. data/lib/vue/apps/users/components/management-security.vue +113 -0
  139. data/lib/vue/apps/users/components/management-sessions.vue +101 -0
  140. data/lib/vue/apps/users/components/management-settings.vue +93 -0
  141. data/lib/vue/apps/users/index.vue +207 -0
  142. data/lib/vue/apps/users/new.vue +181 -0
  143. data/lib/vue/apps/users/show.vue +131 -0
  144. data/lib/vue/stores/descriptor.js +117 -0
  145. data/lib/vue/stores/descriptors.js +156 -0
  146. data/lib/vue/stores/role.js +203 -0
  147. data/lib/vue/stores/roles.js +58 -0
  148. data/lib/vue/stores/translations.json +277 -0
  149. data/lib/vue/stores/user.js +331 -0
  150. data/lib/vue/stores/users.js +166 -0
  151. data/license +674 -0
  152. data/readme.md +76 -0
  153. metadata +225 -0
@@ -0,0 +1,331 @@
1
+ /*
2
+ Lesli
3
+
4
+ Copyright (c) 2023, Lesli Technologies, S. A.
5
+
6
+ This program is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program. If not, see http://www.gnu.org/licenses/.
18
+
19
+ Lesli · Ruby on Rails SaaS Development Framework.
20
+
21
+ Made with ♥ by https://www.lesli.tech
22
+ Building a better future, one line of code at a time.
23
+
24
+ @contact hello@lesli.tech
25
+ @website https://www.lesli.tech
26
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
27
+
28
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
29
+ // ·
30
+ */
31
+
32
+
33
+ // ·
34
+ import { defineStore } from "pinia"
35
+
36
+
37
+ // ·
38
+ export const useUser = defineStore("lesli.user", {
39
+ state: () => {
40
+ return {
41
+ options: {
42
+ regions: [],
43
+ locales: [],
44
+ salutations: [],
45
+ mfa_methods: []
46
+ },
47
+ user: {
48
+ roles_id: null,
49
+ email: null,
50
+ alias: null,
51
+ first_name: null,
52
+ last_name: null,
53
+ telephone: null,
54
+ detail_attributes: {
55
+ salutation: null,
56
+ title: null,
57
+ }
58
+ },
59
+ roles: [],
60
+ sessions: {
61
+ pagination: {},
62
+ records: []
63
+ },
64
+ options: {
65
+ salutations: [],
66
+ locales: []
67
+ }
68
+ }
69
+ },
70
+ getters: {
71
+ initials() {
72
+ let initials = ""
73
+ if (this.user?.first_name) initials += this.user?.first_name[0];
74
+ if (this.user?.last_name) initials += this.user?.last_name[0];
75
+ return initials.toUpperCase()
76
+ }
77
+ },
78
+ actions: {
79
+
80
+ getOptions() {
81
+ this.http.get(this.url.lesli("users/options")).then(result => {
82
+ this.options = result
83
+ })
84
+ },
85
+
86
+ getUser(id=null) {
87
+
88
+ let url = this.url.security("profile")
89
+
90
+ if (id !== null) {
91
+ url = this.url.security("users/:id", id)
92
+ }
93
+
94
+ // get an specifick user if id is provided
95
+ this.http.get(url).then(result => {
96
+ this.user = result
97
+ this.user.password = ""
98
+ this.user.password_confirmation = ""
99
+
100
+ this.language = result.locale ? result.locale.value : this.language
101
+
102
+ // Backend should return the list of roles ordered by object level permission
103
+ this.role_names = result.roles[0].name
104
+
105
+ }).catch(error => {
106
+ console.log(error)
107
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
108
+ }).finally(() => {
109
+ this.loading = false
110
+ })
111
+ },
112
+
113
+ putUser() {
114
+ this.http.put(this.url.security("users/:id", this.user.id), {
115
+ user: {
116
+ active: this.user.active,
117
+ alias: this.user.alias,
118
+ first_name: this.user.first_name,
119
+ last_name: this.user.last_name,
120
+ telephone: this.user.telephone,
121
+ detail_attributes: {
122
+ title: this.user.detail_attributes.title,
123
+ salutation: this.user.detail_attributes.salutation
124
+ }
125
+ }
126
+ }).then(result => {
127
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
128
+ }).catch(error => {
129
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
130
+ })
131
+ },
132
+
133
+ deleteUser() {
134
+ this.dialog.confirmation({
135
+ title: "Delete user",
136
+ text: "Are you sure you want to delete user?",
137
+ confirmText: "Yes",
138
+ cancelText: "No"
139
+ })
140
+ .then(({ isConfirmed }) => {
141
+ if (isConfirmed) {
142
+ this.http.delete(this.url.lesli("/users/:id", this.user.id)).then(result => {
143
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
144
+ //this.url.go("/administration/users")
145
+ }).catch(error => {
146
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
147
+ })
148
+ }
149
+ })
150
+ },
151
+
152
+ getRoles() {
153
+ this.http.get(this.url.security("users/:id/roles", this.user.id)).then(result => {
154
+ this.roles = result
155
+ }).catch(error => {
156
+ console.log(error)
157
+ })
158
+ },
159
+
160
+ postRole(role) {
161
+ this.http.post(this.url.security('users/:id/roles', this.user.id), {
162
+ user_role: {
163
+ id: role.id
164
+ }
165
+ }).then(result => {
166
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
167
+ }).catch(error => {
168
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
169
+ })
170
+ },
171
+
172
+ deleteRole(role) {
173
+ this.http.delete(this.url.security('users/:user_id/roles/:role_id', {
174
+ user_id: this.user.id,
175
+ role_id: role.id
176
+ })).then(result => {
177
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
178
+ }).catch(error => {
179
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
180
+ })
181
+ },
182
+
183
+ doRequestPassword() {
184
+ this.http.post(this.url.lesli("users/:id/requestpassword", this.user.id)).then(result => {
185
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
186
+ }).catch(error => {
187
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
188
+ })
189
+ },
190
+
191
+ doPasswordReset() {
192
+ this.http.post(this.url.lesli("users/:id/passwordreset", this.user.id)).then(result => {
193
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
194
+ }).catch(error => {
195
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
196
+ })
197
+ },
198
+
199
+ doLogout() {
200
+ this.http.post(this.url.lesli("users/:id/logout", this.user.id)).then(result => {
201
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
202
+ }).catch(error => {
203
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
204
+ })
205
+ },
206
+
207
+ doRevokeAccess() {
208
+ this.http.post(this.url.lesli("users/:id/revokeaccess", this.user.id)).then(result => {
209
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
210
+ }).catch(error => {
211
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
212
+ })
213
+ },
214
+
215
+ fetchSessions() {
216
+ if (!this.sessions.length > 0) {
217
+ this.getSessions()
218
+ }
219
+ },
220
+
221
+ getSessions() {
222
+ this.http.get(this.url.security("users/:id/sessions", this.user.id )).then(result => {
223
+ this.sessions.pagination = result.pagination
224
+ this.sessions.records = result.records
225
+ }).catch(error => {
226
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
227
+ }).finally(() => {
228
+ this.loading = false
229
+ })
230
+ },
231
+
232
+ deleteSession(user_session_id){
233
+ this.dialog.confirmation({
234
+ title: "Close session",
235
+ text: 'Are you sure you want to close this session',
236
+ confirmText: "Yes",
237
+ cancelText: "No"
238
+ })
239
+ .then(({ isConfirmed }) => {
240
+ if (isConfirmed) {
241
+ this.http.delete(this.url.lesli("users/:id/sessions/:session_id", {
242
+ id: this.user.id,
243
+ session_id: user_session_id
244
+ })).then(result => {
245
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
246
+ }).catch(error => {
247
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
248
+ })
249
+ this.fetchSessions()
250
+ }
251
+ })
252
+ },
253
+
254
+ postLanguage() {
255
+ this.http.post(this.url.lesli('users/:id/settings', this.user.id), {
256
+ user_setting: {
257
+ name: 'locale',
258
+ value: this.user.locale.value
259
+ }
260
+ }).then(result => {
261
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
262
+ // TODO: Only if current_user changed his own language
263
+ // reload the page so the user can work with the new language
264
+ // setTimeout(() => window.location.reload(), 1000)
265
+ }).catch(error => {
266
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
267
+ })
268
+ },
269
+
270
+ getOptions() {
271
+ this.http.get(this.url.lesli("users/options")).then(result => {
272
+ this.options.salutations = result.salutations
273
+
274
+ this.options.locales = Object.keys(result.locales).map(key => {
275
+ return {label: result.locales[key], value: key}
276
+ })
277
+ }).catch(error => {
278
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
279
+ })
280
+ },
281
+ }
282
+ })
283
+
284
+
285
+
286
+
287
+ /*
288
+
289
+
290
+
291
+ updatePassword() {
292
+ this.http.put("/", {
293
+ user: {
294
+ password: this.user.password,
295
+ password_confirmation: this.user.password_confirmation
296
+ }
297
+ }).then(result => {
298
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
299
+ this.user.password = ""
300
+ this.user.password_confirmation = ""
301
+ }).catch(error => {
302
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
303
+ })
304
+ },
305
+
306
+ // This action is used to change the user status active or inactive
307
+ putUserStatus(){
308
+ this.dialog.confirmation({
309
+ title: "Change status",
310
+ text: "Are you sure you want to change the status of this user?",
311
+ confirmText: "Yes",
312
+ cancelText: "No"
313
+ })
314
+ .then(({ isConfirmed }) => {
315
+ if (isConfirmed) {
316
+ this.http.patch(this.url.lesli('users/:id', this.user.id), {
317
+ user: {
318
+ active: this.user.active
319
+ }
320
+ }).then(result => {
321
+ this.msg.success(I18n.t("core.users.messages_success_operation"))
322
+ }) .catch(error => {
323
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
324
+ })
325
+ } else {
326
+ this.user.active = !this.user.active
327
+ }
328
+ })
329
+ },
330
+
331
+ */
@@ -0,0 +1,166 @@
1
+ /*
2
+ Lesli
3
+
4
+ Copyright (c) 2023, Lesli Technologies, S. A.
5
+
6
+ This program is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program. If not, see http://www.gnu.org/licenses/.
18
+
19
+ Lesli · Ruby on Rails SaaS Development Framework.
20
+
21
+ Made with ♥ by https://www.lesli.tech
22
+ Building a better future, one line of code at a time.
23
+
24
+ @contact hello@lesli.tech
25
+ @website https://www.lesli.tech
26
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
27
+
28
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
29
+ // ·
30
+ */
31
+
32
+
33
+ // ·
34
+ import { defineStore } from "pinia"
35
+
36
+
37
+ // ·
38
+ export const useUsers = defineStore("guard.users", {
39
+ state: () => {
40
+ return {
41
+ loading: false,
42
+ search: "",
43
+ order: {
44
+ column: "id",
45
+ direction: "desc"
46
+ },
47
+ index: {
48
+ pagination: {},
49
+ records: []
50
+ },
51
+ filters :{
52
+ per_page: 15,
53
+ role: null,
54
+ status: 'active'
55
+ },
56
+ roles_options: [],
57
+
58
+ user: {
59
+ roles_id: null,
60
+ email: null,
61
+ first_name: null,
62
+ last_name: null,
63
+ telephone: null,
64
+ }
65
+ }
66
+ },
67
+ actions: {
68
+
69
+ search(search_string) {
70
+ this.index.pagination.page = 1
71
+ this.search_string = search_string
72
+ this.loading = true
73
+ this.getUsers()
74
+ },
75
+
76
+ paginateIndex(page) {
77
+ this.index.pagination.page = page
78
+ this.getUsers()
79
+ },
80
+
81
+ sortIndex(column, direction) {
82
+ this.order.column = column
83
+ this.order.direction = direction
84
+ this.getUsers()
85
+ },
86
+
87
+ fetchUsers() {
88
+
89
+ if (!this.index.pagination?.results > 0) {
90
+ this.loading = true
91
+ this.getUsers()
92
+ }
93
+
94
+ },
95
+
96
+ getUsers() {
97
+
98
+ const query_filters = {}
99
+
100
+ //Format filters to send them in the query string
101
+ for (const [key, value] of Object.entries(this.filters)) {
102
+ //query_filters[key] = [value]
103
+ }
104
+
105
+ this.http.get(
106
+ this.url
107
+ .security("users")
108
+ .search(this.search_string)
109
+ .paginate(this.index.pagination.page, this.filters.per_page)
110
+ .filter(query_filters)
111
+ .order(this.order.column, this.order.direction)
112
+ ).then(result => {
113
+ this.index = result
114
+ this.search_string=""
115
+ }).catch(error => {
116
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
117
+ }).finally(() => {
118
+ this.loading = false
119
+ })
120
+ },
121
+
122
+ getUser(id=null) {
123
+
124
+ // get the profile by default
125
+ let url = this.url.lesli("profile")
126
+
127
+ // get an specifick user if id is provided
128
+ if (id) { url = this.url.lesli("users/:id", id) }
129
+
130
+ this.http.get(url).then(result => {
131
+ this.user = result
132
+ this.user.password = ""
133
+ this.user.password_confirmation = ""
134
+
135
+ this.language = result.locale ? result.locale.value : this.language
136
+
137
+ // Backend should return the list of roles ordered by object level permission
138
+ this.role_names = result.roles[0].name
139
+
140
+ }).catch(error => {
141
+ this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
142
+ }).finally(() => {
143
+ this.loading = false
144
+ })
145
+ },
146
+
147
+ postUsers() {
148
+ return this.http.post(this.url.admin("users"), {
149
+ user: this.user
150
+ })
151
+ },
152
+
153
+ fetchList() {
154
+ this.loading = true
155
+ return this.http.get(this.url.admin("users/list")).then(response => {
156
+ //this.records = response
157
+ this.list = response
158
+ }).catch(error => {
159
+
160
+ }).finally(() => {
161
+ this.loading = false
162
+ })
163
+ }
164
+
165
+ }
166
+ })