lesli 5.0.1 → 5.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/lesli_manifest.js +7 -4
  3. data/app/assets/fonts/lesli/Domine/Domine-VariableFont_wght.ttf +0 -0
  4. data/app/assets/fonts/lesli/Domine/OFL.txt +2 -0
  5. data/app/assets/javascripts/lesli/users/passwords.js +776 -0
  6. data/app/assets/javascripts/lesli/users/registrations.js +776 -0
  7. data/app/assets/javascripts/lesli/users/sessions.js +776 -1
  8. data/app/assets/stylesheets/lesli/users/passwords.scss +5 -6
  9. data/app/assets/stylesheets/lesli/users/registrations.scss +5 -6
  10. data/app/assets/stylesheets/lesli/users/sessions.scss +5 -10
  11. data/app/controllers/lesli/abouts_controller.rb +66 -0
  12. data/app/controllers/lesli/application_lesli_controller.rb +0 -1
  13. data/app/controllers/lesli/interfaces/application/logger.rb +9 -9
  14. data/app/controllers/lesli/roles_controller.rb +43 -0
  15. data/{lib/sass/lesli/devise/registrations.scss.erb → app/controllers/lesli/users_controller.rb} +18 -23
  16. data/app/controllers/users/registrations_controller.rb +137 -58
  17. data/app/helpers/lesli/assets_helper.rb +2 -2
  18. data/app/helpers/lesli/general_helper.rb +1 -1
  19. data/app/helpers/lesli/navigation_helper.rb +7 -10
  20. data/app/helpers/lesli/system_helper.rb +1 -1
  21. data/app/lib/lesli/system.rb +7 -3
  22. data/app/mailers/lesli/application_lesli_mailer.rb +199 -0
  23. data/app/mailers/lesli/application_mailer.rb +7 -0
  24. data/app/mailers/lesli/devise_mailer.rb +33 -0
  25. data/app/models/concerns/user_guard.rb +3 -4
  26. data/app/models/lesli/account.rb +29 -0
  27. data/{lib/sass/lesli/pages/passes.scss → app/models/lesli/descriptor.rb} +14 -8
  28. data/app/models/lesli/role.rb +90 -0
  29. data/app/models/lesli/system_controller.rb +1 -0
  30. data/app/models/lesli/user/detail.rb +55 -0
  31. data/{lib/sass/lesli/pages/otps.scss → app/models/lesli/user/role.rb} +13 -9
  32. data/app/models/lesli/user.rb +4 -3
  33. data/app/services/lesli/role_service.rb +45 -0
  34. data/app/services/lesli/user_service.rb +69 -0
  35. data/app/views/devise/passwords/new.html.erb +72 -12
  36. data/app/views/devise/registrations/new.html.erb +146 -28
  37. data/app/views/devise/sessions/new.html.erb +11 -78
  38. data/app/views/devise/shared/_links.html.erb +96 -25
  39. data/app/views/lesli/emails/devise_mailer/confirmation_instructions.html.erb +23 -0
  40. data/app/views/lesli/emails/user_mailer/invitation.html.erb +23 -0
  41. data/app/views/lesli/layouts/application-devise.html.erb +1 -1
  42. data/app/views/lesli/layouts/application-public.html.erb +2 -2
  43. data/app/views/lesli/layouts/mailer.html.erb +13 -0
  44. data/app/views/lesli/layouts/mailer.text.erb +1 -0
  45. data/app/views/lesli/partials/_application-lesli-header.html.erb +27 -41
  46. data/app/views/lesli/partials/_application-lesli-javascript.html.erb +10 -6
  47. data/app/views/lesli/partials/_application-public-javascript.html.erb +12 -8
  48. data/{lib/sass/lesli/devise/confirmations.scss.erb → app/views/lesli/wrappers/_application-devise-simple.erb} +30 -46
  49. data/app/views/lesli/wrappers/{_application-auth.html.erb → _application-devise.html.erb} +15 -0
  50. data/config/initializers/{lesli_defaults.rb → lesli.rb} +4 -2
  51. data/config/locales/translations.en.yml +7 -0
  52. data/config/locales/translations.es.yml +7 -0
  53. data/config/routes.rb +24 -17
  54. data/db/migrate/v1.0/0010000210_create_lesli_roles.rb +1 -1
  55. data/db/{tables/0010003010_create_user_details.rb → migrate/v1.0/0010003010_create_lesli_user_details.rb} +6 -6
  56. data/db/{tables/0010003510_create_user_roles.rb → migrate/v1.0/0010003410_create_lesli_user_roles.rb} +4 -4
  57. data/db/{tables/0010005010_create_descriptors.rb → migrate/v1.0/0010005010_create_lesli_descriptors.rb} +5 -6
  58. data/db/{tables/0010005110_create_descriptor_privileges.rb → migrate/v1.0/0010005110_create_lesli_descriptor_privileges.rb} +8 -7
  59. data/db/{tables/0010005210_create_descriptor_activities.rb → migrate/v1.0/0010005210_create_lesli_descriptor_activities.rb} +6 -8
  60. data/db/seeds.rb +0 -2
  61. data/lib/lesli/engine.rb +25 -2
  62. data/lib/lesli/routing.rb +26 -0
  63. data/lib/lesli/version.rb +2 -2
  64. data/lib/lesli.rb +1 -0
  65. data/lib/{sass/lesli/pages/mfas.scss → mailer_previews/devise_mailer_preview.rb} +12 -6
  66. data/lib/sass/lesli/bulma/loader.scss +3 -0
  67. data/lib/sass/lesli/elements/header.scss +1 -1
  68. data/lib/sass/lesli/fonts/families.scss +3 -3
  69. data/lib/sass/lesli/layouts/application-container.scss +4 -0
  70. data/lib/sass/lesli/{devise/passwords.scss.erb → pages/devise-simple.scss} +38 -38
  71. data/lib/sass/lesli/{templates → pages}/devise.scss +4 -26
  72. data/lib/sass/lesli/settings/variables.scss +1 -1
  73. data/lib/sass/lesli/templates/application.scss +8 -4
  74. data/lib/sass/lesli/templates/dashboards.scss +8 -0
  75. data/lib/sass/lesli/templates/public.scss +2 -3
  76. data/lib/tasks/lesli/controllers.rake +33 -0
  77. data/lib/tasks/lesli/db.rake +88 -0
  78. data/lib/tasks/lesli/git.rake +74 -0
  79. data/lib/tasks/lesli_tasks.rake +70 -20
  80. data/lib/vue/devise/registrations.js +10 -15
  81. data/lib/vue/layouts/application-container.vue +10 -2
  82. data/lib/vue/layouts/application-header.vue +10 -3
  83. data/lib/vue/stores/account.js +113 -0
  84. data/lib/vue/stores/role.js +243 -0
  85. data/lib/vue/stores/translations.json +86 -0
  86. data/lib/vue/stores/user.js +102 -0
  87. data/lib/{sass/lesli/devise/sessions.scss → vue/translation.js} +14 -5
  88. data/lib/webpack/base.js +2 -2
  89. data/lib/webpack/core.js +2 -0
  90. data/readme.md +74 -55
  91. data/vendor/bulma/LICENSE +21 -0
  92. data/vendor/bulma/bulma.sass +10 -0
  93. data/vendor/bulma/css/bulma-rtl.css +11851 -0
  94. data/vendor/bulma/css/bulma-rtl.min.css +1 -0
  95. data/vendor/bulma/css/bulma.css +11851 -0
  96. data/vendor/bulma/css/bulma.min.css +1 -0
  97. data/vendor/bulma/sass/base/_all.sass +6 -0
  98. data/vendor/bulma/sass/base/animations.sass +5 -0
  99. data/vendor/bulma/sass/base/generic.sass +145 -0
  100. data/vendor/bulma/sass/base/helpers.sass +1 -0
  101. data/vendor/bulma/sass/base/minireset.sass +79 -0
  102. data/vendor/bulma/sass/components/_all.sass +15 -0
  103. data/vendor/bulma/sass/components/breadcrumb.sass +77 -0
  104. data/vendor/bulma/sass/components/card.sass +103 -0
  105. data/vendor/bulma/sass/components/dropdown.sass +83 -0
  106. data/vendor/bulma/sass/components/level.sass +79 -0
  107. data/vendor/bulma/sass/components/media.sass +59 -0
  108. data/vendor/bulma/sass/components/menu.sass +59 -0
  109. data/vendor/bulma/sass/components/message.sass +101 -0
  110. data/vendor/bulma/sass/components/modal.sass +117 -0
  111. data/vendor/bulma/sass/components/navbar.sass +446 -0
  112. data/vendor/bulma/sass/components/pagination.sass +167 -0
  113. data/vendor/bulma/sass/components/panel.sass +121 -0
  114. data/vendor/bulma/sass/components/tabs.sass +176 -0
  115. data/vendor/bulma/sass/elements/_all.sass +16 -0
  116. data/vendor/bulma/sass/elements/box.sass +26 -0
  117. data/vendor/bulma/sass/elements/button.sass +357 -0
  118. data/vendor/bulma/sass/elements/container.sass +29 -0
  119. data/vendor/bulma/sass/elements/content.sass +162 -0
  120. data/vendor/bulma/sass/elements/form.sass +1 -0
  121. data/vendor/bulma/sass/elements/icon.sass +46 -0
  122. data/vendor/bulma/sass/elements/image.sass +73 -0
  123. data/vendor/bulma/sass/elements/notification.sass +52 -0
  124. data/vendor/bulma/sass/elements/other.sass +31 -0
  125. data/vendor/bulma/sass/elements/progress.sass +73 -0
  126. data/vendor/bulma/sass/elements/table.sass +134 -0
  127. data/vendor/bulma/sass/elements/tag.sass +140 -0
  128. data/vendor/bulma/sass/elements/title.sass +70 -0
  129. data/vendor/bulma/sass/form/_all.sass +9 -0
  130. data/vendor/bulma/sass/form/checkbox-radio.sass +22 -0
  131. data/vendor/bulma/sass/form/file.sass +184 -0
  132. data/vendor/bulma/sass/form/input-textarea.sass +66 -0
  133. data/vendor/bulma/sass/form/select.sass +88 -0
  134. data/vendor/bulma/sass/form/shared.sass +60 -0
  135. data/vendor/bulma/sass/form/tools.sass +215 -0
  136. data/vendor/bulma/sass/grid/_all.sass +5 -0
  137. data/vendor/bulma/sass/grid/columns.sass +513 -0
  138. data/vendor/bulma/sass/grid/tiles.sass +36 -0
  139. data/vendor/bulma/sass/helpers/_all.sass +12 -0
  140. data/vendor/bulma/sass/helpers/color.sass +39 -0
  141. data/vendor/bulma/sass/helpers/flexbox.sass +35 -0
  142. data/vendor/bulma/sass/helpers/float.sass +10 -0
  143. data/vendor/bulma/sass/helpers/other.sass +14 -0
  144. data/vendor/bulma/sass/helpers/overflow.sass +2 -0
  145. data/vendor/bulma/sass/helpers/position.sass +7 -0
  146. data/vendor/bulma/sass/helpers/spacing.sass +31 -0
  147. data/vendor/bulma/sass/helpers/typography.sass +103 -0
  148. data/vendor/bulma/sass/helpers/visibility.sass +122 -0
  149. data/vendor/bulma/sass/layout/_all.sass +6 -0
  150. data/vendor/bulma/sass/layout/footer.sass +11 -0
  151. data/vendor/bulma/sass/layout/hero.sass +153 -0
  152. data/vendor/bulma/sass/layout/section.sass +17 -0
  153. data/vendor/bulma/sass/utilities/_all.sass +9 -0
  154. data/vendor/bulma/sass/utilities/animations.sass +1 -0
  155. data/vendor/bulma/sass/utilities/controls.sass +49 -0
  156. data/vendor/bulma/sass/utilities/derived-variables.sass +114 -0
  157. data/vendor/bulma/sass/utilities/extends.sass +25 -0
  158. data/vendor/bulma/sass/utilities/functions.sass +135 -0
  159. data/vendor/bulma/sass/utilities/initial-variables.sass +79 -0
  160. data/vendor/bulma/sass/utilities/mixins.sass +303 -0
  161. data/vendor/lesli-css/_index.scss +34 -0
  162. data/vendor/lesli-css/lesli.scss +51 -0
  163. data/{app/assets/stylesheets/lesli/users/devise.scss → vendor/lesli-css/license} +7 -11
  164. data/vendor/lesli-css/src/base/fonts.scss +50 -0
  165. data/vendor/lesli-css/src/base/normalize.scss +118 -0
  166. data/vendor/lesli-css/src/components/blockquote.scss +61 -0
  167. data/vendor/lesli-css/src/components/columns.scss +92 -0
  168. data/vendor/lesli-css/src/components/container.scss +47 -0
  169. data/vendor/lesli-css/src/components/grid.scss +0 -0
  170. data/vendor/lesli-css/src/components/navigation.scss +59 -0
  171. data/vendor/lesli-css/src/functions/colors.scss +184 -0
  172. data/vendor/lesli-css/src/helpers/units.scss +44 -0
  173. data/vendor/lesli-css/src/mixins/breakpoint.scss +184 -0
  174. data/vendor/lesli-css/src/mixins/flex.scss +80 -0
  175. data/vendor/lesli-css/src/mixins/scrollbar.scss +46 -0
  176. data/vendor/lesli-css/src/settings/variables.scss +26 -0
  177. data/vendor/lesli-css/tests/base/normalize.spec.scss +125 -0
  178. data/vendor/lesli-css/tests/functions/colors.spec.scss +117 -0
  179. data/vendor/lesli-css/tests/mixins/breakpoint.spec.scss +429 -0
  180. data/vendor/lesli-css/tests/mixins/scrollbar.spec.scss +82 -0
  181. data/vendor/lesli-css/vendor/normalize.scss +351 -0
  182. data/vendor/remixicon/License +201 -0
  183. data/vendor/remixicon/fonts/remixicon.css +2583 -0
  184. metadata +290 -51
  185. data/app/assets/fonts/lesli/Domine/Domine-Bold.ttf +0 -0
  186. data/app/assets/fonts/lesli/Domine/Domine-Regular.ttf +0 -0
  187. data/app/controllers/lesli/profiles_controller.rb +0 -60
  188. data/app/helpers/lesli/profiles_helper.rb +0 -4
  189. data/app/models/lesli/profile.rb +0 -4
  190. data/app/views/lesli/devise/sessions/_form.html.erb +0 -17
  191. data/app/views/lesli/devise/sessions/_session.html.erb +0 -2
  192. data/app/views/lesli/devise/sessions/edit.html.erb +0 -10
  193. data/app/views/lesli/devise/sessions/index.html.erb +0 -14
  194. data/app/views/lesli/devise/sessions/new.html.erb +0 -9
  195. data/app/views/lesli/devise/sessions/show.html.erb +0 -10
  196. data/app/views/lesli/profiles/_form.html.erb +0 -17
  197. data/app/views/lesli/profiles/_profile.html.erb +0 -2
  198. data/app/views/lesli/profiles/edit.html.erb +0 -10
  199. data/app/views/lesli/profiles/index.html.erb +0 -14
  200. data/app/views/lesli/profiles/new.html.erb +0 -9
  201. data/app/views/lesli/profiles/show.html.erb +0 -10
  202. data/lib/sass/lesli/pages/dashboards.scss +0 -57
  203. data/lib/tasks/db.rb +0 -76
  204. data/lib/vue/stores/profile.js +0 -90
  205. data/lib/vue/stores/workflow2.js +0 -345
  206. data/lib/vue/stores/workflows/actions.js +0 -327
  207. data/lib/vue/stores/workflows/associations.js +0 -130
  208. data/lib/vue/stores/workflows/checks.js +0 -210
  209. /data/lib/vue/stores/{announcements.js → entities/announcements.js} +0 -0
  210. /data/lib/vue/stores/{dashboard.js → entities/dashboard.js} +0 -0
  211. /data/lib/vue/stores/{workflow.js → entities/workflow.js} +0 -0
  212. /data/lib/vue/stores/{cloud-bell → panels}/notification.js +0 -0
  213. /data/lib/vue/stores/{firebase.js → services/firebase.js} +0 -0
