lesli_shield 1.1.9 → 1.1.10

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/lesli_shield/login-background.webp +0 -0
  3. data/app/assets/images/lesli_shield/register-background.webp +0 -0
  4. data/app/assets/stylesheets/lesli_shield/application.css +23 -28
  5. data/app/assets/stylesheets/lesli_shield/invitations.css +1 -1
  6. data/app/assets/stylesheets/lesli_shield/registrations.css +35 -10
  7. data/app/assets/stylesheets/lesli_shield/sessions.css +1 -1
  8. data/app/controllers/lesli_shield/profile/passwords_controller.rb +0 -2
  9. data/app/controllers/lesli_shield/profiles_controller.rb +0 -1
  10. data/app/controllers/lesli_shield/user/roles_controller.rb +35 -59
  11. data/app/controllers/lesli_shield/users_controller.rb +4 -2
  12. data/app/controllers/users/registrations_controller.rb +27 -0
  13. data/app/controllers/users/sessions_controller.rb +11 -0
  14. data/app/interfaces/lesli_shield/security_interface.rb +146 -0
  15. data/app/models/concerns/lesli_shield/user_authentication.rb +0 -29
  16. data/app/models/concerns/lesli_shield/user_legal_acceptance.rb +45 -0
  17. data/app/models/concerns/lesli_shield/user_security.rb +23 -14
  18. data/app/services/lesli_shield/user_role_service.rb +37 -0
  19. data/app/services/lesli_shield/user_validator_service.rb +6 -28
  20. data/app/views/devise/registrations/_terms.html.erb +34 -0
  21. data/app/views/devise/registrations/new.html.erb +3 -5
  22. data/app/views/devise/sessions/new.html.erb +2 -1
  23. data/app/views/lesli_shield/partials/_navigation.html.erb +5 -5
  24. data/app/views/lesli_shield/roles/show.html.erb +40 -50
  25. data/app/views/lesli_shield/user/roles/index.html.erb +1 -16
  26. data/app/views/lesli_shield/users/_management-privileges.html.erb +74 -68
  27. data/app/views/lesli_shield/users/show.html.erb +1 -1
  28. data/config/locales/translations.en.yml +8 -1
  29. data/config/locales/translations.es.yml +8 -1
  30. data/config/locales/user_roles.en.yml +16 -0
  31. data/config/locales/user_roles.es.yml +16 -0
  32. data/config/routes.rb +1 -1
  33. data/lib/lesli_shield/engine.rb +4 -0
  34. data/lib/lesli_shield/version.rb +1 -1
  35. metadata +10 -6
  36. data/app/assets/images/lesli_shield/login-background.jpg +0 -0
  37. data/app/assets/images/lesli_shield/register-background.jpg +0 -0
  38. data/app/interfaces/lesli_shield/authentication_interface.rb +0 -64
  39. data/app/interfaces/lesli_shield/authorization_interface.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2709d93da10db9d66649835d7ad6264933a2b4c22020b294dab6730c3344d640
4
- data.tar.gz: 81b28aae6c12c81f927b2500a2c50473324e9ccb0902c93ff1dbf7369967002a
3
+ metadata.gz: 7666d70ba185bd6a7c0b675651750a7159285f13d1023999ca3b81e02c1b445a
4
+ data.tar.gz: db43aea6eae8ae60daf8578b69732022fda34ab593e4bc23aa70fa41443627bf
5
5
  SHA512:
6
- metadata.gz: 905b6789cf92f1254faa9b9d363eb49d55f41e2ac897f2116de1c3441998a77fc21e576f610dd16edce097b674456dbb7b2e7cf15a2a03fe3d6e9575baeaeb81
7
- data.tar.gz: 5c519043f3e10f9fae14adc725f8875e3976f5d4f35a4552437192be9a216df6e3037cc5100cce206d21575f37ea7e5aaac86fcda95eea5e5f694ccf5639f77d
6
+ metadata.gz: 93401775e251fd8220bd874fdea10d20cce089d60c5e863f95cdca7170475386a7a7b144c3ebc322e1094955e94f8ecbf04289a97c19a21f9f36dec75eb28004
7
+ data.tar.gz: 720b5e0f982d1845d75bb79ba06415b88721bc9d7a19c87c933b1d2572ffaa64ccfd85bee7debbff38c4da844ee919dace84394ba304ffed22c4377071755f81
@@ -79,6 +79,9 @@
79
79
  .mb-1\.5 {
80
80
  margin-bottom: calc(var(--spacing, 0.25rem) * 1.5);
81
81
  }
