lesli_guard 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +38 -0
- data/app/assets/config/lesli_guard_manifest.js +38 -0
- data/app/assets/images/lesli_guard/guard-logo.svg +160 -0
- data/app/assets/javascripts/lesli_guard/application.js +4787 -0
- data/app/assets/stylesheets/lesli_guard/application.scss +33 -0
- data/app/assets/stylesheets/lesli_guard/dashboards.scss +32 -0
- data/app/assets/stylesheets/lesli_guard/descriptors.scss +32 -0
- data/app/assets/stylesheets/lesli_guard/roles.scss +32 -0
- data/app/assets/stylesheets/lesli_guard/system_controller.scss +32 -0
- data/app/assets/stylesheets/lesli_guard/users.scss +67 -0
- data/app/controllers/lesli_guard/accounts_controller.rb +60 -0
- data/app/controllers/lesli_guard/application_controller.rb +37 -0
- data/app/controllers/lesli_guard/dashboard/components_controller.rb +60 -0
- data/app/controllers/lesli_guard/dashboards_controller.rb +36 -0
- data/app/controllers/lesli_guard/descriptor/activities_controller.rb +122 -0
- data/app/controllers/lesli_guard/descriptor/privileges_controller.rb +112 -0
- data/app/controllers/lesli_guard/descriptors_controller.rb +129 -0
- data/app/controllers/lesli_guard/role/activities_controller.rb +76 -0
- data/app/controllers/lesli_guard/role/descriptors_controller.rb +97 -0
- data/app/controllers/lesli_guard/role/privileges_controller.rb +47 -0
- data/app/controllers/lesli_guard/roles_controller.rb +185 -0
- data/app/controllers/lesli_guard/user/roles_controller.rb +98 -0
- data/app/controllers/lesli_guard/user/sessions_controller.rb +71 -0
- data/app/controllers/lesli_guard/users_controller.rb +206 -0
- data/app/helpers/lesli_guard/accounts_helper.rb +4 -0
- data/app/helpers/lesli_guard/application_helper.rb +4 -0
- data/app/helpers/lesli_guard/dashboards_helper.rb +4 -0
- data/app/helpers/lesli_guard/descriptor/activities_helper.rb +4 -0
- data/app/helpers/lesli_guard/descriptor/privileges_helper.rb +4 -0
- data/app/helpers/lesli_guard/descriptors_helper.rb +4 -0
- data/app/helpers/lesli_guard/role/activities_helper.rb +4 -0
- data/app/helpers/lesli_guard/role/descriptors_helper.rb +4 -0
- data/app/helpers/lesli_guard/role/privileges_helper.rb +4 -0
- data/app/helpers/lesli_guard/roles_helper.rb +4 -0
- data/app/jobs/lesli_guard/application_job.rb +37 -0
- data/app/mailers/lesli_guard/application_mailer.rb +39 -0
- data/app/models/lesli_guard/account.rb +43 -0
- data/app/models/lesli_guard/application_record.rb +37 -0
- data/app/models/lesli_guard/dashboard/component.rb +42 -0
- data/app/models/lesli_guard/dashboard.rb +58 -0
- data/app/models/lesli_guard/descriptor/activity.rb +40 -0
- data/app/models/lesli_guard/descriptor/privilege.rb +40 -0
- data/app/models/lesli_guard/descriptor.rb +41 -0
- data/app/models/lesli_guard/role/activity.rb +40 -0
- data/app/services/lesli_guard/descriptor_privilege_service.rb +74 -0
- data/app/services/lesli_guard/descriptor_service.rb +152 -0
- data/app/services/lesli_guard/role_descriptor_service.rb +61 -0
- data/app/services/lesli_guard/role_service.rb +215 -0
- data/app/services/lesli_guard/user_service.rb +305 -0
- data/app/views/lesli_guard/accounts/_account.html.erb +2 -0
- data/app/views/lesli_guard/accounts/_form.html.erb +17 -0
- data/app/views/lesli_guard/accounts/edit.html.erb +10 -0
- data/app/views/lesli_guard/accounts/index.html.erb +14 -0
- data/app/views/lesli_guard/accounts/new.html.erb +9 -0
- data/app/views/lesli_guard/accounts/show.html.erb +10 -0
- data/app/views/lesli_guard/dashboards/show.html.erb +1 -0
- data/app/views/lesli_guard/descriptor/activities/_form.html.erb +32 -0
- data/app/views/lesli_guard/descriptor/activities/edit.html.erb +34 -0
- data/app/views/lesli_guard/descriptor/activities/index.html.erb +34 -0
- data/app/views/lesli_guard/descriptor/activities/new.html.erb +34 -0
- data/app/views/lesli_guard/descriptor/activities/show.html.erb +34 -0
- data/app/views/lesli_guard/descriptor/privileges/_form.html.erb +32 -0
- data/app/views/lesli_guard/descriptor/privileges/edit.html.erb +34 -0
- data/app/views/lesli_guard/descriptor/privileges/index.html.erb +34 -0
- data/app/views/lesli_guard/descriptor/privileges/new.html.erb +34 -0
- data/app/views/lesli_guard/descriptor/privileges/show.html.erb +34 -0
- data/app/views/lesli_guard/descriptors/_form.html.erb +32 -0
- data/app/views/lesli_guard/descriptors/edit.html.erb +34 -0
- data/app/views/lesli_guard/descriptors/index.html.erb +34 -0
- data/app/views/lesli_guard/descriptors/new.html.erb +34 -0
- data/app/views/lesli_guard/descriptors/show.html.erb +34 -0
- data/app/views/lesli_guard/partials/_engine-navigation.html.erb +38 -0
- data/app/views/lesli_guard/role/activities/_form.html.erb +32 -0
- data/app/views/lesli_guard/role/activities/edit.html.erb +34 -0
- data/app/views/lesli_guard/role/activities/index.html.erb +34 -0
- data/app/views/lesli_guard/role/activities/new.html.erb +34 -0
- data/app/views/lesli_guard/role/activities/show.html.erb +34 -0
- data/app/views/lesli_guard/role/descriptors/_form.html.erb +32 -0
- data/app/views/lesli_guard/role/descriptors/edit.html.erb +34 -0
- data/app/views/lesli_guard/role/descriptors/index.html.erb +34 -0
- data/app/views/lesli_guard/role/descriptors/new.html.erb +34 -0
- data/app/views/lesli_guard/role/descriptors/show.html.erb +34 -0
- data/app/views/lesli_guard/role/privileges/_form.html.erb +32 -0
- data/app/views/lesli_guard/role/privileges/edit.html.erb +34 -0
- data/app/views/lesli_guard/role/privileges/index.html.erb +34 -0
- data/app/views/lesli_guard/role/privileges/new.html.erb +34 -0
- data/app/views/lesli_guard/role/privileges/show.html.erb +34 -0
- data/app/views/lesli_guard/roles/edit.html.erb +34 -0
- data/app/views/lesli_guard/roles/index.html.erb +34 -0
- data/app/views/lesli_guard/roles/new.html.erb +34 -0
- data/app/views/lesli_guard/roles/show.html.erb +34 -0
- data/app/views/lesli_guard/users/edit.html.erb +10 -0
- data/app/views/lesli_guard/users/index.html.erb +34 -0
- data/app/views/lesli_guard/users/new.html.erb +34 -0
- data/app/views/lesli_guard/users/show.html.erb +1 -0
- data/config/locales/translations.en.yml +43 -0
- data/config/locales/translations.es.yml +43 -0
- data/config/routes.rb +90 -0
- data/db/migrate/v1/0801000110_create_lesli_guard_accounts.rb +42 -0
- data/db/migrate/v1/0801050110_create_lesli_guard_dashboards.rb +51 -0
- data/db/migrate/v1/0801050210_create_lesli_guard_dashboard_components.rb +53 -0
- data/lib/lesli_guard/engine.rb +18 -0
- data/lib/lesli_guard/version.rb +4 -0
- data/lib/lesli_guard.rb +6 -0
- data/lib/tasks/lesli_guard_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 +107 -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 +98 -0
- data/lib/vue/stores/user.js +331 -0
- data/lib/vue/stores/users.js +176 -0
- data/license +674 -0
- data/readme.md +76 -0
- metadata +199 -0
@@ -0,0 +1,129 @@
|
|
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 LesliGuard
|
34
|
+
class DescriptorsController < ApplicationController
|
35
|
+
before_action :set_descriptor, only: %i[ show update destroy ]
|
36
|
+
|
37
|
+
# GET /descriptors/list.json
|
38
|
+
def list
|
39
|
+
respond_to do |format|
|
40
|
+
format.html {}
|
41
|
+
format.json do
|
42
|
+
respond_with_successful(DescriptorService.new(current_user, query).list)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# GET /descriptors
|
48
|
+
def index
|
49
|
+
respond_to do |format|
|
50
|
+
format.html {}
|
51
|
+
format.json do
|
52
|
+
#respond_with_successful(DescriptorService.new(current_user, query).index)
|
53
|
+
respond_with_pagination(DescriptorService.new(current_user, query).index)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# GET /descriptors/:id
|
59
|
+
def show
|
60
|
+
respond_to do |format|
|
61
|
+
format.html {}
|
62
|
+
format.json do
|
63
|
+
respond_with_successful(@descriptor.show)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# GET /descriptors/new
|
69
|
+
def new
|
70
|
+
end
|
71
|
+
|
72
|
+
# GET /descriptors/:id/edit
|
73
|
+
def edit
|
74
|
+
end
|
75
|
+
|
76
|
+
# POST /descriptors
|
77
|
+
def create
|
78
|
+
descriptor = DescriptorService.new(current_user, query).create(descriptor_params)
|
79
|
+
|
80
|
+
# Check if the creation went ok
|
81
|
+
if descriptor.successful?
|
82
|
+
respond_with_successful(descriptor)
|
83
|
+
else
|
84
|
+
respond_with_error(descriptor.errors)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# PATCH/PUT /descriptors/:id
|
89
|
+
def update
|
90
|
+
return respond_with_not_found unless @descriptor.found?
|
91
|
+
|
92
|
+
@descriptor.update(descriptor_params)
|
93
|
+
|
94
|
+
# Check if the update went ok
|
95
|
+
unless @descriptor.successful?
|
96
|
+
return respond_with_error(@descriptor.errors)
|
97
|
+
end
|
98
|
+
|
99
|
+
respond_with_successful(@descriptor.result)
|
100
|
+
end
|
101
|
+
|
102
|
+
# DELETE /descriptors/1
|
103
|
+
def destroy
|
104
|
+
return respond_with_not_found unless @descriptor.found?
|
105
|
+
|
106
|
+
@descriptor.destroy
|
107
|
+
|
108
|
+
# Check if the deletion went ok
|
109
|
+
unless @descriptor.successful?
|
110
|
+
return respond_with_error(@descriptor.errors)
|
111
|
+
end
|
112
|
+
|
113
|
+
respond_with_successful
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
# Use callbacks to share common setup or constraints between actions.
|
119
|
+
def set_descriptor
|
120
|
+
@descriptor = DescriptorService.new(current_user, @query).find(params[:id])
|
121
|
+
end
|
122
|
+
|
123
|
+
# Only allow a list of trusted parameters through.
|
124
|
+
def descriptor_params
|
125
|
+
params.require(:descriptor).permit(:id, :name)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
@@ -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 LesliGuard
|
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 LesliGuard
|
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 LesliGuard
|
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 LesliGuard
|
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 LesliGuard
|
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
|