@@ -0,0 +1,199 @@
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 · Ruby on Rails SaaS Development Framework.
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://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module Lesli
34
+ class ApplicationLesliMailer < ActionMailer::Base
35
+
36
+ # Set a dynamic template according to the engine that is sending the email
37
+ # this is equivalent to: default template_path: -> { "engine_name/emails" }
38
+ =begin
39
+ default(
40
+
41
+ from: -> {
42
+
43
+ instance = Rails.application.config.lesli.dig(:instance)
44
+
45
+ # add custom email name for emails sent from www.lesli.cloud
46
+ if instance[:code] == 'lesli_cloud'
47
+ return email_address_with_name(
48
+ Rails.configuration.lesli.dig(:env, :action_mailer, :default_options_from),
49
+ "Lesli"
50
+ )
51
+ end
52
+
53
+ Rails.configuration.lesli.dig(:env, :action_mailer, :default_options_from)
54
+
55
+ },
56
+
57
+ template_path: -> {
58
+
59
+ instance = Rails.application.config.lesli.dig(:instance)
60
+
61
+ # get class that is executing the mailer
62
+ module_info = self.class.name.split("::")
63
+
64
+ # mailers from engines
65
+ if module_info.length > 1
66
+ return "#{ instance[:code] }/emails/#{(module_info[0].underscore)}/#{ module_info[1].underscore }"
67
+ end
68
+
69
+ # mailers from core
70
+ return "#{ instance[:code] }/emails/#{ module_info[0].underscore }"
71
+
72
+ }
73
+
74
+ )
75
+ =end
76
+ #after_action :log_mail_requests
77
+
78
+ default(template_path: "lesli/emails/devise_mailer")
79
+
80
+ def initialize
81
+
82
+ super
83
+
84
+ # some @email data is defined on: LesliMails/src/partials/data.html
85
+ @custom = {}
86
+ @email = {}
87
+ @data = {}
88
+ @app = {}
89
+
90
+ end
91
+
92
+ protected
93
+
94
+ def email(data={}, to:, subject:, template_name:)
95
+
96
+ @app[:host] = default_url_options[:host]
97
+ @data = @data.merge(data)
98
+
99
+ mail(
100
+ to: to,
101
+ subject: subject,
102
+ template_name: template_name
103
+ )
104
+ end
105
+
106
+
107
+ private
108
+
109
+
110
+ def build_data_from_params(params, data={})
111
+
112
+ # make custom data available in mailer method and mailer template
113
+ @data = @data.merge(data)
114
+
115
+ build_app_from_params(params)
116
+
117
+ build_customization_from_params(params)
118
+
119
+ end
120
+
121
+ def build_app_from_params(params)
122
+
123
+ @app[:host] = default_url_options[:host]
124
+ # @app[:company] = {
125
+ # id: 0,
126
+ # name: "",
127
+ # tag_line: "",
128
+ # }
129
+
130
+ # return if params[:user].blank? || params[:user].class.name != "User"
131
+
132
+ # @app[:company] = {
133
+ # id: params[:user].account.id,
134
+ # name: params[:user].account.company_name,
135
+ # tag_line: params[:user].account.company_tag_line,
136
+ # }
137
+
138
+ end
139
+
140
+ def build_customization_from_params(params)
141
+
142
+ instance = Rails.application.config.lesli.dig(:instance)
143
+
144
+ # lesli is the code used for the core. If there are no builder engines,
145
+ # the instance namespace is "/"
146
+ instance_path = ""
147
+ instance_path = "#{instance[:code]}/" if instance[:code] != "lesli"
148
+
149
+ # using cdn logos by default (testing feature)
150
+ # @custom[:logo] = "#{instance_path}brand/app-logo.svg"
151
+ @custom[:logo] = "https://cdn.lesli.tech/leslicloud/brand/app-logo.png"
152
+
153
+ return if params[:user].blank? || params[:user].class.name != "User"
154
+
155
+ custom_logo = nil # params[:user].account.files.where(file_type: "app_logo").last
156
+
157
+ if custom_logo
158
+ @custom[:logo] = custom_logo.attachment.url if custom_logo.attachment_identifier
159
+ @custom[:logo] = custom_logo.attachment_public.url if custom_logo.attachment_public_identifier
160
+ end
161
+
162
+ end
163
+
164
+ def build_recipients_from_users(users)
165
+ if users.is_a?(Array)
166
+ users.map { |user| email_address_with_name(user.email, user.full_name) }
167
+ end
168
+ end
169
+
170
+ def build_recipients_from_contacts(contacts)
171
+ if contacts.is_a?(Array)
172
+ contacts.map { |contact| email_address_with_name(contact[:email], contact[:name]) }
173
+ end
174
+ end
175
+
176
+ def build_recipients_from_emails()
177
+ end
178
+
179
+ def log_mail_requests title="email_sent", payload=nil
180
+
181
+ if payload.blank?
182
+ payload = {
183
+ subject: self.message.subject,
184
+ to: self.message.to
185
+ }
186
+ end
187
+
188
+ # TODO: Save template path and view used within the email
189
+ Account::Log.log_email(
190
+ "#{self.class.to_s}/#{self.action_name}",
191
+ self.action_name,
192
+ title,
193
+ payload
194
+ )
195
+
196
+ end
197
+
198
+ end
199
+ end
@@ -0,0 +1,7 @@
1
+ module Lesli
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "hello@lesli.tech"
4
+ layout "lesli/layouts/mailer"
5
+ end
6
+ end
7
+
@@ -0,0 +1,33 @@
1
+ module Lesli
2
+ class DeviseMailer < ApplicationLesliMailer
3
+ def confirmation_instructions(record, token, opts = {})
4
+
5
+ # defaults for new accounts/users
6
+ email_template = "confirmation_instructions"
7
+ email_subject = I18n.t("core.users/confirmations.mailer_email_verification")
8
+
9
+ # # custom email and subject if user is changin his email address
10
+ # if !record.unconfirmed_email.blank?
11
+ # email_template = "update_email_confirmation_instructions"
12
+ # email_subject = I18n.t("core.users/confirmations.mailer_confirmation_instructions_subject")
13
+ # end
14
+
15
+ # Depending on wheter there is a new user or they are changing their email,
16
+ # one or another field will be used
17
+ email_recipient = record.unconfirmed_email || record.email
18
+
19
+ # email custom data
20
+ params = {
21
+ url: "/confirmation?confirmation_token=#{token}"
22
+ }
23
+
24
+ # send email
25
+ email(
26
+ params,
27
+ to: email_recipient,
28
+ subject: email_subject,
29
+ template_name: email_template
30
+ )
31
+ end
32
+ end
33
+ end
@@ -17,7 +17,7 @@ GNU General Public License for more details.
17
17
  You should have received a copy of the GNU General Public License