82
+ .mb-3 {
83
+ margin-bottom: calc(var(--spacing, 0.25rem) * 3);
84
+ }
82
85
  .mb-4 {
83
86
  margin-bottom: calc(var(--spacing, 0.25rem) * 4);
84
87
  }
@@ -183,9 +186,6 @@
183
186
  --tw-translate-y: calc(calc(1 / 2 * 100%) * -1);
184
187
  translate: var(--tw-translate-x) var(--tw-translate-y);
185
188
  }
186
- .transform {
187
- transform: var(--tw-rotate-x, ) var(--tw-rotate-y, ) var(--tw-rotate-z, ) var(--tw-skew-x, ) var(--tw-skew-y, );
188
- }
189
189
  .cursor-not-allowed {
190
190
  cursor: not-allowed;
191
191
  }
@@ -219,6 +219,9 @@
219
219
  .items-center {
220
220
  align-items: center;
221
221
  }
222
+ .items-end {
223
+ align-items: flex-end;
224
+ }
222
225
  .items-start {
223
226
  align-items: flex-start;
224
227
  }
@@ -269,6 +272,11 @@
269
272
  margin-block-start: calc(calc(var(--spacing, 0.25rem) * 6) * var(--tw-space-y-reverse));
270
273
  margin-block-end: calc(calc(var(--spacing, 0.25rem) * 6) * calc(1 - var(--tw-space-y-reverse)));
271
274
  }
275
+ :where(.space-y-8 > :not(:last-child)) {
276
+ --tw-space-y-reverse: 0;
277
+ margin-block-start: calc(calc(var(--spacing, 0.25rem) * 8) * var(--tw-space-y-reverse));
278
+ margin-block-end: calc(calc(var(--spacing, 0.25rem) * 8) * calc(1 - var(--tw-space-y-reverse)));
279
+ }
272
280
  .gap-x-4 {
273
281
  column-gap: calc(var(--spacing, 0.25rem) * 4);
274
282
  }
@@ -408,6 +416,9 @@
408
416
  .p-5 {
409
417
  padding: calc(var(--spacing, 0.25rem) * 5);
410
418
  }
419
+ .p-6 {
420
+ padding: calc(var(--spacing, 0.25rem) * 6);
421
+ }
411
422
  .px-2 {
412
423
  padding-inline: calc(var(--spacing, 0.25rem) * 2);
413
424
  }
@@ -426,6 +437,9 @@
426
437
  .px-6 {
427
438
  padding-inline: calc(var(--spacing, 0.25rem) * 6);
428
439
  }
440
+ .py-0\.5 {
441
+ padding-block: calc(var(--spacing, 0.25rem) * 0.5);
442
+ }
429
443
  .py-1 {
430
444
  padding-block: var(--spacing, 0.25rem);
431
445
  }
@@ -850,6 +864,9 @@
850
864
  .sm\:grid-cols-2 {
851
865
  grid-template-columns: repeat(2, minmax(0, 1fr));
852
866
  }
867
+ .sm\:grid-cols-\[minmax\(0\,1fr\)_auto\] {
868
+ grid-template-columns: minmax(0,1fr) auto;
869
+ }
853
870
  .sm\:flex-row {
854
871
  flex-direction: row;
855
872
  }
@@ -971,6 +988,9 @@
971
988
  vertical-align: middle;
972
989
  }
973
990
  }
991
+ .\[\&_\.lesli-form-field\]\:mb-0 .lesli-form-field {
992
+ margin-bottom: 0px;
993
+ }
974
994
  .\[\&\:\:-webkit-details-marker\]\:hidden::-webkit-details-marker {
975
995
  display: none;
976
996
  }
@@ -990,26 +1010,6 @@
990
1010
  inherits: false;
991
1011
  initial-value: 0;
992
1012
  }
