lesli 5.0.19 → 5.0.21
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.
- checksums.yaml +4 -4
- data/app/assets/images/lesli/brand/register-background.jpg +0 -0
- data/app/assets/stylesheets/lesli/application.css +1 -0
- data/app/helpers/lesli/navigation_helper.rb +6 -0
- data/app/interfaces/lesli/responder_interface.rb +35 -19
- data/app/models/concerns/lesli/account_initializer.rb +79 -0
- data/app/models/concerns/lesli/user_extensions.rb +133 -0
- data/app/models/concerns/lesli/user_security.rb +220 -0
- data/app/models/lesli/role/action.rb +3 -2
- data/app/models/lesli/shared/dashboard.rb +2 -2
- data/app/models/lesli/user/session.rb +1 -1
- data/app/models/lesli/user.rb +15 -15
- data/app/operators/lesli/role_operator.rb +9 -4
- data/app/services/lesli/role/action_service.rb +2 -3
- data/app/services/lesli/role_service.rb +3 -3
- data/app/views/lesli/abouts/welcome.html.erb +8 -5
- data/app/views/lesli/apps/show.html.erb +21 -33
- data/app/views/lesli/errors/not_found.html.erb +32 -0
- data/app/views/lesli/errors/unauthorized.html.erb +48 -0
- data/app/views/lesli/layouts/application-devise.html.erb +2 -2
- data/app/views/lesli/layouts/application-lesli.html.erb +1 -2
- data/app/views/lesli/partials/_application-analytics.html.erb +2 -2
- data/app/views/lesli/partials/_application-data.html.erb +0 -1
- data/app/views/lesli/partials/_application-head.html.erb +4 -4
- data/app/views/lesli/partials/_application-lesli-header.html.erb +47 -67
- data/app/views/lesli/partials/_application-lesli-navigation.html.erb +23 -5
- data/config/importmap.rb +0 -10
- data/config/initializers/devise_rails_8_patch.rb +8 -0
- data/config/initializers/lesli.rb +27 -23
- data/db/migrate/v1/0000120310_create_lesli_role_privileges.rb +2 -2
- data/db/seed/accounts.rb +1 -1
- data/db/seed/users.rb +6 -4
- data/db/seeds.rb +6 -6
- data/lib/lesli/engine.rb +0 -14
- data/lib/lesli/routing.rb +1 -1
- data/lib/lesli/version.rb +2 -2
- data/lib/rspec/testers/request.rb +15 -6
- data/lib/scss/_apps.scss +93 -0
- data/lib/scss/application.scss +34 -0
- data/lib/tasks/lesli/controllers.rake +1 -1
- data/lib/tasks/lesli/db.rake +27 -27
- data/lib/tasks/lesli_tasks.rake +3 -0
- data/readme.md +9 -10
- metadata +33 -13
- data/app/models/concerns/account_initializer.rb +0 -83
- data/app/models/concerns/user_extensions.rb +0 -152
- data/app/models/concerns/user_security.rb +0 -276
- data/app/operators/lesli/user_registration_operator.rb +0 -122
- /data/app/models/concerns/{user_activities.rb → lesli/user_activities.rb} +0 -0
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lesli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Lesli Development Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '8.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '8.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: i18n-js
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -28,16 +42,16 @@ dependencies:
|
|
28
42
|
name: importmap-rails
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 2.2.0
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 2.2.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: turbo-rails
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,7 +178,8 @@ dependencies:
|
|
164
178
|
- - "~>"
|
165
179
|
- !ruby/object:Gem::Version
|
166
180
|
version: '0.6'
|
167
|
-
description:
|
181
|
+
description: Lesli is a SaaS development framework designed to build highly scalable,
|
182
|
+
secure and customizable software products.
|
168
183
|
email:
|
169
184
|
- hello@lesli.tech
|
170
185
|
executables: []
|
@@ -180,6 +195,7 @@ files:
|
|
180
195
|
- app/assets/images/lesli/brand/favicon.png
|
181
196
|
- app/assets/images/lesli/brand/favicon.svg
|
182
197
|
- app/assets/images/lesli/brand/login-background.jpg
|
198
|
+
- app/assets/images/lesli/brand/register-background.jpg
|
183
199
|
- app/assets/images/lesli/lesli-logo.svg
|
184
200
|
- app/assets/javascripts/lesli/application.js
|
185
201
|
- app/assets/stylesheets/lesli/application.css
|
@@ -207,11 +223,11 @@ files:
|
|
207
223
|
- app/mailers/lesli/application_lesli_mailer.rb
|
208
224
|
- app/mailers/lesli/application_mailer.rb
|
209
225
|
- app/mailers/lesli/devise_mailer.rb
|
210
|
-
- app/models/concerns/account_initializer.rb
|
226
|
+
- app/models/concerns/lesli/account_initializer.rb
|
211
227
|
- app/models/concerns/lesli/has_activities.rb
|
212
|
-
- app/models/concerns/user_activities.rb
|
213
|
-
- app/models/concerns/user_extensions.rb
|
214
|
-
- app/models/concerns/user_security.rb
|
228
|
+
- app/models/concerns/lesli/user_activities.rb
|
229
|
+
- app/models/concerns/lesli/user_extensions.rb
|
230
|
+
- app/models/concerns/lesli/user_security.rb
|
215
231
|
- app/models/lesli/account.rb
|
216
232
|
- app/models/lesli/account/detail.rb
|
217
233
|
- app/models/lesli/account/log.rb
|
@@ -237,7 +253,6 @@ files:
|
|
237
253
|
- app/models/lesli/user/setting.rb
|
238
254
|
- app/operators/lesli/controller_operator.rb
|
239
255
|
- app/operators/lesli/role_operator.rb
|
240
|
-
- app/operators/lesli/user_registration_operator.rb
|
241
256
|
- app/services/lesli/application_lesli_service.rb
|
242
257
|
- app/services/lesli/role/action_service.rb
|
243
258
|
- app/services/lesli/role_service.rb
|
@@ -248,6 +263,8 @@ files:
|
|
248
263
|
- app/views/lesli/abouts/welcome.html.erb
|
249
264
|
- app/views/lesli/apps/show.html.erb
|
250
265
|
- app/views/lesli/emails/user_mailer/invitation.html.erb
|
266
|
+
- app/views/lesli/errors/not_found.html.erb
|
267
|
+
- app/views/lesli/errors/unauthorized.html.erb
|
251
268
|
- app/views/lesli/layouts/application-devise.html.erb
|
252
269
|
- app/views/lesli/layouts/application-lesli.html.erb
|
253
270
|
- app/views/lesli/layouts/application-public.html.erb
|
@@ -276,6 +293,7 @@ files:
|
|
276
293
|
- app/views/lesli/wrappers/_application-devise.html.erb
|
277
294
|
- config/importmap.rb
|
278
295
|
- config/initializers/devise.rb
|
296
|
+
- config/initializers/devise_rails_8_patch.rb
|
279
297
|
- config/initializers/lesli.rb
|
280
298
|
- config/initializers/lesli_migration_helpers.rb
|
281
299
|
- config/locales/devise.en.yml
|
@@ -362,6 +380,8 @@ files:
|
|
362
380
|
- lib/rspec/testers/controller.rb
|
363
381
|
- lib/rspec/testers/model.rb
|
364
382
|
- lib/rspec/testers/request.rb
|
383
|
+
- lib/scss/_apps.scss
|
384
|
+
- lib/scss/application.scss
|
365
385
|
- lib/tasks/lesli/controllers.rake
|
366
386
|
- lib/tasks/lesli/db.rake
|
367
387
|
- lib/tasks/lesli/dev.rake
|
@@ -389,7 +409,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
389
409
|
requirements:
|
390
410
|
- - ">="
|
391
411
|
- !ruby/object:Gem::Version
|
392
|
-
version: '2
|
412
|
+
version: '3.2'
|
393
413
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
394
414
|
requirements:
|
395
415
|
- - ">="
|
@@ -1,83 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
|
3
|
-
Lesli
|
4
|
-
|
5
|
-
Copyright (c) 2025, 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 LesliTech
|
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 AccountInitializer
|
34
|
-
extend ActiveSupport::Concern
|
35
|
-
|
36
|
-
# initialize minimum resources needed for the account
|
37
|
-
def initialize_account
|
38
|
-
|
39
|
-
|
40
|
-
# create default roles for the new account
|
41
|
-
owner = self.roles
|
42
|
-
.create_with({ permission_level: 2147483647 })
|
43
|
-
.find_or_create_by(:name => "owner")
|
44
|
-
|
45
|
-
|
46
|
-
# platform administrator role
|
47
|
-
admin = self.roles
|
48
|
-
.create_with({ permission_level: 100000})
|
49
|
-
.find_or_create_by(name: "admin")
|
50
|
-
|
51
|
-
|
52
|
-
# access only to user profile
|
53
|
-
limited = self.roles
|
54
|
-
.create_with({ permission_level: 10, path_default: "/administration/profile" })
|
55
|
-
.find_or_create_by(name: "limited")
|
56
|
-
|
57
|
-
|
58
|
-
# Add base privileges to roles
|
59
|
-
Lesli::RoleOperator.new(owner).add_owner_actions
|
60
|
-
Lesli::RoleOperator.new(admin).add_owner_actions
|
61
|
-
Lesli::RoleOperator.new(limited).add_profile_privileges
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
# initialize engines for new accounts
|
68
|
-
def initialize_engines
|
69
|
-
|
70
|
-
LesliSystem.engines.each do |engine, data|
|
71
|
-
|
72
|
-
next if ["Lesli", "LesliBabel", "LesliShield", "Root"].include?(engine)
|
73
|
-
|
74
|
-
# Skip if the engine is not defined
|
75
|
-
next unless Object.const_defined?(engine)
|
76
|
-
|
77
|
-
#next if self.public_send(attribute).blank?
|
78
|
-
|
79
|
-
# Create an associated account if the attribute is blank
|
80
|
-
engine.constantize::Account.create!(account: self)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,152 +0,0 @@
|
|
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
|
-
# User extension methods
|
35
|
-
# Custom methods that belongs to a instance user
|
36
|
-
module UserExtensions
|
37
|
-
extend ActiveSupport::Concern
|
38
|
-
|
39
|
-
|
40
|
-
# @return [nil]
|
41
|
-
# @description Set the user alias based on the full_name.
|
42
|
-
# @example
|
43
|
-
# puts current_user.full_name # John Doe
|
44
|
-
# puts current_user.set_alias # John D.
|
45
|
-
def set_alias
|
46
|
-
if self.alias.blank?
|
47
|
-
self.alias = full_name_initials()
|
48
|
-
self.save
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
# @return [void]
|
54
|
-
# @description Register a new notification for the current user
|
55
|
-
# @param subject String Short notification description
|
56
|
-
# @param body String Long notification description
|
57
|
-
# @param url String Link to notified object
|
58
|
-
# @param category String Kind of notification: info, warning, danger, success.
|
59
|
-
def notification subject, body:nil, url:nil, category:"info"
|
60
|
-
Courier::Bell::Notification.new(self, subject, body:body, url:url, category:category)
|
61
|
-
end
|
62
|
-
|
63
|
-
# @return [void]
|
64
|
-
# @description Register a new notification for the current user
|
65
|
-
# @param subject String Short notification description
|
66
|
-
# @param body String Long notification description
|
67
|
-
# @param url String Link to notified object
|
68
|
-
# @param category String Kind of notification: info, warning, danger, success.
|
69
|
-
def notifications quantity=5, category:"info"
|
70
|
-
query = {
|
71
|
-
:pagination => {
|
72
|
-
:perPage => quantity,
|
73
|
-
:page => 1
|
74
|
-
}
|
75
|
-
}
|
76
|
-
Lesli::Courier.new(:lesli_bell, []).from(:notification_service, self, query).call(:index)
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
# @return [CloudDriver::Calendar]
|
81
|
-
# @description Return the default calendar of the user if source_code is not provided.
|
82
|
-
# If source_code is provided the method return the specified source calendar.
|
83
|
-
def calendar source_code: :lesli
|
84
|
-
return Courier::Driver::Calendar.get_user_calendar(self, source_code: source_code, default: true) if source_code == :lesli
|
85
|
-
Courier::Driver::Calendar.get_user_calendar(self, source_code: source_code)
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
# @return [String] The name of this user.
|
90
|
-
# @description Retrieves and returns the name of the user depending on the available information.
|
91
|
-
# The name can be a full name (first and last names), just the first name, or, in case the information
|
92
|
-
# is not available, the email. This method currently is available if the the CloudLock engine exists,
|
93
|
-
# otherwise, it returns *nil*
|
94
|
-
# @example
|
95
|
-
# my_user = current_user
|
96
|
-
# puts my_user.name # can print John Doe
|
97
|
-
# other_user = User.last
|
98
|
-
# puts other_user.name # can print jane.smith@email.com
|
99
|
-
def full_name
|
100
|
-
self.first_name.blank? ? email : self.first_name + " " + self.last_name.to_s
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
# @return [String] The name initials of this user.
|
105
|
-
# @description Retrieves and returns the name initials of the user depending on the available information.
|
106
|
-
# @example
|
107
|
-
# puts current_user.full_name_initials # would print JD
|
108
|
-
def full_name_initials
|
109
|
-
self.first_name.blank? ? "" : self.first_name[0].upcase + "" + (self.last_name.blank? ? "" : self.last_name[0].upcase)
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
# @return [String]
|
114
|
-
# @description Returns the local configuration for the user if there is no locale the default local
|
115
|
-
# of the platform will be returned
|
116
|
-
# @example
|
117
|
-
# locale = User.last.locle
|
118
|
-
# will print something like: :es
|
119
|
-
def locale
|
120
|
-
user_locale = self.settings.find_by(name: "locale")
|
121
|
-
|
122
|
-
# return the desire locale by the user
|
123
|
-
return user_locale.value.to_sym if user_locale
|
124
|
-
|
125
|
-
# create a desire locale if the record does not exist
|
126
|
-
self.settings.create_with(:value => I18n.locale).find_or_create_by(:name => "locale")
|
127
|
-
|
128
|
-
# reevaluate
|
129
|
-
self.locale()
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
def role_names
|
134
|
-
user_roles = self.lesliroles.map(&:name).join(", ")
|
135
|
-
end
|
136
|
-
|
137
|
-
|
138
|
-
# @return [void]
|
139
|
-
# @description Returns MFA settings configured by the user
|
140
|
-
# Example
|
141
|
-
# user_mfa_settings = User.find(2).mfa_settings
|
142
|
-
# puts user_mfa_settings
|
143
|
-
# { :mfa_enabled => true, :mfa_method => "email"}
|
144
|
-
def mfa_settings
|
145
|
-
mfa_enabled = self.settings.create_with(:value => false).find_or_create_by(:name => "mfa_enabled")
|
146
|
-
mfa_method = self.settings.create_with(:value => :email).find_or_create_by(:name => "mfa_method")
|
147
|
-
{
|
148
|
-
:enabled => mfa_enabled.nil? ? false : mfa_enabled.value == 't',
|
149
|
-
:method => mfa_method.nil? ? nil : mfa_method.value.to_sym
|
150
|
-
}
|
151
|
-
end
|
152
|
-
end
|
@@ -1,276 +0,0 @@
|
|
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
|
-
|
34
|
-
# User extension methods
|
35
|
-
# Custom methods that belongs to a instance user
|
36
|
-
module UserSecurity
|
37
|
-
extend ActiveSupport::Concern
|
38
|
-
|
39
|
-
|
40
|
-
def max_object_level_permission
|
41
|
-
|
42
|
-
# get the max object level permission from roles assigned to the user
|
43
|
-
level = self.lesliroles.maximum(:permission_level)
|
44
|
-
|
45
|
-
# if user has no roles assigned, we return the lowest role available
|
46
|
-
# NOTE: This should not be possible due the user needs a role to login
|
47
|
-
unless level
|
48
|
-
return (self.account.roles.minimum(:permission_level))
|
49
|
-
end
|
50
|
-
|
51
|
-
# return the level found
|
52
|
-
level
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [void]
|
56
|
-
# @description After creating a user, creates the necessary resources for them to access the different engines.
|
57
|
-
# @param *roles [String] One or more roles to be checked
|
58
|
-
# check role of the user
|
59
|
-
def has_roles? *roles
|
60
|
-
!roles.intersection(self.roles.map{ |r| r[:name] }).empty?
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
# @return [Boolean]
|
65
|
-
# @description Return true/false if a user has all the privileges to do an action based on a controllers list,
|
66
|
-
# this validation includes the privileges that the user could have based on its roles and the privileges
|
67
|
-
# that has been added to the specific user.
|
68
|
-
# @examples
|
69
|
-
# validate privileges on a controller with the same actions on each one
|
70
|
-
# controllers = ["cloud_house/companies", "cloud_house/projects"]
|
71
|
-
# actions = ["index", "update"]
|
72
|
-
#
|
73
|
-
# current_user.has_privileges?(controllers, actions)
|
74
|
-
def has_privileges_for?(controller, action)
|
75
|
-
begin
|
76
|
-
return !self.privileges
|
77
|
-
.where("lesli_role_privileges.controller = ?", controller)
|
78
|
-
.where("lesli_role_privileges.action = ?", action)
|
79
|
-
.first.blank?
|
80
|
-
rescue => exception
|
81
|
-
return false
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
# @return [Hash]
|
87
|
-
# @description Return a hash that contains all the abilities grouped by controller and define every action privilege. It also
|
88
|
-
# evaluate if the user has the ability no matter if is given to the user by role or by itself.
|
89
|
-
# @examples
|
90
|
-
# current_user.abilities_by_controller
|
91
|
-
def abilities_by_controller
|
92
|
-
|
93
|
-
# Abilities hash where we will save all the privileges the user has to
|
94
|
-
abilities = {}
|
95
|
-
|
96
|
-
# We check all the privileges the user has in the cache table according to his roles
|
97
|
-
# and create a key per controller (with the full controller name) that contains an array of all the
|
98
|
-
# methods/actions with permission
|
99
|
-
# self.privileges.all.each do |privilege|
|
100
|
-
# abilities[privilege.controller] = [] if abilities[privilege.controller].nil?
|
101
|
-
# abilities[privilege.controller] << privilege.action
|
102
|
-
# end
|
103
|
-
|
104
|
-
abilities
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
# @return Boolean
|
110
|
-
# @description Check if user has enough privilege to work with the given role
|
111
|
-
def can_work_with_role?(role)
|
112
|
-
|
113
|
-
# get the role if only id is given
|
114
|
-
role = self.account.roles.find_by(:id => role) unless role.class.name == "Lesli::Role"
|
115
|
-
|
116
|
-
# false if role not found
|
117
|
-
return false if role.blank?
|
118
|
-
|
119
|
-
# not valid role without object levelpermission defined
|
120
|
-
return false if role.object_level_permission.blank?
|
121
|
-
|
122
|
-
# owner role can work with all the roles
|
123
|
-
return true if !self.roles.find_by(name: 'owner').blank?
|
124
|
-
|
125
|
-
# get the max object level permission from the roles the user has assigned
|
126
|
-
user_role_level_max = self.roles.map(&:object_level_permission).max()
|
127
|
-
|
128
|
-
# check if user can work with the object level permission of the role is trying to modify
|
129
|
-
# Note: user only can assigned an object level permission below the max of his own roles
|
130
|
-
# Current user cannot assign role if
|
131
|
-
# role to assign has greater object level permission than the greater role assigned to the current user
|
132
|
-
# role to assign is the same of the greater role assigned to the current user
|
133
|
-
# current user is not sysadmin or owner
|
134
|
-
return false if role.object_level_permission >= user_role_level_max
|
135
|
-
|
136
|
-
# user can work with this role :)
|
137
|
-
return true
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
|
142
|
-
# @return [nil,string]
|
143
|
-
# @description Checks configuration of all the roles assigned to the user
|
144
|
-
# if user has a role with "default path" to use as home to redirect after login
|
145
|
-
# IMPORTANT: This home path is used only the send the user after login, the user
|
146
|
-
# and the role are not limited by this configuration
|
147
|
-
def has_role_with_default_path?()
|
148
|
-
|
149
|
-
# get the roles that contains a path
|
150
|
-
role = self.roles.where.not(path_default: [nil, ""])
|
151
|
-
|
152
|
-
# here we must order the results descendant because we must
|
153
|
-
# keep the path of the hightest object level permission role.
|
154
|
-
# Example: we should use the path of the admin role if user has
|
155
|
-
# admin & employee roles, also order by default_path, so we get first
|
156
|
-
# the roles with path in case the user has roles with the same object level permission
|
157
|
-
role = role.order(object_level_permission: :desc).order(:path_default)
|
158
|
-
|
159
|
-
# get the first role found, due previously we sort in a descendant order
|
160
|
-
# the first role is going to be the one with highest object level permission
|
161
|
-
# this is going to return nil if no role was found
|
162
|
-
default_path = role.first&.path_default || "/"
|
163
|
-
|
164
|
-
# if first loggin for account owner send him to the onboarding page
|
165
|
-
if self.account.onboarding? && self.has_roles?("owner")
|
166
|
-
default_path = "/onboarding"
|
167
|
-
end
|
168
|
-
|
169
|
-
default_path
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
|
174
|
-
# @return [nil,string]
|
175
|
-
# @description Checks configuration of all the roles assigned to the user
|
176
|
-
# if user has a role limited to a defined path
|
177
|
-
# if user has a high privilege role that overrides any other role configuration
|
178
|
-
def has_role_limited_to_path?()
|
179
|
-
|
180
|
-
# get the roles ordering in descendant mode because we must
|
181
|
-
# keep the path of the hightest object level permission role.
|
182
|
-
# Example: we should use the path of the admin role if user has
|
183
|
-
# admin & employee roles, also order by default_path, so we get first
|
184
|
-
# the roles with path in case the user has roles with the same object level permission
|
185
|
-
role = self.lesliroles.order(object_level_permission: :desc).order(:path_default)
|
186
|
-
|
187
|
-
# get the first role found, due previously we sort in a descendant order
|
188
|
-
# the first role is going to be the one with highest object level permission
|
189
|
-
# this is going to return nil if no role was found
|
190
|
-
role = role.first
|
191
|
-
|
192
|
-
# return the path of the role if is limited to a that specific path
|
193
|
-
return role.path_default if role.path_limited == true
|
194
|
-
|
195
|
-
# return nil if role has no limits
|
196
|
-
return nil
|
197
|
-
end
|
198
|
-
|
199
|
-
|
200
|
-
# @return [void]
|
201
|
-
# @description Sets this user as inactive and removes complete access to the platform from them
|
202
|
-
# @example
|
203
|
-
# old_user = User.last
|
204
|
-
# old_user.revoke_access
|
205
|
-
def revoke_access
|
206
|
-
self.update(active: false)
|
207
|
-
end
|
208
|
-
|
209
|
-
|
210
|
-
# @return [void]
|
211
|
-
# @description Change user password forcing user to reset the password
|
212
|
-
def set_password_as_expired
|
213
|
-
self.update(password_expiration_at: Time.current)
|
214
|
-
end
|
215
|
-
|
216
|
-
|
217
|
-
# @return [void]
|
218
|
-
# @description Change user password forcing user to reset the password
|
219
|
-
# @todo validate object level permission
|
220
|
-
def password_reset
|
221
|
-
pass = SecureRandom.hex(10)
|
222
|
-
self.update(password: pass)
|
223
|
-
pass
|
224
|
-
end
|
225
|
-
|
226
|
-
|
227
|
-
# @return [void]
|
228
|
-
# @description After creating a user, creates the necessary resources for them to access the different engines.
|
229
|
-
def has_expired_password?
|
230
|
-
return false if self.password_expiration_at.blank?
|
231
|
-
return Time.current > self.password_expiration_at
|
232
|
-
end
|
233
|
-
|
234
|
-
|
235
|
-
# @return String
|
236
|
-
# @description Change user password forcing user to reset the password
|
237
|
-
def generate_password_reset_token
|
238
|
-
raw, enc = Devise.token_generator.generate(self.class, :reset_password_token)
|
239
|
-
|
240
|
-
self.reset_password_token = enc
|
241
|
-
self.reset_password_sent_at = Time.now.utc
|
242
|
-
save(validate: false)
|
243
|
-
raw
|
244
|
-
end
|
245
|
-
|
246
|
-
|
247
|
-
# @return [Boolean]
|
248
|
-
# @description check if user has a confirmed telephone number
|
249
|
-
def telephone_confirmed?
|
250
|
-
!!self.telephone_confirmed_at
|
251
|
-
end
|
252
|
-
|
253
|
-
|
254
|
-
# @return String
|
255
|
-
# @description Generate a token to validate telephone number
|
256
|
-
def generate_telephone_token(length=4)
|
257
|
-
|
258
|
-
raw, enc = Devise.token_generator.create(self.class, :telephone_confirmation_token, type:'number', length:length)
|
259
|
-
|
260
|
-
self.telephone_confirmation_token = enc
|
261
|
-
self.telephone_confirmation_sent_at = Time.now.utc
|
262
|
-
self.telephone_confirmed_at = nil
|
263
|
-
save(validate: false)
|
264
|
-
raw
|
265
|
-
end
|
266
|
-
|
267
|
-
|
268
|
-
# @return String
|
269
|
-
# @description Mark telephone number as valid and confirmed
|
270
|
-
def confirm_telephone_number
|
271
|
-
self.telephone_confirmation_token = nil
|
272
|
-
self.telephone_confirmation_sent_at = nil
|
273
|
-
self.telephone_confirmed_at = Time.now.utc
|
274
|
-
save(validate: false)
|
275
|
-
end
|
276
|
-
end
|