18
18
  along with this program. If not, see http://www.gnu.org/licenses/.
19
19
 
20
- Lesli · Ruby on Rails Development Platform.
20
+ Lesli · Ruby on Rails SaaS Development Framework.
21
21
 
22
22
  Made with ♥ by https://www.lesli.tech
23
23
  Building a better future, one line of code at a time.
@@ -28,7 +28,6 @@ Building a better future, one line of code at a time.
28
28
 
29
29
  // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
30
  // ·
31
-
32
31
  =end
33
32
 
34
33
 
@@ -41,12 +40,12 @@ module UserGuard
41
40
  def max_object_level_permission
42
41
 
43
42
  # get the max object level permission from roles assigned to the user
44
- level = self.roles.map(&:object_level_permission).max()
43
+ level = self.roles.maximum(:object_level_permission)
45
44
 
46
45
  # if user has no roles assigned, we return the lowest role available
47
46
  # NOTE: This should not be possible due the user needs a role to login
48
47
  unless level
49
- return (self.account.roles.map(&:object_level_permission).min() + 1)
48
+ return (self.account.roles.minimum(:object_level_permission))
50
49
  end
51
50
 
52
51
  # return the level found
@@ -73,5 +73,34 @@ module Lesli
73
73
 
74
74
  # required a name for the lesli account