993
- @property --tw-rotate-x {
994
- syntax: "*";
995
- inherits: false;
996
- }
997
- @property --tw-rotate-y {
998
- syntax: "*";
999
- inherits: false;
1000
- }
1001
- @property --tw-rotate-z {
1002
- syntax: "*";
1003
- inherits: false;
1004
- }
1005
- @property --tw-skew-x {
1006
- syntax: "*";
1007
- inherits: false;
1008
- }
1009
- @property --tw-skew-y {
1010
- syntax: "*";
1011
- inherits: false;
1012
- }
1013
1013
  @property --tw-space-y-reverse {
1014
1014
  syntax: "*";
1015
1015
  inherits: false;
@@ -1113,11 +1113,6 @@
1113
1113
  --tw-translate-x: 0;
1114
1114
  --tw-translate-y: 0;
1115
1115
  --tw-translate-z: 0;
1116
- --tw-rotate-x: initial;
1117
- --tw-rotate-y: initial;
1118
- --tw-rotate-z: initial;
1119
- --tw-skew-x: initial;
1120
- --tw-skew-y: initial;
1121
1116
  --tw-space-y-reverse: 0;
1122
1117
  --tw-divide-y-reverse: 0;
1123
1118
  --tw-border-style: solid;
@@ -374,7 +374,7 @@
374
374
  }
