lesli 5.0.3 → 5.0.5
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 +2 -1
- data/app/assets/images/lesli/brand/app-logo2.svg +52 -0
- data/app/assets/javascripts/lesli/users/confirmations.js +32 -0
- data/app/assets/javascripts/lesli/users/passwords.js +3 -3
- data/app/assets/javascripts/lesli/users/registrations.js +3 -3
- data/app/assets/javascripts/lesli/users/sessions.js +3 -3
- data/app/assets/stylesheets/lesli/users/confirmations.scss +28 -6
- data/app/controllers/lesli/application_controller.rb +3 -3
- data/app/controllers/lesli/application_lesli_controller.rb +2 -2
- data/app/controllers/lesli/interfaces/application/authorization.rb +2 -2
- data/app/controllers/lesli/interfaces/application/logger.rb +14 -38
- data/app/controllers/lesli/interfaces/application/requester.rb +1 -1
- data/app/controllers/lesli/roles_controller.rb +3 -1
- data/app/controllers/lesli/shared/dashboards_controller.rb +308 -0
- data/app/controllers/users/confirmations_controller.rb +63 -27
- data/app/controllers/users/passwords_controller.rb +67 -30
- data/app/controllers/users/sessions_controller.rb +2 -4
- data/app/helpers/lesli/general_helper.rb +1 -1
- data/app/helpers/lesli/navigation_helper.rb +17 -16
- data/app/lib/lesli/system.rb +14 -5
- data/app/mailers/lesli/application_lesli_mailer.rb +8 -19
- data/app/mailers/lesli/devise_mailer.rb +29 -3
- data/app/models/concerns/account_initializer.rb +100 -0
- data/app/models/concerns/{user_guard.rb → user_security.rb} +7 -8
- data/app/models/lesli/account.rb +9 -26
- data/app/models/lesli/application_lesli_record.rb +2 -1
- data/app/models/lesli/descriptor/privilege.rb +38 -0
- data/app/models/lesli/descriptor.rb +18 -1
- data/app/models/lesli/role/power.rb +70 -0
- data/app/models/lesli/role/privilege.rb +38 -0
- data/app/models/lesli/role.rb +20 -15
- data/app/models/lesli/shared/dashboard.rb +162 -0
- data/app/models/lesli/system_controller.rb +1 -0
- data/app/models/lesli/user/{role.rb → power.rb} +1 -1
- data/app/{services/lesli/role_service.rb → models/lesli/user/setting.rb} +10 -9
- data/app/models/lesli/user.rb +11 -20
- data/app/operators/lesli/controller_operator.rb +148 -0
- data/app/operators/lesli/descriptor_privilege_operator.rb +75 -0
- data/app/operators/lesli/role_power_operator.rb +108 -0
- data/app/operators/lesli/user_registration_operator.rb +121 -0
- data/app/services/lesli/user_service.rb +2 -4
- data/app/services/lesli/{user/session_service.rb → user_session_service.rb} +11 -4
- data/app/views/devise/confirmations/new.html.erb +0 -14
- data/app/views/devise/confirmations/show.html.erb +63 -0
- data/app/views/devise/passwords/edit.html.erb +78 -24
- data/app/views/devise/passwords/new.html.erb +2 -3
- data/app/views/lesli/emails/devise_mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/lesli/emails/devise_mailer/reset_password_instructions.html.erb +23 -0
- data/app/views/lesli/partials/_application-lesli-engines.html.erb +1 -1
- data/app/views/lesli/partials/_application-lesli-header.html.erb +3 -1
- data/app/views/lesli/partials/_application-lesli-icons.html.erb +1 -1
- data/config/initializers/devise.rb +2 -0
- data/config/locales/translations.en.yml +13 -3
- data/config/locales/translations.es.yml +13 -3
- data/config/routes.rb +4 -2
- data/db/migrate/v1.0/0010000110_create_lesli_accounts.rb +2 -0
- data/db/{tables/0010001010_create_account_settings.rb → migrate/v1.0/0010001010_create_lesli_account_settings.rb} +5 -5
- data/db/{tables/0010003110_create_user_settings.rb → migrate/v1.0/0010003110_create_lesli_user_settings.rb} +4 -4
- data/db/migrate/v1.0/0010003210_create_lesli_user_sessions.rb +6 -2
- data/db/migrate/v1.0/{0010003410_create_lesli_user_roles.rb → 0010003410_create_lesli_user_powers.rb} +4 -4
- data/db/migrate/v1.0/0010005010_create_lesli_descriptors.rb +1 -1
- data/db/migrate/v1.0/{0010003910_create_lesli_user_agents.rb → 0010005510_create_lesli_role_powers.rb} +7 -9
- data/db/{tables/0010005710_create_role_privileges.rb → migrate/v1.0/0010005710_create_lesli_role_privileges.rb} +6 -6
- data/db/seed/development/users.rb +3 -4
- data/db/seed/tools.rb +4 -4
- data/db/seeds.rb +16 -29
- data/lib/lesli/engine.rb +33 -10
- data/lib/lesli/version.rb +1 -1
- data/lib/mailer_previews/devise_mailer_preview.rb +7 -0
- data/lib/sass/lesli/bulma/loader.scss +3 -0
- data/lib/sass/lesli/layouts/application-navbar.scss +1 -1
- data/lib/sass/lesli/pages/devise-simple.scss +2 -1
- data/lib/tasks/lesli/controllers.rake +1 -94
- data/lib/tasks/lesli/db.rake +43 -3
- data/lib/tasks/lesli/dev.rake +66 -0
- data/lib/tasks/lesli/engine.rake +59 -0
- data/lib/tasks/lesli/privileges.rake +54 -0
- data/lib/tasks/lesli_tasks.rake +5 -0
- data/lib/vue/application.js +11 -3
- data/lib/vue/devise/passwords.js +7 -7
- data/lib/vue/devise/registrations.js +2 -2
- data/lib/vue/devise/sessions.js +11 -6
- data/lib/vue/layouts/application-header.vue +15 -3
- data/lib/vue/shared/dashboards/apps/edit.vue +215 -0
- data/lib/vue/{apps → shared}/dashboards/apps/index.vue +3 -5
- data/lib/vue/{apps → shared}/dashboards/apps/show.vue +26 -16
- data/lib/vue/{apps → shared}/dashboards/components/form.vue +31 -43
- data/lib/vue/shared/stores/dashboard.js +251 -0
- data/lib/vue/stores/translations.json +24 -72
- data/lib/vue/stores/{user.js → users.js} +1 -1
- data/lib/webpack/base.js +3 -2
- data/lib/webpack/core.js +2 -1
- data/readme.md +23 -7
- metadata +63 -65
- data/app/models/concerns/account_engines.rb +0 -249
- data/app/models/concerns/user_polyfill.rb +0 -134
- data/db/migrate/v1.0/0010001510_create_lesli_account_requests.rb +0 -45
- data/db/migrate/v1.0/0010003810_create_lesli_user_requests.rb +0 -44
- data/db/tables/0010005510_create_role_descriptors.rb +0 -44
- data/lib/vue/apps/dashboards/apps/edit.vue +0 -105
- data/lib/vue/apps/dashboards/components/preview.vue +0 -172
- /data/app/assets/icons/lesli/{cloud-vault.svg → cloud-guard.svg} +0 -0
- /data/lib/vue/{apps → shared}/cloudobjects/action.vue +0 -0
- /data/lib/vue/{apps → shared}/cloudobjects/discussion/content.vue +0 -0
- /data/lib/vue/{apps → shared}/cloudobjects/discussion/element.vue +0 -0
- /data/lib/vue/{apps → shared}/cloudobjects/discussion/filters.vue +0 -0
- /data/lib/vue/{apps → shared}/cloudobjects/discussion/new.vue +0 -0
- /data/lib/vue/{apps → shared}/cloudobjects/discussion.vue +0 -0
- /data/lib/vue/{apps → shared}/cloudobjects/file/grid.vue +0 -0
- /data/lib/vue/{apps → shared}/cloudobjects/file/list.vue +0 -0
- /data/lib/vue/{apps → shared}/cloudobjects/file.vue +0 -0
- /data/lib/vue/{apps → shared}/dashboards/apps/new.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/actions/form.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/actions/forms/chatroom-form.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/actions/forms/cloud-object-clone-form.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/actions/forms/cloud-object-file-form.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/actions/forms/email-form.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/actions/forms/notification-form.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/actions/forms/send-cloud-object-file.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/actions/forms/task-form.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/actions/index.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/checks/form.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/checks/index.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/index.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/new.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/apps/show.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/components/associations.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/components/chart.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/components/workflow-form.vue +0 -0
- /data/lib/vue/{apps → shared}/workflows2/components/workflow-status-dropdown.vue +0 -0
@@ -32,6 +32,14 @@ Building a better future, one line of code at a time.
|
|
32
32
|
|
33
33
|
module Lesli
|
34
34
|
module NavigationHelper
|
35
|
+
|
36
|
+
# Prints a separator line
|
37
|
+
def navigation_separator
|
38
|
+
content_tag(:li) do
|
39
|
+
content_tag(:hr)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
35
43
|
# Prints a html link inside a list item
|
36
44
|
def navigation_item(path, label, icon = nil, reload: false)
|
37
45
|
# default vue router links for single page applications
|
@@ -58,15 +66,9 @@ module Lesli
|
|
58
66
|
end
|
59
67
|
end
|
60
68
|
|
61
|
-
# Prints a separator line
|
62
|
-
def navigation_separator
|
63
|
-
content_tag(:li) do
|
64
|
-
content_tag(:hr)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
69
|
# 00.00 System administration
|
69
70
|
def navigation_engine_admin(title: "Administration", subtitle: "Users, privileges, access roles.")
|
71
|
+
return unless defined? LesliAdmin
|
70
72
|
navigation_engine_item(title, subtitle, "admin", lesli_admin.root_path, controller_path.include?("lesli_admin"))
|
71
73
|
end
|
72
74
|
|
@@ -243,10 +245,10 @@ module Lesli
|
|
243
245
|
|
244
246
|
# 07.02 Help engine
|
245
247
|
def navigation_engine_help(title: "Help", subtitle: "Support Ticket System")
|
246
|
-
return unless defined?
|
248
|
+
return unless defined? LesliHelp
|
247
249
|
|
248
|
-
navigation_engine_item(title, subtitle, "help",
|
249
|
-
controller_path.include?("
|
250
|
+
navigation_engine_item(title, subtitle, "help", lesli_help.root_path,
|
251
|
+
controller_path.include?("lesli_help"))
|
250
252
|
end
|
251
253
|
|
252
254
|
# 07.03 Portal engine
|
@@ -267,12 +269,11 @@ module Lesli
|
|
267
269
|
|
268
270
|
# SECURITY & PRIVACY
|
269
271
|
|
270
|
-
# 08.01
|
271
|
-
def
|
272
|
-
return unless defined?
|
273
|
-
|
274
|
-
|
275
|
-
controller_path.include?("lesli_vault"))
|
272
|
+
# 08.01 Guard engine
|
273
|
+
def navigation_engine_guard(title: "Guard", subtitle: "Users, privileges and access roles.")
|
274
|
+
return unless defined? LesliGuard
|
275
|
+
navigation_engine_item(title, subtitle, "guard", lesli_guard.root_path,
|
276
|
+
controller_path.include?("lesli_guard"))
|
276
277
|
end
|
277
278
|
|
278
279
|
# 08.03 Audit engine
|
data/app/lib/lesli/system.rb
CHANGED
@@ -17,17 +17,17 @@ 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 ·
|
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.
|
24
24
|
|
25
25
|
@contact hello@lesli.tech
|
26
|
-
@website https://lesli.tech
|
26
|
+
@website https://www.lesli.tech
|
27
27
|
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
28
28
|
|
29
|
-
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
30
|
-
// ·
|
29
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
30
|
+
// ·
|
31
31
|
=end
|
32
32
|
|
33
33
|
module Lesli
|
@@ -81,6 +81,15 @@ module Lesli
|
|
81
81
|
name.sub("Lesli", "")
|
82
82
|
end
|
83
83
|
|
84
|
-
LESLI_ENGINES = [
|
84
|
+
LESLI_ENGINES = [
|
85
|
+
"Lesli",
|
86
|
+
"LesliAdmin",
|
87
|
+
"LesliBabel",
|
88
|
+
"LesliAudit",
|
89
|
+
"LesliBell",
|
90
|
+
"LesliDriver",
|
91
|
+
"LesliGuard",
|
92
|
+
"LesliHelp"
|
93
|
+
]
|
85
94
|
end
|
86
95
|
end
|
@@ -75,26 +75,27 @@ module Lesli
|
|
75
75
|
=end
|
76
76
|
#after_action :log_mail_requests
|
77
77
|
|
78
|
-
default(template_path: "lesli/emails/devise_mailer")
|
78
|
+
#default(template_path: "lesli/emails/devise_mailer")
|
79
79
|
|
80
80
|
def initialize
|
81
81
|
|
82
82
|
super
|
83
83
|
|
84
84
|
# some @email data is defined on: LesliMails/src/partials/data.html
|
85
|
-
|
85
|
+
|
86
86
|
@email = {}
|
87
|
-
@
|
88
|
-
@
|
87
|
+
@custom = {}
|
88
|
+
@params = {
|
89
|
+
:host => default_url_options[:host] || ""
|
90
|
+
}
|
89
91
|
|
90
92
|
end
|
91
93
|
|
92
94
|
protected
|
93
95
|
|
94
|
-
def email(
|
96
|
+
def email(params={}, user:nil, to:, subject:, template_name:)
|
95
97
|
|
96
|
-
@
|
97
|
-
@data = @data.merge(data)
|
98
|
+
@params = @params.merge(params)
|
98
99
|
|
99
100
|
mail(
|
100
101
|
to: to,
|
@@ -106,18 +107,6 @@ module Lesli
|
|
106
107
|
|
107
108
|
private
|
108
109
|
|
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
110
|
def build_app_from_params(params)
|
122
111
|
|
123
112
|
@app[:host] = default_url_options[:host]
|
@@ -1,6 +1,32 @@
|
|
1
1
|
module Lesli
|
2
2
|
class DeviseMailer < ApplicationLesliMailer
|
3
|
-
|
3
|
+
|
4
|
+
default(template_path: "lesli/emails/devise_mailer")
|
5
|
+
|
6
|
+
# Sends an email with instructions to allow the user reset the password
|
7
|
+
def reset_password_instructions(user, token, opts = {})
|
8
|
+
|
9
|
+
# defaults for new accounts/users
|
10
|
+
email_template = "reset_password_instructions"
|
11
|
+
email_subject = I18n.t("core.users/confirmations.mailer_email_verification")
|
12
|
+
|
13
|
+
# email parameters
|
14
|
+
params = {
|
15
|
+
url: "/password/edit?reset_password_token=#{token}",
|
16
|
+
user_name: user.full_name
|
17
|
+
}
|
18
|
+
|
19
|
+
# send email
|
20
|
+
pp email(
|
21
|
+
params,
|
22
|
+
to: user.email,
|
23
|
+
subject: email_subject,
|
24
|
+
template_name: email_template
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Sends an email to allow the user confirm the email address
|
29
|
+
def confirmation_instructions(user, token, opts = {})
|
4
30
|
|
5
31
|
# defaults for new accounts/users
|
6
32
|
email_template = "confirmation_instructions"
|
@@ -14,9 +40,9 @@ module Lesli
|
|
14
40
|
|
15
41
|
# Depending on wheter there is a new user or they are changing their email,
|
16
42
|
# one or another field will be used
|
17
|
-
email_recipient =
|
43
|
+
email_recipient = user.unconfirmed_email || user.email
|
18
44
|
|
19
|
-
# email
|
45
|
+
# email parameters
|
20
46
|
params = {
|
21
47
|
url: "/confirmation?confirmation_token=#{token}"
|
22
48
|
}
|
@@ -0,0 +1,100 @@
|
|
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 AccountInitializer
|
34
|
+
extend ActiveSupport::Concern
|
35
|
+
|
36
|
+
|
37
|
+
# initialize minimum resources needed for the account
|
38
|
+
def initialize_account
|
39
|
+
|
40
|
+
# create initial descriptors
|
41
|
+
descriptor_owner = self.descriptors.find_or_create_by(name: "owner")
|
42
|
+
descriptor_sysadmin = self.descriptors.find_or_create_by(name: "sysadmin")
|
43
|
+
descriptor_profile = self.descriptors.find_or_create_by(name: "profile")
|
44
|
+
|
45
|
+
# create default roles for the new account
|
46
|
+
owner = self.roles.create({ name: "owner", active: true, object_level_permission: 2147483647 })
|
47
|
+
|
48
|
+
# platform administrator role
|
49
|
+
sysadmin = self.roles.create({ name: "sysadmin", active: true, object_level_permission: 100000 })
|
50
|
+
|
51
|
+
# access only to user profile
|
52
|
+
limited = self.roles.create({ name: "limited", active: true, object_level_permission: 10, path_default: "/administration/profile" })
|
53
|
+
|
54
|
+
# assign descriptors with appropriate privileges
|
55
|
+
owner.powers.create(:descriptor => descriptor_owner)
|
56
|
+
sysadmin.powers.create(:descriptor => descriptor_sysadmin)
|
57
|
+
limited.powers.create(:descriptor => descriptor_profile)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# initialize engines for new accounts
|
62
|
+
def initialize_engines
|
63
|
+
|
64
|
+
# 01.01 LesliAdmin - Lesli administration area
|
65
|
+
if defined? LesliAdmin
|
66
|
+
if self.admin.blank?
|
67
|
+
self.admin = LesliAdmin::Account.new
|
68
|
+
self.admin.account = self
|
69
|
+
self.admin.save!
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# 03.01 LesliDriver - Unified calendar app
|
74
|
+
if defined? LesliDriver
|
75
|
+
if self.driver.blank?
|
76
|
+
self.driver = LesliDriver::Account.new
|
77
|
+
self.driver.account = self
|
78
|
+
self.driver.save!
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# 07.02 LesliHelp - Support Ticket System
|
83
|
+
if defined? LesliHelp
|
84
|
+
if self.help.blank?
|
85
|
+
self.help = LesliHelp::Account.new
|
86
|
+
self.help.account = self
|
87
|
+
self.help.save!
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# 08.03 LesliAudit - System analytics
|
92
|
+
if defined? LesliAudit
|
93
|
+
if self.audit.blank?
|
94
|
+
self.audit = LesliAudit::Account.new
|
95
|
+
self.audit.account = self
|
96
|
+
self.audit.save!
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -33,7 +33,7 @@ Building a better future, one line of code at a time.
|
|
33
33
|
|
34
34
|
# User extension methods
|
35
35
|
# Custom methods that belongs to a instance user
|
36
|
-
module
|
36
|
+
module UserSecurity
|
37
37
|
extend ActiveSupport::Concern
|
38
38
|
|
39
39
|
|
@@ -71,14 +71,13 @@ module UserGuard
|
|
71
71
|
# actions = ["index", "update"]
|
72
72
|
#
|
73
73
|
# current_user.has_privileges?(controllers, actions)
|
74
|
-
def
|
74
|
+
def has_privileges_for?(controller, action)
|
75
75
|
begin
|
76
|
-
!self.privileges
|
77
|
-
.where("
|
78
|
-
.where("
|
79
|
-
.first.blank?
|
76
|
+
return !self.privileges
|
77
|
+
.where("lesli_role_privileges.controller = ?", controller)
|
78
|
+
.where("lesli_role_privileges.action = ?", action)
|
79
|
+
.first.blank?
|
80
80
|
rescue => exception
|
81
|
-
#Honeybadger.notify(exception)
|
82
81
|
return false
|
83
82
|
end
|
84
83
|
end
|
@@ -191,7 +190,7 @@ module UserGuard
|
|
191
190
|
role = role.first
|
192
191
|
|
193
192
|
# return the path of the role if is limited to a that specific path
|
194
|
-
return role.
|
193
|
+
return role.path_default if role.path_limited == true
|
195
194
|
|
196
195
|
# return nil if role has no limits
|
197
196
|
return nil
|
data/app/models/lesli/account.rb
CHANGED
@@ -33,6 +33,8 @@ Building a better future, one line of code at a time.
|
|
33
33
|
module Lesli
|
34
34
|
class Account < ApplicationLesliRecord
|
35
35
|
|
36
|
+
include AccountInitializer
|
37
|
+
|
36
38
|
|
37
39
|
# accounts always belongs to a user
|
38
40
|
belongs_to :user, optional: true
|
@@ -48,10 +50,14 @@ module Lesli
|
|
48
50
|
has_many :locations
|
49
51
|
has_many :feedbacks
|
50
52
|
has_many :descriptors
|
51
|
-
has_many :activities
|
52
|
-
has_many :currencies
|
53
|
+
has_many :activities
|
54
|
+
has_many :currencies
|
53
55
|
has_many :logs
|
54
56
|
|
57
|
+
has_one :help, class_name: "LesliHelp::Account"
|
58
|
+
has_one :audit, class_name: "LesliAudit::Account"
|
59
|
+
has_one :admin, class_name: "LesliAdmin::Account"
|
60
|
+
has_one :driver, class_name: "LesliDriver::Account"
|
55
61
|
|
56
62
|
|
57
63
|
# account statuses
|
@@ -77,30 +83,7 @@ module Lesli
|
|
77
83
|
|
78
84
|
# initializers for new accounts
|
79
85
|
after_create :initialize_account
|
86
|
+
after_create :initialize_engines
|
80
87
|
|
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
|
105
88
|
end
|
106
89
|
end
|
@@ -0,0 +1,38 @@
|
|
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 Descriptor::Privilege < ApplicationLesliRecord
|
35
|
+
belongs_to :descriptor
|
36
|
+
belongs_to :action, class_name: "SystemController::Action"
|
37
|
+
end
|
38
|
+
end
|
@@ -33,9 +33,26 @@ Building a better future, one line of code at a time.
|
|
33
33
|
module Lesli
|
34
34
|
class Descriptor < ApplicationLesliRecord
|
35
35
|
belongs_to :account
|
36
|
-
|
36
|
+
has_many :privileges
|
37
37
|
#has_many :role_descriptors
|
38
|
+
|
39
|
+
# this scope is needed to allow to join with deleted descriptors
|
40
|
+
# join with deleted descriptors is needed to know which privileges we have to remove from the
|
41
|
+
# role_privileges table when a descriptor is removed from role_describers
|
42
|
+
has_many :role_descriptors_all, -> { with_deleted }, foreign_key: "descriptors_id", class_name: "Role::Descriptor"
|
38
43
|
|
39
44
|
validates :name, presence: true
|
45
|
+
|
46
|
+
after_create :initialize_descriptor_privileges
|
47
|
+
|
48
|
+
def initialize_descriptor_privileges
|
49
|
+
|
50
|
+
descriptor_operator = DescriptorPrivilegeOperator.new(self)
|
51
|
+
|
52
|
+
descriptor_operator.add_profile_privileges(self) if self.name == "profile"
|
53
|
+
|
54
|
+
descriptor_operator.add_owner_privileges(self) if ["owner", "sysadmin"].include?(self.name)
|
55
|
+
|
56
|
+
end
|
40
57
|
end
|
41
58
|
end
|
@@ -0,0 +1,70 @@
|
|
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::Power < ApplicationLesliRecord
|
35
|
+
belongs_to :role
|
36
|
+
belongs_to :descriptor
|
37
|
+
|
38
|
+
after_save :synchronize_privileges
|
39
|
+
after_destroy :synchronize_privileges
|
40
|
+
|
41
|
+
def synchronize_privileges
|
42
|
+
RolePowerOperator.new(self.role.id).synchronize
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.index current_user, query, role
|
46
|
+
|
47
|
+
#role.descriptors
|
48
|
+
Descriptor
|
49
|
+
.joins(:privileges)
|
50
|
+
.left_joins(:role_descriptors)
|
51
|
+
.joins(%(
|
52
|
+
inner join system_controller_actions
|
53
|
+
on system_controller_actions.id = descriptor_privileges.system_controller_action_id
|
54
|
+
)).joins(%(
|
55
|
+
inner join system_controllers
|
56
|
+
on system_controllers.id = system_controller_actions.system_controller_id
|
57
|
+
))
|
58
|
+
.select(
|
59
|
+
"coalesce(role_descriptors.descriptor_id, descriptors.id) as id",
|
60
|
+
"descriptors.name as name",
|
61
|
+
"system_controllers.reference as reference",
|
62
|
+
"system_controllers.route as controller",
|
63
|
+
#"descriptors.category as action",
|
64
|
+
"system_controller_actions.name as action",
|
65
|
+
"system_controllers.engine as engine",
|
66
|
+
"case when role_descriptors.descriptor_id is null then false else true end as active"
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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::Privilege < Lesli::ApplicationLesliRecord
|
35
|
+
belongs_to :role
|
36
|
+
has_many :descriptors
|
37
|
+
end
|
38
|
+
end
|
data/app/models/lesli/role.rb
CHANGED
@@ -32,24 +32,36 @@ Building a better future, one line of code at a time.
|
|
32
32
|
|
33
33
|
module Lesli
|
34
34
|
class Role < ApplicationLesliRecord
|
35
|
-
|
36
35
|
belongs_to :account
|
37
36
|
|
38
|
-
|
39
37
|
# Role resources
|
40
38
|
has_many :activities
|
41
|
-
has_many :
|
42
|
-
has_many :privileges,
|
43
|
-
|
39
|
+
has_many :powers, dependent: :delete_all
|
40
|
+
has_many :privileges, dependent: :delete_all
|
41
|
+
|
42
|
+
# validations
|
43
|
+
validates :name, presence: :true
|
44
|
+
validates :object_level_permission, presence: :true
|
44
45
|
|
45
46
|
# initializers for new roles
|
46
47
|
after_create :after_create_role
|
47
48
|
|
49
|
+
# Return a list of roles that the user is able to work with
|
50
|
+
# according to object level permission
|
51
|
+
def self.list(current_user, query, params)
|
52
|
+
current_user.account.roles
|
53
|
+
.where("object_level_permission <= ?", current_user.max_object_level_permission)
|
54
|
+
.order(object_level_permission: :desc, name: :asc)
|
55
|
+
.select(:id, :name, :object_level_permission)
|
56
|
+
end
|
48
57
|
|
49
|
-
#
|
50
|
-
|
51
|
-
|
58
|
+
# @return [Boolean]
|
59
|
+
# @description Returns if a role is assigned to users.
|
60
|
+
def has_users?
|
61
|
+
User::Role.where(role: self).count > 0
|
62
|
+
end
|
52
63
|
|
64
|
+
private
|
53
65
|
|
54
66
|
def after_create_role
|
55
67
|
|
@@ -66,13 +78,6 @@ module Lesli
|
|
66
78
|
self.update_attribute("code", role_code)
|
67
79
|
end
|
68
80
|
|
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
81
|
# @return [void]
|
77
82
|
# @param current_user [::User] The user that deleted the role
|
78
83
|
# @param [Role] The role that was deleted
|