75
75
  validates :company_name, :presence => true
76
+
77
+
78
+ # initializers for new accounts
79
+ after_create :initialize_account
80
+
81
+
82
+ def initialize_account
83
+
84
+ # create initial descriptors
85
+ descriptor_owner = self.descriptors.find_or_create_by(name: "owner")
86
+ descriptor_sysadmin = self.descriptors.find_or_create_by(name: "sysadmin")
87
+ descriptor_profile = self.descriptors.find_or_create_by(name: "profile")
88
+
89
+
90
+ # create default roles for the new account
91
+ owner = self.roles.create({ name: "owner", active: true, object_level_permission: 2147483647 })
92
+
93
+ # platform administrator role
94
+ sysadmin = self.roles.create({ name: "sysadmin", active: true, object_level_permission: 100000 })
95
+
96
+ # access only to user profile
97
+ limited = self.roles.create({ name: "limited", active: true, object_level_permission: 10, path_default: "/administration/profile" })
98
+
99
+
100
+ # assign descriptors with appropriate privileges
101
+ #owner.descriptors.create(:descriptor => descriptor_owner)
102
+ #sysadmin.descriptors.create(:descriptor => descriptor_sysadmin)
103
+ #limited.descriptors.create(:descriptor => descriptor_profile)
104
+ end
76
105
  end