375
375
  @layer components {
376
376
  .lesli-auth-visual {
377
- background: linear-gradient( 0deg, rgb(49 106 255 / 40%), rgb(49 106 255 / 40%) ), url("/lesli_shield/register-background.jpg");
377
+ background: linear-gradient(0deg, rgba(49, 106, 255, 0.4), rgba(49, 106, 255, 0.4)), url("/lesli_shield/register-background.webp");
378
378
  background-position: center;
379
379
  background-size: cover;
380
380
  }
@@ -20,11 +20,14 @@
20
20
  .mx-auto {
21
21
  margin-inline: auto;
22
22
  }
23
+ .my-6 {
24
+ margin-block: calc(var(--spacing, 0.25rem) * 6);
25
+ }
23
26
  .mt-1 {
24
27
  margin-top: var(--spacing, 0.25rem);
25
28
  }
26
- .mb-4 {
27
- margin-bottom: calc(var(--spacing, 0.25rem) * 4);
29
+ .mt-3 {
30
+ margin-top: calc(var(--spacing, 0.25rem) * 3);
28
31
  }
29
32
  .mb-6 {
30
33
  margin-bottom: calc(var(--spacing, 0.25rem) * 6);
@@ -41,6 +44,10 @@
41
44
  .inline-flex {
42
45
  display: inline-flex;
43
46
  }
47
+ .size-4 {
48
+ width: calc(var(--spacing, 0.25rem) * 4);
49
+ height: calc(var(--spacing, 0.25rem) * 4);
50
+ }
44
51
  .h-5 {
45
52
  height: calc(var(--spacing, 0.25rem) * 5);
46
53
  }
@@ -74,18 +81,30 @@
74
81
  .flex-1 {
75
82
  flex: 1;
76
83
  }
84
+ .shrink-0 {
85
+ flex-shrink: 0;
86
+ }
87
+ .cursor-pointer {
88
+ cursor: pointer;
89
+ }
77
90
  .flex-col {
78
91
  flex-direction: column;
79
92
  }
80
93
  .items-center {
81
94
  align-items: center;
82
95
  }
96
+ .items-start {
97
+ align-items: flex-start;
98
+ }
83
99
  .justify-center {
84
100
  justify-content: center;
85
101
  }
86
102
  .gap-2 {
87
103
  gap: calc(var(--spacing, 0.25rem) * 2);
88
104
  }
105
+ .gap-3 {
106
+ gap: calc(var(--spacing, 0.25rem) * 3);
107
+ }
89
108
  .overflow-hidden {
90
109
  overflow: hidden;
91
110
  }
@@ -151,14 +170,14 @@
151
170
  font-size: var(--text-xs, 0.75rem);
152
171
  line-height: var(--tw-leading, var(--text-xs--line-height, calc(1 / 0.75)));
153
172
  }
154
- .leading-5 {
155
- --tw-leading: calc(var(--spacing, 0.25rem) * 5);
156
- line-height: calc(var(--spacing, 0.25rem) * 5);
157
- }
158
173
  .leading-6 {
159
174
  --tw-leading: calc(var(--spacing, 0.25rem) * 6);
160
175
  line-height: calc(var(--spacing, 0.25rem) * 6);
161
176
  }
177
+ .leading-relaxed {
178
+ --tw-leading: var(--leading-relaxed, 1.625);
179
+ line-height: var(--leading-relaxed, 1.625);
180
+ }
162
181
  .leading-tight {
163
182
  --tw-leading: var(--leading-tight, 1.25);
164
183
  line-height: var(--leading-tight, 1.25);
@@ -178,9 +197,6 @@
178
197
  .text-\[var\(--lesli-color-primary\)\] {
179
198
  color: var(--lesli-color-primary);
180
199
  }
181
- .text-neutral-500 {
182
- color: var(--lesli-color-neutral-500);
183
- }
184
200
  .text-neutral-600 {
185
201
  color: var(--lesli-color-neutral-600);
186
202
  }
@@ -199,6 +215,9 @@
199
215
  .underline-offset-2 {
200
216
  text-underline-offset: 2px;
201
217
  }
218
+ .accent-primary {
219
+ accent-color: var(--lesli-color-primary);
220
+ }
202
221
  .transition {
203
222
  transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter, display, content-visibility, overlay, pointer-events;
204
223
  transition-timing-function: var(--tw-ease, var(--default-transition-timing-function, cubic-bezier(0.4, 0, 0.2, 1)));
@@ -240,9 +259,15 @@
240
259
  .focus-visible\:outline-offset-2:focus-visible {
241
260
  outline-offset: 2px;
242
261
  }
262
+ .focus-visible\:outline-offset-4:focus-visible {
263
+ outline-offset: 4px;
264
+ }
243
265
  .focus-visible\:outline-\[var\(--lesli-color-primary\)\]:focus-visible {
244
266
  outline-color: var(--lesli-color-primary);
245
267
  }
268
+ .focus-visible\:outline-primary:focus-visible {
269
+ outline-color: var(--lesli-color-primary);
270
+ }
246
271
  @media (width >= 40rem) {
247
272
  .sm\:px-10 {
248
273
  padding-inline: calc(var(--spacing, 0.25rem) * 10);
@@ -271,7 +296,7 @@
271
296
  }
272
297
  @layer components {
273
298
  .lesli-auth-visual {
274
- background: linear-gradient( 0deg, rgb(49 106 255 / 40%), rgb(49 106 255 / 40%) ), url("/lesli_shield/register-background.jpg");
299
+ background: linear-gradient(0deg, rgba(49, 106, 255, 0.4), rgba(49, 106, 255, 0.4)), url("/lesli_shield/register-background.webp");
275
300
  background-position: center;
276
301
  background-size: cover;
277
302
  }
@@ -354,7 +354,7 @@
354
354
  font-family: "Domine", "OpenSans", sans-serif;
355
355
  }
356
356
  .lesli-auth-visual {
357
- background: linear-gradient(0deg, rgba(49, 106, 255, 0.4), rgba(49, 106, 255, 0.4)), url("/lesli_shield/login-background.jpg");
357
+ background: linear-gradient(0deg, rgba(49, 106, 255, 0.4), rgba(49, 106, 255, 0.4)), url("/lesli_shield/login-background.webp");
358
358
  background-position: center;
359
359
  background-size: cover;
360
360
  }
@@ -3,8 +3,6 @@ module LesliShield
3
3
  class PasswordsController < ApplicationController
4
4
  PASSWORD_CHANGE_RATE_LIMIT_WINDOW = 15.minutes
5
5
 
6
- skip_before_action :authorize_request
7
-
8
6
  rate_limit(
9
7
  to: 10,
10
8
  within: PASSWORD_CHANGE_RATE_LIMIT_WINDOW,
@@ -12,7 +12,6 @@ module LesliShield
12
12
  time_zone
13
13
  ].freeze
14
14
 
15
- skip_before_action :authorize_request
16
15
  before_action :set_profile
17
16
 
18
17
  def show
@@ -1,62 +1,38 @@
1
1
  module LesliShield
2
- class User::RolesController < ApplicationController
3
- before_action :set_user_role, only: %i[ show edit update destroy ]
4
-
5
- # GET /user/roles
6
- def index
7
- @user_roles = User::Role.all
8
- end
9
-
10
- # GET /user/roles/1
11
- def show
12
- end
13
-
14
- # GET /user/roles/new
15
- def new
16
- @user_role = User::Role.new
17
- end
18
-
19
- # GET /user/roles/1/edit
20
- def edit
21
- end
22
-
23
- # POST /user/roles
24
- def create
25
- # @user_role = User::Role.new(user_role_params)
26
-
27
- # if @user_role.save
28
- # redirect_to @user_role, notice: "Role was successfully created."
29
- # else
30
- # render :new, status: :unprocessable_content
31
- # end
32
- end
33
-
34
- # PATCH/PUT /user/roles/1
35
- def update
36
- # if @user_role.update(user_role_params)
37
- # redirect_to @user_role, notice: "Role was successfully updated.", status: :see_other
38
- # else
39
- # render :edit, status: :unprocessable_content
40
- # end
2
+ class User::RolesController < ApplicationController
3
+ before_action :set_user
4
+
5
+ def index
6
+ prepare_roles
7
+ end
8
+
9
+ def create
10
+ role_service.create(params.require(:user_role).require(:role_id))
11
+ redirect_to user_roles_path(@user), status: :see_other
12
+ rescue ActiveRecord::RecordInvalid => error
13
+ @role_error = error.record.errors.full_messages.to_sentence
14
+ prepare_roles
15
+ render :index, formats: [:html], status: :unprocessable_entity
16
+ end
17
+
18
+ def destroy
19
+ role_service.destroy(params[:id])
20
+ redirect_to user_roles_path(@user), status: :see_other
21
+ end
22
+
23
+ private
24
+
25
+ def set_user
26
+ @user = current_user.account.users.find(params[:user_id])
27
+ end
28
+
29
+ def role_service
30
+ @role_service ||= UserRoleService.new(current_user, @user)
31
+ end
32
+
33
+ def prepare_roles
34
+ @user_roles = role_service.index
35
+ @available_roles = role_service.list
36
+ end
41
37
  end
42
-
43
- # DELETE /user/roles/1
44
- def destroy
45
- @user_role.destroy!
46
- redirect_to user_roles_path, notice: "Role 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_user_role
52
- @user_role = User::Role.find(params.expect(:id))
53
- end
54
-
55
- # Only allow a list of trusted parameters through.
56
- def user_role_params
57
- params.require(:user_role).permit(
58
- :role_id
59
- )
60
- end
61
- end
62
38
  end
@@ -42,11 +42,13 @@ module LesliShield
42
42
  # GET /users/1
43
43
  def show
44
44
  @user = @user.show
45
- @user_roles = @user.roles
45
+ role_service = UserRoleService.new(current_user, @user)
46
+ @user_roles = role_service.index
47
+ @available_roles = role_service.list
46
48
  @sessions = @user.sessions
47
49
  @activities = if defined?(LesliAudit)
48
50
  @user.logs.order(id: :desc)
49
- .select(:id, :operation, :description, Lesli::Date2.new.db_column("created_at", as: "date"))
51
+ .select(:id, :operation, :description, Date2.new.db_column("created_at", as: "date"))
50
52
  .limit(7).as_json
51
53
  else
52
54
  []
@@ -36,6 +36,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
36
36
  REGISTRATION_RATE_LIMIT_WINDOW = 1.hour
37
37
 
38
38
  before_action :ensure_registration_allowed!, only: %i[new create]
39
+ before_action :ensure_registration_terms_configured!, only: %i[new create]
39
40
 
40
41
  rate_limit(
41
42
  to: 10,
@@ -65,6 +66,20 @@ class Users::RegistrationsController < Devise::RegistrationsController
65
66
 
66
67
  protected
67
68
 
69
+ def sign_up_params
70
+ attributes = super
71
+ return attributes unless Lesli.config.shield[:require_terms_acceptance]
72
+
73
+ attributes.merge(params.require(resource_name).permit(
74
+ :terms_accepted, :terms_version, :privacy_version
75
+ ))
76
+ end
77
+
78
+ def build_resource(attributes = {})
79
+ super
80
+ resource.legal_acceptance_required = Lesli.config.shield[:require_terms_acceptance]
81
+ end
82
+
68
83
  # Standalone registrations remain inactive until confirmation creates the
69
84
  # account and role. Preserve the existing UX by returning to the form with
70
85
  # Devise's success notice instructing the user to check their email.
@@ -74,6 +89,18 @@ class Users::RegistrationsController < Devise::RegistrationsController
74
89
 
75
90
  private
76
91
 
92
+ def ensure_registration_terms_configured!
93
+ return unless Lesli.config.shield[:require_terms_acceptance]
94
+
95
+ # An incomplete host configuration is a developer error, not an
96
+ # acceptance of empty versions or links to documents that do not exist.
97
+ %i[terms_url terms_version privacy_url privacy_version].each do |key|
98
+ next if Lesli.config.shield[key].present?
99
+
100
+ raise ArgumentError, "config.shield[:#{key}] is required when require_terms_acceptance is enabled"
101
+ end
102
+ end
103
+
77
104
  def ensure_registration_allowed!
78
105
  return if Lesli.config.security.dig(:allow_registration)
79
106
 
@@ -59,6 +59,7 @@ class Users::SessionsController < Devise::SessionsController
59
59
  # without reimplementing Devise's create action.
60
60
  def create
61
61
  super do |user|
62
+ validate_login_user!(user)
62
63
  persist_application_session!(user)
63
64
  record_successful_login_analytics
64
65
  # Devise sets the successful-login notice before yielding.
@@ -77,6 +78,16 @@ class Users::SessionsController < Devise::SessionsController
77
78
 
78
79
  private
79
80
 
81
+ # Shield's account, active-user and role rules run only during login.
82
+ # Devise has already signed in the user before yielding to our create block.
83
+ def validate_login_user!(user)
84
+ return if LesliShield::UserValidatorService.new(user).validate.valid?
85
+
86
+ flash.delete(:notice)
87
+ rollback_web_session
88
+ throw(:warden, auth_options.merge(message: :invalid))
89
+ end
90
+
80
91
  # Devise has already established the web session when its create action
81
92
  # yields. If either mandatory write fails, remove that session so the request
82
93
  # cannot leave a partially completed login behind.
@@ -0,0 +1,146 @@
1
+ =begin
2
+
3
+ Lesli
4
+
5
+ Copyright (c) 2026, Lesli Technologies, S. A.
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see http://www.gnu.org/licenses/.
19
+
20
+ Lesli · Ruby on Rails SaaS Development Framework.
21
+
22
+ Made with ♥ by LesliTech
23
+ Building a better future, one line of code at a time.
24
+
25
+ @contact hello@lesli.tech
26
+ @website https://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module LesliShield
34
+ module SecurityInterface
35
+
36
+ def set_privileges(&action)
37
+ if current_user
38
+ current_user.with_privileges(&action)
39
+ else
40
+ action.call
41
+ end
42
+ end
43
+
44
+ # Validate user authentication and session status
45
+ def authenticate_request
46
+
47
+ # this version Lesli requires to be mounted as root "/"
48
+ # engine_path = Lesli::Engine.routes.find_script_name({})
49
+ engine_path = nil
50
+
51
+ # check if the users is logged into the system
52
+ unless user_signed_in?()
53
+
54
+ message = "Please Login to view that page!"
55
+
56
+ # check if requested url is valid
57
+ if (request.get? && is_navigational_format? && !request.xhr? && !request.fullpath.blank?)
58
+
59
+ # redirect only if the path worth it
60
+ if request.fullpath != "/"
61
+
62
+ # redirect with requested url, so user will be redirected after login
63
+ redirect_to("#{engine_path}/login?r=#{request.fullpath}", notice: message) and return
64
+
65
+ end
66
+
67
+ end
68
+
69
+ # redirect to root route
70
+ redirect_to("#{engine_path}/login", notice: message) and return
71
+
72
+ end
73
+
74
+ # run aditinal validations only for html requests
75
+ return true unless request.format.html?
76
+
77
+ # # get the current user session
78
+ # current_session = current_user.sessions.find_by(id: session[:user_session_id])
79
+
80
+ # # check if user has an active session
81
+ # if current_session.equal? nil or !current_session.active?
82
+ # current_user.log(operation: "system_session_logout", description: "session finished by the system")
83
+ # sign_out current_user
84
+ # redirect_to "#{engine_path}/logout" and return
85
+ # end
86
+
87
+ # if !current_session.expiration_at.blank? && current_session.expiration_at < Time.current
88
+ # current_user.log(operation: "system_session_logout", description: "session expired by the system")
89
+ # sign_out current_user
90
+ # redirect_to "#{engine_path}/logout" and return
91
+ # end
92
+
93
+ # # check password expiration date
94
+ # if current_user.has_expired_password?
95
+ # unless controller_name == "profiles"
96
+ # current_user.log(operation: "redirect_due_to_expired_password")
97
+ # redirect_to "/administration/profile#force-password-reset", notice: I18n.t("core.users/sessions.messages_danger_password_expired")
98
+ # return
99
+ # end
100
+ # end
101
+
102
+ end
103
+
104
+ # Check if current_user has privileges to complete this request
105
+ def authorize_request
106
+
107
+ # check if user has access to the requested controller
108
+ # this search is over all the privileges for all the roles of the users
109
+ granted = current_user.has_privileges_for?(params[:controller], params[:action])
110
+
111
+
112
+ # get the path to which the user is limited to
113
+ limited_path = false# current_user.has_role_limited_to_path?
114
+
115
+ # to redirect to the limited path we must check:
116
+ # limited_path must not to be nil or empty string ("")
117
+ # limited_path must not to be equal to the current path (to avoid a loop)
118
+ # request must not to be AJAX
119
+ # request must be for show or index views
120
+ if !limited_path.blank? and
121
+ !(limited_path == request.original_fullpath) and
122
+ !(request[:format] == "json") and
123
+ ["show", "index"].include?(params[:action])
124
+
125
+ return redirect_to(limited_path)
126
+ end
127
+
128
+ # privilege for object not found
129
+ if granted.blank?
130
+ log(
131
+ :operation => :authorize_request,
132
+ :description => "Privilege not found for: #{request.path}"
133
+ )
134
+ return respond_with_forbidden({ controller: params[:controller], action: params[:action] })
135
+ end
136
+
137
+ unless granted
138
+ log(
139
+ :operation => :authorize_request,
140
+ :description => "Privilege not granted for: #{request.path}"
141
+ )
142
+ return respond_with_forbidden({ controller: params[:controller], action: params[:action] })
143
+ end
144
+ end
145
+ end
146
+ end
@@ -7,34 +7,6 @@ module LesliShield
7
7
  module UserAuthentication
8
8
  extend ActiveSupport::Concern
9
9
 
10
- # This module is prepended after Devise installs its model modules so
11
- # LesliShield can extend, rather than replace, Devise's eligibility
12
- # checks. Calling super preserves confirmable, lockable, and any other
13
- # authentication provider rules.
14
- module LoginEligibility
15
- def active_for_authentication?
16
- super && lesli_shield_login_validation.valid?
17
- end
18
-
19
- def inactive_message
20
- return super if lesli_shield_login_validation.valid?
21
-
22
- :invalid
23
- end
24
-
25
- private
26
-
27
- def lesli_shield_login_validation
28
- return @lesli_shield_login_validation if defined?(
29
- @lesli_shield_login_validation
30
- )
31
-
32
- @lesli_shield_login_validation = LesliShield::UserValidatorService
33
- .new(self)
34
- .validate
35
- end
36
- end
37
-
38
10
  DEVISE_MODULES = %i[
39
11
  database_authenticatable
40
12
  registerable
@@ -48,7 +20,6 @@ module LesliShield
48
20
 
49
21
  included do
50
22
  devise(*LesliShield::UserAuthentication::DEVISE_MODULES)
51
- prepend LesliShield::UserAuthentication::LoginEligibility
52
23
  end
53
24
  end
54
25
  end