lesli_security 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Rakefile +38 -0
- data/app/assets/config/lesli_security_manifest.js +38 -0
- data/app/assets/images/lesli_security/security-logo.svg +57 -0
- data/app/assets/javascripts/lesli_security/application.js +5583 -0
- data/app/assets/stylesheets/lesli_security/application.css +95 -0
- data/app/controllers/lesli_security/accounts_controller.rb +60 -0
- data/app/controllers/lesli_security/application_controller.rb +37 -0
- data/app/controllers/lesli_security/dashboard/components_controller.rb +60 -0
- data/app/controllers/lesli_security/dashboards_controller.rb +36 -0
- data/app/controllers/lesli_security/descriptor/activities_controller.rb +122 -0
- data/app/controllers/lesli_security/descriptor/privileges_controller.rb +112 -0
- data/app/controllers/lesli_security/descriptors_controller.rb +129 -0
- data/app/controllers/lesli_security/role/activities_controller.rb +76 -0
- data/app/controllers/lesli_security/role/descriptors_controller.rb +97 -0
- data/app/controllers/lesli_security/role/privileges_controller.rb +47 -0
- data/app/controllers/lesli_security/roles_controller.rb +185 -0
- data/app/controllers/lesli_security/user/roles_controller.rb +98 -0
- data/app/controllers/lesli_security/user/sessions_controller.rb +71 -0
- data/app/controllers/lesli_security/users_controller.rb +206 -0
- data/app/helpers/lesli_security/accounts_helper.rb +4 -0
- data/app/helpers/lesli_security/application_helper.rb +4 -0
- data/app/helpers/lesli_security/dashboards_helper.rb +4 -0
- data/app/helpers/lesli_security/descriptor/activities_helper.rb +4 -0
- data/app/helpers/lesli_security/descriptor/privileges_helper.rb +4 -0
- data/app/helpers/lesli_security/descriptors_helper.rb +4 -0
- data/app/helpers/lesli_security/role/activities_helper.rb +4 -0
- data/app/helpers/lesli_security/role/descriptors_helper.rb +4 -0
- data/app/helpers/lesli_security/role/privileges_helper.rb +4 -0
- data/app/helpers/lesli_security/roles_helper.rb +4 -0
- data/app/jobs/lesli_security/application_job.rb +37 -0
- data/app/mailers/lesli_security/application_mailer.rb +39 -0
- data/app/models/lesli_security/account.rb +43 -0
- data/app/models/lesli_security/application_record.rb +37 -0
- data/app/models/lesli_security/dashboard/component.rb +42 -0
- data/app/models/lesli_security/dashboard.rb +58 -0
- data/app/models/lesli_security/descriptor/activity.rb +40 -0
- data/app/models/lesli_security/descriptor/privilege.rb +40 -0
- data/app/models/lesli_security/descriptor.rb +41 -0
- data/app/models/lesli_security/role/activity.rb +40 -0
- data/app/services/lesli_security/descriptor_privilege_service.rb +74 -0
- data/app/services/lesli_security/descriptor_service.rb +152 -0
- data/app/services/lesli_security/role_descriptor_service.rb +61 -0
- data/app/services/lesli_security/role_service.rb +215 -0
- data/app/services/lesli_security/user_service.rb +305 -0
- data/app/views/lesli_security/accounts/_account.html.erb +2 -0
- data/app/views/lesli_security/accounts/_form.html.erb +17 -0
- data/app/views/lesli_security/accounts/edit.html.erb +10 -0
- data/app/views/lesli_security/accounts/index.html.erb +14 -0
- data/app/views/lesli_security/accounts/new.html.erb +9 -0
- data/app/views/lesli_security/accounts/show.html.erb +10 -0
- data/app/views/lesli_security/dashboards/show.html.erb +1 -0
- data/app/views/lesli_security/descriptor/activities/_form.html.erb +32 -0
- data/app/views/lesli_security/descriptor/activities/edit.html.erb +34 -0
- data/app/views/lesli_security/descriptor/activities/index.html.erb +34 -0
- data/app/views/lesli_security/descriptor/activities/new.html.erb +34 -0
- data/app/views/lesli_security/descriptor/activities/show.html.erb +34 -0
- data/app/views/lesli_security/descriptor/privileges/_form.html.erb +32 -0
- data/app/views/lesli_security/descriptor/privileges/edit.html.erb +34 -0
- data/app/views/lesli_security/descriptor/privileges/index.html.erb +34 -0
- data/app/views/lesli_security/descriptor/privileges/new.html.erb +34 -0
- data/app/views/lesli_security/descriptor/privileges/show.html.erb +34 -0
- data/app/views/lesli_security/descriptors/_form.html.erb +32 -0
- data/app/views/lesli_security/descriptors/edit.html.erb +34 -0
- data/app/views/lesli_security/descriptors/index.html.erb +34 -0
- data/app/views/lesli_security/descriptors/new.html.erb +34 -0
- data/app/views/lesli_security/descriptors/show.html.erb +34 -0
- data/app/views/lesli_security/partials/_engine-navigation.html.erb +38 -0
- data/app/views/lesli_security/role/activities/_form.html.erb +32 -0
- data/app/views/lesli_security/role/activities/edit.html.erb +34 -0
- data/app/views/lesli_security/role/activities/index.html.erb +34 -0
- data/app/views/lesli_security/role/activities/new.html.erb +34 -0
- data/app/views/lesli_security/role/activities/show.html.erb +34 -0
- data/app/views/lesli_security/role/descriptors/_form.html.erb +32 -0
- data/app/views/lesli_security/role/descriptors/edit.html.erb +34 -0
- data/app/views/lesli_security/role/descriptors/index.html.erb +34 -0
- data/app/views/lesli_security/role/descriptors/new.html.erb +34 -0
- data/app/views/lesli_security/role/descriptors/show.html.erb +34 -0
- data/app/views/lesli_security/role/privileges/_form.html.erb +32 -0
- data/app/views/lesli_security/role/privileges/edit.html.erb +34 -0
- data/app/views/lesli_security/role/privileges/index.html.erb +34 -0
- data/app/views/lesli_security/role/privileges/new.html.erb +34 -0
- data/app/views/lesli_security/role/privileges/show.html.erb +34 -0
- data/app/views/lesli_security/roles/edit.html.erb +34 -0
- data/app/views/lesli_security/roles/index.html.erb +34 -0
- data/app/views/lesli_security/roles/new.html.erb +34 -0
- data/app/views/lesli_security/roles/show.html.erb +34 -0
- data/app/views/lesli_security/users/edit.html.erb +10 -0
- data/app/views/lesli_security/users/index.html.erb +34 -0
- data/app/views/lesli_security/users/new.html.erb +34 -0
- data/app/views/lesli_security/users/show.html.erb +1 -0
- data/config/locales/translations.en.yml +44 -0
- data/config/locales/translations.es.yml +44 -0
- data/config/locales/translations.fr.yml +44 -0
- data/config/locales/translations.it.yml +44 -0
- data/config/locales/translations.pt.yml +44 -0
- data/config/routes.rb +90 -0
- data/db/migrate/v1/0010000210_create_lesli_roles.rb +60 -0
- data/db/migrate/v1/0010000310_create_lesli_users.rb +97 -0
- data/db/migrate/v1/0010003010_create_lesli_user_details.rb +49 -0
- data/db/migrate/v1/0010003110_create_lesli_user_settings.rb +44 -0
- data/db/migrate/v1/0010003210_create_lesli_user_sessions.rb +55 -0
- data/db/migrate/v1/0010003410_create_lesli_user_powers.rb +43 -0
- data/db/migrate/v1/0010004010_create_lesli_user_logs.rb +45 -0
- data/db/migrate/v1/0010005010_create_lesli_descriptors.rb +44 -0
- data/db/migrate/v1/0010005110_create_lesli_descriptor_privileges.rb +45 -0
- data/db/migrate/v1/0010005210_create_lesli_descriptor_activities.rb +49 -0
- data/db/migrate/v1/0010005510_create_lesli_role_powers.rb +51 -0
- data/db/migrate/v1/0010005710_create_lesli_role_privileges.rb +45 -0
- data/db/migrate/v1/0802000110_create_lesli_security_accounts.rb +42 -0
- data/db/migrate/v1/0802050110_create_lesli_security_dashboards.rb +51 -0
- data/db/migrate/v1/0802050210_create_lesli_security_dashboard_components.rb +53 -0
- data/lib/lesli_security/engine.rb +18 -0
- data/lib/lesli_security/version.rb +4 -0
- data/lib/lesli_security.rb +6 -0
- data/lib/scss/application.scss +38 -0
- data/lib/scss/users.scss +67 -0
- data/lib/tasks/lesli_security_tasks.rake +50 -0
- data/lib/vue/application.js +112 -0
- data/lib/vue/apps/descriptors/components/form.vue +136 -0
- data/lib/vue/apps/descriptors/edit.vue +83 -0
- data/lib/vue/apps/descriptors/index.vue +113 -0
- data/lib/vue/apps/descriptors/new.vue +69 -0
- data/lib/vue/apps/descriptors/show.vue +233 -0
- data/lib/vue/apps/roles/components/descriptors.vue +81 -0
- data/lib/vue/apps/roles/components/form.vue +253 -0
- data/lib/vue/apps/roles/components/privilegeCustom.vue +86 -0
- data/lib/vue/apps/roles/components/privilegeStandard.vue +196 -0
- data/lib/vue/apps/roles/edit.vue +118 -0
- data/lib/vue/apps/roles/index.vue +168 -0
- data/lib/vue/apps/roles/logs.vue +110 -0
- data/lib/vue/apps/roles/new.vue +86 -0
- data/lib/vue/apps/roles/show.vue +109 -0
- data/lib/vue/apps/users/components/information-card.vue +104 -0
- data/lib/vue/apps/users/components/information-form.vue +176 -0
- data/lib/vue/apps/users/components/integrations-information.vue +61 -0
- data/lib/vue/apps/users/components/management-roles.vue +107 -0
- data/lib/vue/apps/users/components/management-security.vue +113 -0
- data/lib/vue/apps/users/components/management-sessions.vue +101 -0
- data/lib/vue/apps/users/components/management-settings.vue +93 -0
- data/lib/vue/apps/users/index.vue +207 -0
- data/lib/vue/apps/users/new.vue +181 -0
- data/lib/vue/apps/users/show.vue +131 -0
- data/lib/vue/stores/descriptor.js +117 -0
- data/lib/vue/stores/descriptors.js +156 -0
- data/lib/vue/stores/role.js +203 -0
- data/lib/vue/stores/roles.js +58 -0
- data/lib/vue/stores/translations.json +277 -0
- data/lib/vue/stores/user.js +331 -0
- data/lib/vue/stores/users.js +166 -0
- data/license +674 -0
- data/readme.md +76 -0
- metadata +225 -0
|
@@ -0,0 +1,76 @@
|
|
|
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 platform.
|
|
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
|
+
|
|
32
|
+
=end
|
|
33
|
+
|
|
34
|
+
module LesliSecurity
|
|
35
|
+
class Role::ActivitiesController < ApplicationController
|
|
36
|
+
# @return [HTML|JSON] HTML view for listing all activities associated to a *role*
|
|
37
|
+
# @description Retrieves and returns all the activities associated to a *Role*.
|
|
38
|
+
# The HTTP request has to specify wheter the HTML or the JSON text should be rendered
|
|
39
|
+
# @example
|
|
40
|
+
# # Executing this controller's action from javascript's frontend
|
|
41
|
+
# this.http.get(`127.0.0.1/administration/roles/1/activities.json`);
|
|
42
|
+
def index
|
|
43
|
+
respond_to do |format|
|
|
44
|
+
format.html {}
|
|
45
|
+
format.json do
|
|
46
|
+
return respond_with_not_found unless @role
|
|
47
|
+
|
|
48
|
+
respond_with_successful(Role::Activity.index(@role, @query))
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# @return [Json] Json that contains all the information needed to create a new role_activity
|
|
54
|
+
# @description Retrieves and retuns all the information needed to create a new role_activity,
|
|
55
|
+
# including the list of companies and contacts.
|
|
56
|
+
# @example
|
|
57
|
+
# # Executing this controller's action from javascript's frontend
|
|
58
|
+
# this.http.get('127.0.0.1/house/options/projects')
|
|
59
|
+
def options
|
|
60
|
+
respond_with_successful(Role::Activity.options(current_user, @query))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
# @return [void]
|
|
66
|
+
# @description Sets the requested user based on the current_users's account
|
|
67
|
+
# @example
|
|
68
|
+
# # Executing this method from a controller action:
|
|
69
|
+
# set_role
|
|
70
|
+
# puts @role
|
|
71
|
+
# # This will either display nil or an instance of Role
|
|
72
|
+
def set_role
|
|
73
|
+
@role = current_user.account.roles.find_by(id: params[:role_id])
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
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 LesliSecurity
|
|
34
|
+
class Role::DescriptorsController < ApplicationController
|
|
35
|
+
before_action :set_role, only: %i[ index show update create destroy ]
|
|
36
|
+
before_action :set_role_descriptor, only: %i[ show update destroy ]
|
|
37
|
+
|
|
38
|
+
def index
|
|
39
|
+
respond_with_successful(RoleDescriptorService.new(current_user).index(@role))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# POST /role/descriptors
|
|
43
|
+
def create
|
|
44
|
+
|
|
45
|
+
system_descriptor = Lesli::Descriptor.find_by(:id => role_descriptor_params[:id])
|
|
46
|
+
role_power = @role.powers.with_deleted.find_or_create_by(:descriptor => system_descriptor)
|
|
47
|
+
|
|
48
|
+
role_power.recover if role_power.deleted?
|
|
49
|
+
|
|
50
|
+
respond_with_successful(role_power)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def update
|
|
54
|
+
|
|
55
|
+
# Get the descriptor we want to take the privileges to be activated and added
|
|
56
|
+
# into the role, this can be done through the role power table
|
|
57
|
+
system_descriptor = Lesli::Descriptor.find_by(:id => role_descriptor_params[:id])
|
|
58
|
+
|
|
59
|
+
# Check if the descriptor is already added to the role, if not, we create the new record
|
|
60
|
+
# assigning the descriptor to the role as power
|
|
61
|
+
role_power = @role.powers.with_deleted.find_or_create_by(:descriptor => system_descriptor)
|
|
62
|
+
|
|
63
|
+
# Now we update the privileges that the role wants to inherit from the privileges
|
|
64
|
+
# available in the descriptor
|
|
65
|
+
respond_with_successful(role_power.update(role_descriptor_params))
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# DELETE /role/descriptors/1
|
|
69
|
+
def destroy
|
|
70
|
+
return respond_with_not_found unless @role_descriptor
|
|
71
|
+
|
|
72
|
+
if @role_descriptor.destroy
|
|
73
|
+
#Role::Activity.log_destroy_descriptor(current_user, @role, @role_descriptor)
|
|
74
|
+
respond_with_successful
|
|
75
|
+
else
|
|
76
|
+
respond_with_error(@role_descriptor.errors.full_messages.to_sentence)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def set_role
|
|
83
|
+
@role = current_user.account.roles.find_by(id: params[:role_id])
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def set_role_descriptor
|
|
87
|
+
return respond_with_not_found unless @role
|
|
88
|
+
@role_descriptor = @role.powers.find_by(descriptor_id: params[:id])
|
|
89
|
+
#@role_descriptor = @role.descriptors.find_by(system_descriptors_id: params[:id])
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Only allow a list of trusted parameters through.
|
|
93
|
+
def role_descriptor_params
|
|
94
|
+
params.require(:role_descriptor).permit(:id, :pindex, :plist, :pshow, :pcreate, :pupdate, :pdestroy)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
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 LesliSecurity
|
|
34
|
+
class Role::PrivilegesController < ApplicationController
|
|
35
|
+
before_action :set_role, only: %i[ index ]
|
|
36
|
+
|
|
37
|
+
def index
|
|
38
|
+
respond_with_successful(RoleDescriptorService.new(current_user).privileges(@role))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def set_role
|
|
44
|
+
@role = current_user.account.roles.find_by(id: params[:role_id])
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,185 @@
|
|
|
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 LesliSecurity
|
|
34
|
+
class RolesController < ApplicationController
|
|
35
|
+
before_action :set_role, only: %i[ show update destroy ]
|
|
36
|
+
|
|
37
|
+
def index
|
|
38
|
+
respond_to do |format|
|
|
39
|
+
format.html { }
|
|
40
|
+
format.json {
|
|
41
|
+
respond_with_successful(RoleService.new(current_user, query).index)
|
|
42
|
+
#respond_with_pagination(RoleService.new(current_user, query).index)
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def show
|
|
48
|
+
respond_to do |format|
|
|
49
|
+
format.html { }
|
|
50
|
+
format.json { respond_with_successful(@role.show) }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @return [HTML] HTML view for creating a new role
|
|
55
|
+
# @description returns an HTML view with a form so users can create a new role
|
|
56
|
+
# @example
|
|
57
|
+
# # Executing this controller's action from javascript's frontend
|
|
58
|
+
# this.url.go('/roles/new')
|
|
59
|
+
def new
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# @return [HTML] HTML view for editing the role
|
|
63
|
+
# @description returns an HTML view with a form so users edit an existing role
|
|
64
|
+
# @example
|
|
65
|
+
# # Executing this controller's action from javascript's frontend
|
|
66
|
+
# let role_id = 3;
|
|
67
|
+
# this.url.go(`/roles/${role_id}/edit`)
|
|
68
|
+
def edit
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# @return [Json] Json that contains wheter the creation of the role was successful or not.
|
|
72
|
+
# If it is not successful, it returns an error message
|
|
73
|
+
# @description Creates a new role associated to the *current_user*'s *account*.
|
|
74
|
+
# @example
|
|
75
|
+
# # Executing this controller's action from javascript's frontend
|
|
76
|
+
# let data = {
|
|
77
|
+
# role: {
|
|
78
|
+
# name: "Change Request"
|
|
79
|
+
# }
|
|
80
|
+
# };
|
|
81
|
+
# this.http.post('127.0.0.1/house/roles', data);
|
|
82
|
+
def create
|
|
83
|
+
|
|
84
|
+
role = RoleService.new(current_user).create(role_params)
|
|
85
|
+
|
|
86
|
+
if role.successful?
|
|
87
|
+
respond_with_successful(role.result)
|
|
88
|
+
else
|
|
89
|
+
respond_with_error(role.errors_as_sentence)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# @controller_action_param :name [String] The name of the role
|
|
94
|
+
# @return [Json] Json that contains wheter the role was successfully updated or not.
|
|
95
|
+
# If it it not successful, it returns an error message
|
|
96
|
+
# @description Updates an existing role associated to the *current_user*'s *account*.
|
|
97
|
+
def update
|
|
98
|
+
# Respond with 404 if role was not found
|
|
99
|
+
return respond_with_not_found unless @role.found?
|
|
100
|
+
|
|
101
|
+
# check if current user can work with role
|
|
102
|
+
unless current_user.can_work_with_role?(@role.resource)
|
|
103
|
+
return respond_with_error(I18n.t("core.roles.messages_danger_updating_role_object_level_permission_too_high"))
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Update role information
|
|
107
|
+
@role.update(role_params)
|
|
108
|
+
|
|
109
|
+
# check if the update went OK
|
|
110
|
+
unless @role.successful?
|
|
111
|
+
respond_with_error(@role.errors)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
respond_with_successful(@role)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# @return [Json] Json that contains wheter the role was successfully deleted or not.
|
|
118
|
+
# If it it not successful, it returns an error message
|
|
119
|
+
# @description Deletes an existing *role* associated to the *current_user*'s *account*.
|
|
120
|
+
def destroy
|
|
121
|
+
return respond_with_not_found unless @role.found?
|
|
122
|
+
|
|
123
|
+
# Validation: check if the role has still associated users
|
|
124
|
+
if @role.has_users?
|
|
125
|
+
return respond_with_error(I18n.t("core.roles.messages_danger_users_assigned_validation"))
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
@role.destroy
|
|
129
|
+
|
|
130
|
+
# Check if the deletion went ok
|
|
131
|
+
unless @role.successful?
|
|
132
|
+
return respond_with_error(@role.errors)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
respond_with_successful
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# @return [JSON]
|
|
139
|
+
# @description Gets all the specific options for roles CRUD
|
|
140
|
+
def options
|
|
141
|
+
respond_with_successful(RoleService.new(current_user).options)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
private
|
|
145
|
+
|
|
146
|
+
# @return [void]
|
|
147
|
+
# @description Sets the requested user based on the current_users's account
|
|
148
|
+
# @example
|
|
149
|
+
# # Executing this method from a controller action:
|
|
150
|
+
# set_role
|
|
151
|
+
# puts @role
|
|
152
|
+
# # This will either display nil or an instance of Role
|
|
153
|
+
def set_role
|
|
154
|
+
@role = RoleService.new(current_user, @query).find(params[:id])
|
|
155
|
+
return respond_with_not_found unless @role.found?
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# @return [Parameters] Allowed parameters for the role
|
|
159
|
+
# @description Sanitizes the parameters received from an HTTP call to only allow the specified ones.
|
|
160
|
+
# Allowed params are detail_attributes: [:name, :active, :object_level_permission]
|
|
161
|
+
# @example
|
|
162
|
+
# # suppose params contains {
|
|
163
|
+
# # "role": {
|
|
164
|
+
# # "name": "Admin",
|
|
165
|
+
# # "word": Hello
|
|
166
|
+
# # }
|
|
167
|
+
# #}
|
|
168
|
+
# filtered_params = role_params
|
|
169
|
+
# puts filtered_params
|
|
170
|
+
# # will remove all unpermitted attributes and only print {
|
|
171
|
+
# # "name": "Admin",
|
|
172
|
+
# #}
|
|
173
|
+
def role_params
|
|
174
|
+
params.fetch(:role, {}).permit(
|
|
175
|
+
:name,
|
|
176
|
+
:active,
|
|
177
|
+
:only_my_data,
|
|
178
|
+
:default_path,
|
|
179
|
+
:limit_to_path,
|
|
180
|
+
:object_level_permission
|
|
181
|
+
)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
end
|
|
185
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
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 LesliSecurity
|
|
34
|
+
class User::RolesController < ApplicationController
|
|
35
|
+
before_action :set_user, only: [:index, :create, :destroy]
|
|
36
|
+
before_action :set_user_role, only: [:destroy]
|
|
37
|
+
|
|
38
|
+
# Get the list of assigned roles of the requested user
|
|
39
|
+
# we filter the roles according to the object level permission
|
|
40
|
+
# of the current_user
|
|
41
|
+
def index
|
|
42
|
+
respond_with_successful(@user.available_roles)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def create
|
|
46
|
+
|
|
47
|
+
# get the role to assign to the user
|
|
48
|
+
role = current_user.account.roles.find(user_role_params[:id])
|
|
49
|
+
|
|
50
|
+
unless current_user.can_work_with_role?(role)
|
|
51
|
+
return respond_with_error(I18n.t("core.roles.messages_danger_cannot_assign_level_of_role"))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# create new role for user if it does not exist
|
|
55
|
+
user_role = @user.result.powers.with_deleted.find_or_create_by({ role: role })
|
|
56
|
+
|
|
57
|
+
# if role was soft deleted we need to recover it instead of create a new record
|
|
58
|
+
user_role.recover if user_role.deleted?
|
|
59
|
+
|
|
60
|
+
respond_with_successful()
|
|
61
|
+
|
|
62
|
+
#User.log_activity_create_user_role(current_user, @user, role)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# DELETE /user/:user_id/roles/:role_id
|
|
66
|
+
def destroy
|
|
67
|
+
|
|
68
|
+
# get the role to assign to the user
|
|
69
|
+
role = current_user.account.roles.find(@user_role.role.id)
|
|
70
|
+
|
|
71
|
+
unless current_user.can_work_with_role?(role)
|
|
72
|
+
return respond_with_error(I18n.t("core.roles.messages_danger_cannot_modify_role"))
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
@user_role.destroy
|
|
76
|
+
|
|
77
|
+
respond_with_successful()
|
|
78
|
+
|
|
79
|
+
#User.log_activity_destroy_user_role(current_user, @user, role)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
85
|
+
def set_user
|
|
86
|
+
@user = UserService.new(current_user).find(params[:user_id])
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def set_user_role
|
|
90
|
+
@user_role = @user.result.powers.find_by(:role_id => params[:id])
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Only allow a trusted parameter "white list" through.
|
|
94
|
+
def user_role_params
|
|
95
|
+
params.require(:user_role).permit(:id)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
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 LesliSecurity
|
|
34
|
+
class User::SessionsController < ApplicationController
|
|
35
|
+
before_action :set_user_session, only: [:destroy]
|
|
36
|
+
|
|
37
|
+
# GET /user/sessions
|
|
38
|
+
def index
|
|
39
|
+
respond_to do |format|
|
|
40
|
+
format.html {}
|
|
41
|
+
format.json do
|
|
42
|
+
return respond_with_pagination(UserService.new(current_user, query).sessions(session[:user_session_id]))
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# DELETE /user/sessions/1
|
|
48
|
+
def destroy
|
|
49
|
+
return respond_with_not_found unless @user_session
|
|
50
|
+
|
|
51
|
+
if @user_session.delete
|
|
52
|
+
current_user.logs.create({title: "close_session",description: "by_user: " + current_user.email})
|
|
53
|
+
respond_with_successful
|
|
54
|
+
else
|
|
55
|
+
respond_with_error(@user_session.errors.full_messages.to_sentence)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
62
|
+
def set_user_session
|
|
63
|
+
@user_session = User::Session.find_by(id: params[:id])
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Only allow a trusted parameter "white list" through.
|
|
67
|
+
def user_session_params
|
|
68
|
+
params.require(:user_session).permit(:id,)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|