77
106
  end
@@ -1,4 +1,4 @@
1
- /*
1
+ =begin
2
2
 
3
3
  Lesli
4
4
 
@@ -17,7 +17,7 @@ GNU General Public License for more details.
17
17
  You should have received a copy of the GNU General Public License
18
18
  along with this program. If not, see http://www.gnu.org/licenses/.
19
19
 
20
- Lesli · Ruby on Rails SaaS development platform.
20
+ Lesli · Ruby on Rails SaaS Development Framework.
21
21
 
22
22
  Made with ♥ by https://www.lesli.tech
23
23
  Building a better future, one line of code at a time.
@@ -27,9 +27,15 @@ Building a better future, one line of code at a time.
27
27
  @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
28
 
29
29
  // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
- // ·
31
-
32
- */
33
-
34
- // ·
35
- @import "./base.scss";
30
+ // ·
31
+ =end
32
+
33
+ module Lesli
34
+ class Descriptor < ApplicationLesliRecord
35
+ belongs_to :account
36
+ #has_many :privileges
37
+ #has_many :role_descriptors
38
+
39
+ validates :name, presence: true
40
+ end
41
+ end
@@ -0,0 +1,90 @@
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 · Ruby on Rails SaaS Development Framework.
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://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module Lesli
34
+ class Role < ApplicationLesliRecord
35
+
36
+ belongs_to :account
37
+
38
+
39
+ # Role resources
40
+ has_many :activities
41
+ has_many :descriptors, dependent: :delete_all
42
+ has_many :privileges, class_name: "Role::Privilege", dependent: :delete_all
43
+
44
+
45
+ # initializers for new roles
46
+ after_create :after_create_role
47
+
48
+
49
+ # validations
50
+ validates :name, presence: :true
51
+ validates :object_level_permission, presence: :true
52
+
53
+
54
+ def after_create_role
55
+
56
+ # generate a unique code for the role
57
+ role_code = name
58
+ .downcase # string to lowercase
59
+ .gsub(/[^0-9A-Za-z\s\-\_]/, '') # remove special characters from string
60
+ .gsub(/-/, '_') # replace dashes with underscore
61
+ .gsub(/\s+/, '_') # replace spaces or spaces with single dash
62
+
63
+ # transform UTF-8 characters to ASCI (ex: name in german)
64
+ role_code = I18n.transliterate(role_code) + id.to_s
65
+
66
+ self.update_attribute("code", role_code)
67
+ end
68
+
69
+
70
+ # @return [Boolean]
71
+ # @description Returns if a role is assigned to users.
72
+ def has_users?
73
+ User::Role.where(role: self).count > 0
74
+ end
75
+
76
+ # @return [void]
77
+ # @param current_user [::User] The user that deleted the role
78
+ # @param [Role] The role that was deleted
79
+ # @description Creates an activity for this role indicating that someone deleted it
80
+ # Example
81
+ # role = Role.find(1)
82
+ # Role.log_activity_destroy(User.find(1), role)
83
+ def self.log_activity_destroy(current_user, role)
84
+ role.activities.create(
85
+ user_creator: current_user,
86
+ category: "action_destroy"
87
+ )
88
+ end
89
+ end
90
+ end
@@ -39,6 +39,7 @@ module Lesli
39
39
  # get a matrix of controllers and actions
