lesli_admin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +5 -0
  3. data/app/assets/config/lesli_admin_manifest.js +38 -0
  4. data/app/assets/javascripts/lesli_admin/application.js +3713 -0
  5. data/app/assets/stylesheets/lesli_admin/application.css +15 -0
  6. data/app/controllers/lesli_admin/accounts_controller.rb +125 -0
  7. data/app/controllers/lesli_admin/application_controller.rb +4 -0
  8. data/app/controllers/lesli_admin/dashboards_controller.rb +60 -0
  9. data/app/controllers/lesli_admin/users_controller.rb +244 -0
  10. data/app/helpers/lesli_admin/application_helper.rb +4 -0
  11. data/app/helpers/lesli_admin/dashboards_helper.rb +4 -0
  12. data/app/jobs/lesli_admin/application_job.rb +4 -0
  13. data/app/mailers/lesli_admin/application_mailer.rb +6 -0
  14. data/app/models/lesli_admin/account.rb +66 -0
  15. data/app/models/lesli_admin/application_record.rb +5 -0
  16. data/app/models/lesli_admin/dashboard.rb +4 -0
  17. data/app/models/lesli_admin/user.rb +4 -0
  18. data/app/services/lesli_admin/user_service.rb +300 -0
  19. data/app/views/layouts/lesli_admin/application.html.erb +15 -0
  20. data/app/views/lesli_admin/accounts/_account.html.erb +2 -0
  21. data/app/views/lesli_admin/accounts/_form.html.erb +17 -0
  22. data/app/views/lesli_admin/accounts/edit.html.erb +10 -0
  23. data/app/views/lesli_admin/accounts/index.html.erb +34 -0
  24. data/app/views/lesli_admin/accounts/new.html.erb +9 -0
  25. data/app/views/lesli_admin/accounts/show.html.erb +34 -0
  26. data/app/views/lesli_admin/dashboards/_dashboard.html.erb +2 -0
  27. data/app/views/lesli_admin/dashboards/_form.html.erb +17 -0
  28. data/app/views/lesli_admin/dashboards/edit.html.erb +10 -0
  29. data/app/views/lesli_admin/dashboards/index.html.erb +14 -0
  30. data/app/views/lesli_admin/dashboards/new.html.erb +9 -0
  31. data/app/views/lesli_admin/dashboards/show.html.erb +1 -0
  32. data/app/views/lesli_admin/partials/_engine-navigation.html.erb +52 -0
  33. data/app/views/lesli_admin/users/edit.html.erb +10 -0
  34. data/app/views/lesli_admin/users/index.html.erb +34 -0
  35. data/app/views/lesli_admin/users/new.html.erb +34 -0
  36. data/app/views/lesli_admin/users/show.html.erb +10 -0
  37. data/config/routes.rb +13 -0
  38. data/lib/lesli_admin/engine.rb +18 -0
  39. data/lib/lesli_admin/version.rb +3 -0
  40. data/lib/lesli_admin.rb +6 -0
  41. data/lib/tasks/lesli_admin_tasks.rake +4 -0
  42. data/lib/vue/application.js +153 -0
  43. data/lib/vue/apps/account/components/address-form.vue +134 -0
  44. data/lib/vue/apps/account/components/contact-form.vue +162 -0
  45. data/lib/vue/apps/account/components/form-information.vue +107 -0
  46. data/lib/vue/apps/account/show.vue +89 -0
  47. data/lib/vue/apps/dashboard/show.vue +33 -0
  48. data/lib/vue/apps/profile/components/change-email.vue +38 -0
  49. data/lib/vue/apps/profile/components/subscriptions.vue +94 -0
  50. data/lib/vue/apps/profile/show.vue +141 -0
  51. data/lib/vue/apps/users/components/information-card.vue +119 -0
  52. data/lib/vue/apps/users/components/information-form.vue +180 -0
  53. data/lib/vue/apps/users/components/integrations-information.vue +61 -0
  54. data/lib/vue/apps/users/components/management-roles.vue +109 -0
  55. data/lib/vue/apps/users/components/management-security.vue +113 -0
  56. data/lib/vue/apps/users/components/management-sessions.vue +106 -0
  57. data/lib/vue/apps/users/components/management-settings.vue +94 -0
  58. data/lib/vue/apps/users/index.vue +201 -0
  59. data/lib/vue/apps/users/new.vue +181 -0
  60. data/lib/vue/apps/users/show.vue +101 -0
  61. data/lib/vue/stores/account.js +113 -0
  62. data/lib/vue/stores/accountSettings.js +342 -0
  63. data/lib/vue/stores/descriptor.js +116 -0
  64. data/lib/vue/stores/descriptors.js +167 -0
  65. data/lib/vue/stores/integration.js +103 -0
  66. data/lib/vue/stores/role.js +243 -0
  67. data/lib/vue/stores/roles.js +89 -0
  68. data/lib/vue/stores/systemController.js +67 -0
  69. data/lib/vue/stores/user.js +319 -0
  70. data/lib/vue/stores/users.js +150 -0
  71. data/readme.md +28 -0
  72. metadata +130 -0
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,125 @@
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 LesliAdmin
34
+ class AccountsController < ApplicationController
35
+ before_action :set_account, only: %i[show edit update destroy]
36
+
37
+ # GET /accounts/1
38
+ # GET /accounts/1.json
39
+ def show
40
+ respond_to do |format|
41
+ format.html {}
42
+ format.json do
43
+ set_account
44
+ respond_with_successful(@account)
45
+ end
46
+ end
47
+ end
48
+
49
+ # GET /accounts/new
50
+ def new
51
+ end
52
+
53
+ # GET /accounts/1/edit
54
+ def edit
55
+ end
56
+
57
+ # POST /accounts
58
+ # POST /accounts.json
59
+ def create
60
+ current_user.account.company_name = account_params[:company_name]
61
+ current_user.account.status = 'active'
62
+ current_user.account.save
63
+ if current_user.account.errors.any?
64
+ return respond_with_error(current_user.errors.full_messages.to_sentence)
65
+ end
66
+ respond_with_successful
67
+ end
68
+
69
+ # PATCH/PUT /accounts/1
70
+ # PATCH/PUT /accounts/1.json
71
+ def update
72
+ if @account.update(account_params)
73
+ respond_with_successful(@account)
74
+ else
75
+ respond_with_error(@account)
76
+ end
77
+ end
78
+
79
+ # DELETE /accounts/1
80
+ # DELETE /accounts/1.json
81
+ def destroy
82
+ return respond_with_not_found unless @account
83
+
84
+ @account.destroy
85
+ respond_to do |format|
86
+ format.html { redirect_to accounts_url, notice: 'Account was successfully destroyed.' }
87
+ format.json { head :no_content }
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ # Use callbacks to share common setup or constraints between actions.
94
+ def set_account
95
+ #@account = current_user.account
96
+ @account = Account.first
97
+ return respond_with_not_found unless @account
98
+ end
99
+
100
+ # Only allow a list of trusted parameters through.
101
+ def account_params
102
+ params.require(:account).permit(
103
+ :id,
104
+ :company_name,
105
+ :company_name_legal,
106
+ :company_tagline,
107
+ :country,
108
+ :city,
109
+ :postal_code,
110
+ :address,
111
+ :region,
112
+ :website,
113
+ :phone_number_1,
114
+ :public_email,
115
+ :github,
116
+ :twitter,
117
+ :youtube,
118
+ :linkedin,
119
+ :facebook,
120
+ :status,
121
+ :users_id
122
+ )
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,4 @@
1
+ module LesliAdmin
2
+ class ApplicationController < Lesli::ApplicationLesliController
3
+ end
4
+ end
@@ -0,0 +1,60 @@
1
+ module LesliAdmin
2
+ class DashboardsController < ApplicationController
3
+ #before_action :set_dashboard, only: %i[ show edit update destroy ]
4
+
5
+ # GET /dashboards
6
+ def index
7
+ @dashboards = Dashboard.all
8
+ end
9
+
10
+ # GET /dashboards/1
11
+ def show
12
+ end
13
+
14
+ # GET /dashboards/new
15
+ def new
16
+ @dashboard = Dashboard.new
17
+ end
18
+
19
+ # GET /dashboards/1/edit
20
+ def edit
21
+ end
22
+
23
+ # POST /dashboards
24
+ def create
25
+ @dashboard = Dashboard.new(dashboard_params)
26
+
27
+ if @dashboard.save
28
+ redirect_to @dashboard, notice: "Dashboard was successfully created."
29
+ else
30
+ render :new, status: :unprocessable_entity
31
+ end
32
+ end
33
+
34
+ # PATCH/PUT /dashboards/1
35
+ def update
36
+ if @dashboard.update(dashboard_params)
37
+ redirect_to @dashboard, notice: "Dashboard was successfully updated.", status: :see_other
38
+ else
39
+ render :edit, status: :unprocessable_entity
40
+ end
41
+ end
42
+
43
+ # DELETE /dashboards/1
44
+ def destroy
45
+ @dashboard.destroy
46
+ redirect_to dashboards_url, notice: "Dashboard was successfully destroyed.", status: :see_other
47
+ end
48
+
49
+ private
50
+ # Use callbacks to share common setup or constraints between actions.
51
+ def set_dashboard
52
+ @dashboard = Dashboard.find(params[:id])
53
+ end
54
+
55
+ # Only allow a list of trusted parameters through.
56
+ def dashboard_params
57
+ params.fetch(:dashboard, {})
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,244 @@
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 LesliAdmin
34
+ class UsersController < ApplicationController
35
+ before_action :set_user, only: [
36
+ :show,
37
+ :update,
38
+ :destroy,
39
+ :requestpassword,
40
+ :passwordreset,
41
+ :revokeaccess,
42
+ :logout
43
+ ]
44
+
45
+ # GET /users/list
46
+ def list
47
+ respond_to do |format|
48
+ format.json { respond_with_successful(UserService.new("current_user").list(query, params)) }
49
+ end
50
+ end
51
+
52
+ # GET /users
53
+ def index
54
+ respond_to do |format|
55
+ format.html { }
56
+ format.json {
57
+ return respond_with_pagination(UserService.new("current_user").index(query, params))
58
+ }
59
+ end
60
+ end
61
+
62
+ def show
63
+ respond_to do |format|
64
+ format.html {}
65
+ format.json {
66
+ return respond_with_not_found unless @user.found?
67
+ return respond_with_successful(@user.show)
68
+ }
69
+ end
70
+ end
71
+
72
+ def new; end
73
+
74
+ def create
75
+
76
+ user = UserService.new(current_user).create(user_params)
77
+ if user.successful?
78
+ respond_with_successful(user.result)
79
+ else
80
+ respond_with_error("Error creating user", user.errors)
81
+ end
82
+
83
+ end
84
+
85
+ def update
86
+
87
+ # validate that user exists
88
+ return respond_with_not_found unless @user.found?
89
+
90
+ @user.update(user_params)
91
+
92
+ if @user.successful?
93
+ respond_with_successful(@user.result)
94
+ else
95
+ respond_with_error(@user.errors)
96
+ end
97
+
98
+ end
99
+
100
+ def destroy
101
+ return respond_with_not_found unless @user
102
+
103
+ # get the user found in the UserServices
104
+ user = @user.result
105
+
106
+ if user.delete
107
+ current_user.logs.create({ title: "deleted_user", description: "by_user_id: #{ current_user.email }" })
108
+ respond_with_successful()
109
+ else
110
+ respond_with_error(user.errors.full_messages.to_sentence)
111
+ end
112
+ end
113
+
114
+ # Force the user to update his password
115
+ def requestpassword
116
+ if @user.request_password
117
+ respond_with_successful
118
+ else
119
+ respond_with_error
120
+ end
121
+ end
122
+
123
+ # Reset password (generate random)
124
+ def passwordreset
125
+
126
+ pass = @user.password_reset
127
+
128
+ if pass
129
+ respond_with_successful(pass)
130
+ else
131
+ respond_with_error
132
+ end
133
+ end
134
+
135
+ # this method is going to close all the open user sessions
136
+ def logout
137
+ if @user.logout
138
+ respond_with_successful
139
+ else
140
+ respond_with_error
141
+ end
142
+ end
143
+
144
+ # Remove all user access
145
+ def revokeaccess
146
+ if @user.revoke_access
147
+ respond_with_successful
148
+ else
149
+ respond_with_error
150
+ end
151
+ end
152
+
153
+ def become
154
+
155
+ # always should be disabled
156
+ if Rails.configuration.lesli.dig(:security, :enable_becoming) != true
157
+ return respond_with_unauthorized
158
+ end
159
+
160
+ # Allow only sysadmin to become as user
161
+ return respond_with_unauthorized if current_user.email != Rails.application.config.lesli.dig(:account, :user, :email) # sysadmin user
162
+
163
+ # Search for desire user
164
+ becoming_user = User.find(params[:id])
165
+
166
+ # Return an error if user does not exist
167
+ return respond_with_error I18n.t("core.shared.messages_warning_user_not_found") if becoming_user.blank?
168
+
169
+ # Extrictly save a log when becoming
170
+ current_user.activities.create!({
171
+ users_id: becoming_user.id,
172
+ owner_id: current_user.id,
173
+ description: "#{current_user.full_name} -> #{becoming_user.full_name}",
174
+ category: "action_become"
175
+ })
176
+
177
+ # Sign in as the becoming user
178
+ sign_in(:user, becoming_user)
179
+
180
+ # Create a new session for the becoming user
181
+ becoming_session = becoming_user.sessions.create({
182
+ :user_agent => get_user_agent,
183
+ :user_remote => request.remote_ip,
184
+ :session_source => "become_session",
185
+ :last_used_at => LC::Date.now,
186
+ :expiration_at => 60.minutes.from_now
187
+ })
188
+
189
+ # assign the session of the becomer user to the becoming user
190
+ session[:user_session_id] = becoming_session[:id]
191
+
192
+ # Response successful
193
+ respond_with_successful([current_user, becoming_user])
194
+
195
+ end
196
+
197
+ def options
198
+ respond_with_successful({
199
+ #regions: current_user.account.locations.where(level: "region"),
200
+ salutations: User::Detail.salutations.map {|k, v| {value: k, text: v}},
201
+ locales: Rails.application.config.lesli.dig(:configuration, :locales_available),
202
+ mfa_methods: Rails.application.config.lesli.dig(:configuration, :mfa_methods)
203
+ })
204
+ end
205
+
206
+ private
207
+
208
+ # @return [void]
209
+ # @description Sets the requested user based on the current_users's account
210
+ # @example
211
+ # # Executing this method from a controller action:
212
+ # set_user
213
+ # puts @user
214
+ # # This will either display nil or an instance of Account::User
215
+ def set_user
216
+ @user = UserService.new(current_user).find(params[:id])
217
+ end
218
+
219
+ def user_params
220
+ params.require(:user).permit(
221
+ :active,
222
+ :email,
223
+ :alias,
224
+ :roles_id,
225
+ :first_name,
226
+ :last_name,
227
+ :telephone,
228
+ detail_attributes: [
229
+ :title,
230
+ :salutation,
231
+ :address,
232
+ :work_city,
233
+ :work_region,
234
+ :work_address
235
+ ]
236
+ )
237
+ end
238
+
239
+ # Only allow a list of trusted parameters through.
240
+ def user_params
241
+ params.fetch(:user, {})
242
+ end
243
+ end
244
+ end
@@ -0,0 +1,4 @@
1
+ module LesliAdmin
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module LesliAdmin
2
+ module DashboardsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module LesliAdmin
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module LesliAdmin
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -0,0 +1,66 @@
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.dev
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module LesliAdmin
34
+ class Account < Lesli::Account
35
+
36
+ # accounts always belongs to a user
37
+ belongs_to :user, optional: true
38
+
39
+ # account resources
40
+ has_many :users
41
+
42
+ has_one :bell, class_name: "LesliBell::Account"
43
+
44
+
45
+
46
+ # account statuses
47
+ enum status: [
48
+ :registered,
49
+ :onboarding,
50
+ :active,
51
+ :suspended
52
+ ]
53
+
54
+
55
+ # company region (GDPR)
56
+ enum region: {
57
+ latin_america: "latin_america",
58
+ united_states: "united_states",
59
+ european_union: "european_union"
60
+ }
61
+
62
+
63
+ # required a name for the lesli account
64
+ validates :company_name, :presence => true
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ module LesliAdmin
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module LesliAdmin
2
+ class Dashboard < ApplicationRecord
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module LesliAdmin
2
+ class User < ::Lesli::User
3
+ end
4
+ end