40
40
  c = SystemController.joins(:actions).select(
41
41
  "lesli_system_controllers.engine as engine",
42
+ "lesli_system_controllers.route as route",
42
43
  "lesli_system_controllers.reference as controller",
43
44
  "lesli_system_controllers.name as controller_name",
44
45
  "lesli_system_controllers.id as controller_id",
@@ -0,0 +1,55 @@
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 · Ruby on Rails SaaS Development Framework.
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://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module Lesli
34
+ class User::Detail < ApplicationLesliRecord
35
+ belongs_to :user
36
+
37
+ #before_save :validate_work_region
38
+
39
+ enum salutation: {
40
+ mr: "mr",
41
+ ms: "ms",
42
+ mrs: "mrs"
43
+ }
44
+
45
+ protected
46
+
47
+ def validate_work_region
48
+ return true unless work_region
49
+ return true if Account::Location.find_by_id(work_region)
50
+
51
+ errors.add(:base, :work_region_invalid)
52
+ throw :abort
53
+ end
54
+ end
55
+ end
@@ -1,4 +1,4 @@
1
- /*
1
+ =begin
2
2
 
3
3
  Lesli
4
4
 
@@ -17,7 +17,7 @@ GNU General Public License for more details.
17
17
  You should have received a copy of the GNU General Public License
18
18
  along with this program. If not, see http://www.gnu.org/licenses/.
19
19
 
20
- Lesli · Ruby on Rails SaaS development platform.
20
+ Lesli · Ruby on Rails SaaS Development Framework.
21
21
 
22
22
  Made with ♥ by https://www.lesli.tech
23
23
  Building a better future, one line of code at a time.
@@ -27,10 +27,14 @@ Building a better future, one line of code at a time.
27
27
  @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
28
 
29
29
  // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
- // ·
31
-
32
- */
33
-
34
-
35
- // ·
36
- @import "./base.scss";
30
+ // ·
31
+ =end
32
+
33
+ module Lesli
34
+ class User::Role < ApplicationLesliRecord
35
+ belongs_to :user
36
+ belongs_to :role
37
+ has_many :roles
38
+ #has_many :privileges, through: :roles
39
+ end
40
+ end
@@ -57,9 +57,10 @@ module Lesli
57
57
  has_many :activities, class_name: "User::Activity"
58
58
 
59
59
  # users can have many roles and too many privileges through the roles
60
- has_many :user_roles, class_name: "User::Role"
61
- has_many :roles, through: :user_roles, source: :role
62
- has_many :privileges, through: :roles
60
+ has_many :user_roles, class_name: "Lesli::User::Role"
61
+ has_many :roles, class_name: "Lesli::Role", through: :user_roles, source: :role
62
+ #has_many :privileges, through: :roles
63
+
63
64
 
64
65
  # devise implementation
65
66
  devise :database_authenticatable,
@@ -0,0 +1,45 @@
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 · Ruby on Rails SaaS Development Framework.
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://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module Lesli
34
+ class RoleService < ApplicationLesliService
35
+
36
+ # Return a list of roles that the user is able to work with
37
+ # according to object level permission
38
+ def list params
39
+ current_user.account.roles
40
+ .where("object_level_permission <= ?", current_user.max_object_level_permission)
41
+ .order(object_level_permission: :desc, name: :asc)
42
+ .select(:id, :name, :object_level_permission)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,69 @@
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 · Ruby on Rails SaaS Development Framework.
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://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module Lesli
34
+ class UserService < Lesli::ApplicationLesliService
35
+
36
+
37
+ # Return a list of users that belongs to the account of the current_user
38
+ # this list is meant to be used in selectors, autocomplets, etc
39
+ def list params=nil
40
+ #users = current_user.account.users
41
+ users = Lesli::Account.first.users
42
+
43
+ if params[:role].present?
44
+ # add simple quotes to the roles so the sql can manage the query
45
+ roles = params[:role].split(",").map { |role| "'#{role}'" }.join(", ")
46
+ users = users.joins("
47
+ inner join (
48
+ select
49
+ ur.users_id, string_agg(r.\"name\", ', ') role_names
50
+ from user_roles ur
51
+ join roles r
52
+ on r.id = ur.role_id
53
+ and r.name in ( #{ roles } )
54
+ where ur.deleted_at is null
55
+ group by ur.users_id
56
+ ) roles on roles.users_id = users.id
57
+ ")
58
+ end
59
+
60
+ users.order(name: :asc).select(
61
+ :id,
62
+ :email,
63
+ "CONCAT_WS(' ', first_name, last_name) as name",
64
+ :alias
65
+ ).as_json
66
+ end
67
+
68
+ end
69
+ end