lesli_shield 1.1.8 → 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.
- checksums.yaml +4 -4
- data/app/assets/images/lesli_shield/login-background.webp +0 -0
- data/app/assets/images/lesli_shield/register-background.webp +0 -0
- data/app/assets/stylesheets/lesli_shield/application.css +325 -408
- data/app/assets/stylesheets/lesli_shield/confirmations.css +89 -557
- data/app/assets/stylesheets/lesli_shield/invitations.css +116 -580
- data/app/assets/stylesheets/lesli_shield/passwords.css +76 -542
- data/app/assets/stylesheets/lesli_shield/registrations.css +96 -544
- data/app/assets/stylesheets/lesli_shield/sessions.css +99 -565
- data/app/controllers/lesli_shield/profile/passwords_controller.rb +0 -2
- data/app/controllers/lesli_shield/profiles_controller.rb +0 -1
- data/app/controllers/lesli_shield/user/roles_controller.rb +35 -59
- data/app/controllers/lesli_shield/users_controller.rb +4 -2
- data/app/controllers/users/registrations_controller.rb +27 -0
- data/app/controllers/users/sessions_controller.rb +11 -0
- data/app/interfaces/lesli_shield/security_interface.rb +146 -0
- data/app/models/concerns/lesli_shield/user_authentication.rb +0 -29
- data/app/models/concerns/lesli_shield/user_legal_acceptance.rb +45 -0
- data/app/models/concerns/lesli_shield/user_security.rb +23 -14
- data/app/services/lesli_shield/user_role_service.rb +37 -0
- data/app/services/lesli_shield/user_validator_service.rb +6 -28
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/confirmations/show.html.erb +3 -3
- data/app/views/devise/passwords/edit.html.erb +1 -1
- data/app/views/devise/passwords/new.html.erb +2 -2
- data/app/views/devise/registrations/_terms.html.erb +34 -0
- data/app/views/devise/registrations/new.html.erb +5 -7
- data/app/views/devise/sessions/new.html.erb +3 -2
- data/app/views/devise/shared/_application-devise-simple.erb +1 -1
- data/app/views/devise/shared/_application-devise.html.erb +4 -4
- data/app/views/devise/shared/_demo.html.erb +2 -2
- data/app/views/devise/shared/_error_messages.html.erb +5 -5
- data/app/views/devise/shared/_links.html.erb +4 -4
- data/app/views/lesli_shield/invites/_invite.html.erb +9 -9
- data/app/views/lesli_shield/invites/_invite_actions.html.erb +3 -3
- data/app/views/lesli_shield/invites/_status_badge.html.erb +4 -4
- data/app/views/lesli_shield/invites/index.html.erb +20 -20
- data/app/views/lesli_shield/partials/_navigation.html.erb +5 -5
- data/app/views/lesli_shield/profiles/_password-form.html.erb +1 -1
- data/app/views/lesli_shield/role/actions/_custom_actions.html.erb +7 -7
- data/app/views/lesli_shield/role/actions/_deployment_status.html.erb +2 -2
- data/app/views/lesli_shield/role/actions/_matrix.html.erb +13 -13
- data/app/views/lesli_shield/role/actions/_permissions.html.erb +9 -9
- data/app/views/lesli_shield/role/actions/_toggle.html.erb +3 -3
- data/app/views/lesli_shield/role/actions/index.html.erb +0 -1
- data/app/views/lesli_shield/roles/_deployment_badge.html.erb +3 -3
- data/app/views/lesli_shield/roles/_empty_state.html.erb +4 -4
- data/app/views/lesli_shield/roles/_field_errors.html.erb +1 -1
- data/app/views/lesli_shield/roles/_filters.html.erb +9 -9
- data/app/views/lesli_shield/roles/_form.html.erb +22 -22
- data/app/views/lesli_shield/roles/_management_menu.html.erb +5 -5
- data/app/views/lesli_shield/roles/_pagination.html.erb +7 -7
- data/app/views/lesli_shield/roles/_role_list.html.erb +19 -19
- data/app/views/lesli_shield/roles/_status_badge.html.erb +4 -4
- data/app/views/lesli_shield/roles/_type_badge.html.erb +2 -2
- data/app/views/lesli_shield/roles/new.html.erb +1 -1
- data/app/views/lesli_shield/roles/show.html.erb +40 -50
- data/app/views/lesli_shield/user/roles/index.html.erb +1 -16
- data/app/views/lesli_shield/users/_information-card.html.erb +3 -3
- data/app/views/lesli_shield/users/_management-privileges.html.erb +74 -68
- data/app/views/lesli_shield/users/show.html.erb +1 -1
- data/app/views/users/invitations/show.html.erb +10 -10
- data/app/views/users/invitations/unavailable.html.erb +4 -4
- data/config/locales/translations.en.yml +8 -1
- data/config/locales/translations.es.yml +8 -1
- data/config/locales/user_roles.en.yml +16 -0
- data/config/locales/user_roles.es.yml +16 -0
- data/config/routes.rb +1 -1
- data/lib/lesli_shield/engine.rb +4 -0
- data/lib/lesli_shield/version.rb +2 -2
- metadata +10 -12
- data/app/assets/images/lesli_shield/login-background.jpg +0 -0
- data/app/assets/images/lesli_shield/register-background.jpg +0 -0
- data/app/assets/stylesheets/lesli_shield/confirmations.tailwind.css +0 -918
- data/app/assets/stylesheets/lesli_shield/devise/oauth.css +0 -33
- data/app/assets/stylesheets/lesli_shield/passwords.tailwind.css +0 -873
- data/app/assets/stylesheets/lesli_shield/registrations.tailwind.css +0 -908
- data/app/assets/stylesheets/lesli_shield/sessions.tailwind.css +0 -984
- data/app/assets/stylesheets/lesli_shield/users.css +0 -31
- data/app/interfaces/lesli_shield/authentication_interface.rb +0 -64
- data/app/interfaces/lesli_shield/authorization_interface.rb +0 -46
|
@@ -1,62 +1,38 @@
|
|
|
1
1
|
module LesliShield
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LesliShield
|
|
4
|
+
module UserLegalAcceptance
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
attr_accessor :terms_accepted, :legal_acceptance_required
|
|
9
|
+
|
|
10
|
+
# Only public signup sets this flag. Existing users, invitations and
|
|
11
|
+
# administrative creation must not receive invented acceptance records.
|
|
12
|
+
validate :validate_registration_terms, on: :create, if: :legal_acceptance_required
|
|
13
|
+
before_create :record_legal_acceptance, if: :legal_acceptance_required
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Shared by validation and the form: an outdated form needs a new review.
|
|
17
|
+
def current_registration_documents?
|
|
18
|
+
terms_version.present? && privacy_version.present? &&
|
|
19
|
+
terms_version == Lesli.config.shield[:terms_version] &&
|
|
20
|
+
privacy_version == Lesli.config.shield[:privacy_version]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def validate_registration_terms
|
|
26
|
+
unless ["1", true].include?(terms_accepted)
|
|
27
|
+
errors.add(:base, I18n.t(
|
|
28
|
+
"overrides.lesli_shield.devise_registrations.message_terms_required",
|
|
29
|
+
default: :"lesli_shield.devise_registrations.message_terms_required"
|
|
30
|
+
))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
unless current_registration_documents?
|
|
34
|
+
errors.add(:base, I18n.t("lesli_shield.devise_registrations.message_legal_documents_changed"))
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def record_legal_acceptance
|
|
39
|
+
# Never accept a timestamp or accepted version supplied by the client.
|
|
40
|
+
self.terms_accepted_at = Time.current
|
|
41
|
+
self.terms_version = Lesli.config.shield.fetch(:terms_version)
|
|
42
|
+
self.privacy_version = Lesli.config.shield.fetch(:privacy_version)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -47,22 +47,31 @@ module LesliShield
|
|
|
47
47
|
!roles.intersection(self.roles.map{ |r| r[:name] }).empty?
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
#
|
|
51
|
-
#
|
|
50
|
+
# Cache only while handling an HTTP request. Jobs and standalone model
|
|
51
|
+
# calls keep querying current privileges, and ensure clears state on errors.
|
|
52
|
+
def with_privileges
|
|
53
|
+
@request_privileges = nil
|
|
54
|
+
@request_privileges_enabled = true
|
|
55
|
+
yield
|
|
56
|
+
ensure
|
|
57
|
+
@request_privileges = nil
|
|
58
|
+
@request_privileges_enabled = false
|
|
59
|
+
end
|
|
60
|
+
|
|
52
61
|
def has_privileges_for?(controller, action)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
rescue => exception
|
|
63
|
-
Termline.danger(exception.to_s)
|
|
64
|
-
return false
|
|
62
|
+
privileges = Role::Privilege.where(
|
|
63
|
+
role_id: roles.where(active: true).select(:id), active: true
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
if @request_privileges_enabled
|
|
67
|
+
@request_privileges ||= privileges.distinct.pluck(:controller, :action).to_set
|
|
68
|
+
@request_privileges.include?([controller.to_s, action.to_s])
|
|
69
|
+
else
|
|
70
|
+
privileges.exists?(controller: controller, action: action)
|
|
65
71
|
end
|
|
72
|
+
rescue StandardError => exception
|
|
73
|
+
Termline.danger(exception.to_s)
|
|
74
|
+
false
|
|
66
75
|
end
|
|
67
76
|
|
|
68
77
|
# A user can assign only active roles from their own account and never
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module LesliShield
|
|
2
|
+
class UserRoleService
|
|
3
|
+
def initialize(current_user, user)
|
|
4
|
+
@current_user = current_user
|
|
5
|
+
@user = user
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@user.user_roles.includes(:role).order(:id)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def list
|
|
13
|
+
@current_user.account.roles.where(active: true)
|
|
14
|
+
.where(permission_level: ..@current_user.max_level_permission)
|
|
15
|
+
.where.not(id: @user.roles.select(:id)).order(:name, :id)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create(role_id)
|
|
19
|
+
role = @current_user.account.roles.find(role_id)
|
|
20
|
+
raise ActiveRecord::RecordNotFound unless @current_user.can_assign_role?(role)
|
|
21
|
+
|
|
22
|
+
@user.user_roles.find_or_create_by!(role: role)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def destroy(id)
|
|
26
|
+
assignment = @user.user_roles.includes(:role).find(id)
|
|
27
|
+
# Inactive roles can still be removed within the administrator's level.
|
|
28
|
+
role = assignment.role
|
|
29
|
+
unless role.account_id == @current_user.account_id &&
|
|
30
|
+
role.permission_level.to_i <= @current_user.max_level_permission
|
|
31
|
+
raise ActiveRecord::RecordNotFound
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
assignment.destroy!
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -42,7 +42,12 @@ module LesliShield
|
|
|
42
42
|
def validate
|
|
43
43
|
account_present?()
|
|
44
44
|
active?()
|
|
45
|
-
|
|
45
|
+
role_states = current_user.roles.distinct.pluck(:active)
|
|
46
|
+
if role_states.empty?
|
|
47
|
+
log_failure("user_has_no_assigned_role")
|
|
48
|
+
elsif !role_states.include?(true)
|
|
49
|
+
log_failure("user_has_no_active_role")
|
|
50
|
+
end
|
|
46
51
|
self
|
|
47
52
|
end
|
|
48
53
|
|
|
@@ -183,33 +188,6 @@ module LesliShield
|
|
|
183
188
|
return true
|
|
184
189
|
end
|
|
185
190
|
|
|
186
|
-
def roles_empty?
|
|
187
|
-
|
|
188
|
-
# check if user has roles assigned
|
|
189
|
-
unless current_user.roles.exists?
|
|
190
|
-
|
|
191
|
-
log_failure("user_has_no_assigned_role")
|
|
192
|
-
|
|
193
|
-
return true
|
|
194
|
-
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
return false
|
|
198
|
-
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def active_roles?
|
|
202
|
-
|
|
203
|
-
# check user has at least one active role before authorize the sign-in request
|
|
204
|
-
unless current_user.roles.exists?(active: true)
|
|
205
|
-
log_failure("user_has_no_active_role")
|
|
206
|
-
|
|
207
|
-
return false
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
return true
|
|
211
|
-
end
|
|
212
|
-
|
|
213
191
|
def log_failure(description)
|
|
214
192
|
errors.push(description) unless errors.include?(description)
|
|
215
193
|
end
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
builder: LesliView::Forms::Builder
|
|
12
12
|
) do |form| %>
|
|
13
13
|
|
|
14
|
-
<p class="mb-6 text-center text-sm leading-6 text-
|
|
14
|
+
<p class="mb-6 text-center text-sm leading-6 text-neutral-600">
|
|
15
15
|
<%= I18n.t(
|
|
16
16
|
"lesli_shield.devise_confirmations.view_description"
|
|
17
17
|
) %>
|
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
title: I18n.t("lesli_shield.devise_confirmations.view_success_title")
|
|
4
4
|
) do %>
|
|
5
5
|
<section
|
|
6
|
-
class="my-8 w-full max-w-lg rounded-xl border border-
|
|
6
|
+
class="my-8 w-full max-w-lg rounded-xl border border-success-200 bg-white p-8 text-center shadow-sm"
|
|
7
7
|
role="status"
|
|
8
8
|
>
|
|
9
9
|
<span
|
|
10
|
-
class="material-symbols-outlined text-5xl text-
|
|
10
|
+
class="material-symbols-outlined text-5xl text-success-600"
|
|
11
11
|
aria-hidden="true"
|
|
12
12
|
>
|
|
13
13
|
verified
|
|
14
14
|
</span>
|
|
15
15
|
|
|
16
|
-
<p class="mt-4 text-sm leading-6 text-
|
|
16
|
+
<p class="mt-4 text-sm leading-6 text-neutral-600">
|
|
17
17
|
<%= I18n.t(
|
|
18
18
|
"lesli_shield.devise_confirmations.view_success_description"
|
|
19
19
|
) %>
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
builder: LesliView::Forms::Builder
|
|
12
12
|
) do |form| %>
|
|
13
13
|
|
|
14
|
-
<p class="mb-6 text-center text-sm leading-6 text-
|
|
14
|
+
<p class="mb-6 text-center text-sm leading-6 text-neutral-600">
|
|
15
15
|
<%= I18n.t("lesli_shield.devise_passwords.view_update_description") %>
|
|
16
16
|
</p>
|
|
17
17
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
builder: LesliView::Forms::Builder
|
|
13
13
|
) do |form| %>
|
|
14
14
|
|
|
15
|
-
<p class="mb-6 text-center text-sm leading-6 text-
|
|
15
|
+
<p class="mb-6 text-center text-sm leading-6 text-neutral-600">
|
|
16
16
|
<%= I18n.t("lesli_shield.devise_passwords.view_request_description") %>
|
|
17
17
|
</p>
|
|
18
18
|
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
) %>
|
|
44
44
|
|
|
45
45
|
<% if Lesli.config.security.dig(:allow_registration) %>
|
|
46
|
-
<p class="mt-6 text-center text-sm text-
|
|
46
|
+
<p class="mt-6 text-center text-sm text-neutral-600">
|
|
47
47
|
<%= I18n.t(
|
|
48
48
|
"lesli_shield.devise_sessions.view_still_not_registered"
|
|
49
49
|
) %>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<%# locals: (form:) %>
|
|
2
|
+
<% legal = Lesli.config.shield %>
|
|
3
|
+
|
|
4
|
+
<%= form.hidden_field :terms_version, value: legal.fetch(:terms_version) %>
|
|
5
|
+
<%= form.hidden_field :privacy_version, value: legal.fetch(:privacy_version) %>
|
|
6
|
+
|
|
7
|
+
<div class="my-6 text-sm leading-relaxed text-neutral-600">
|
|
8
|
+
<div class="flex items-start gap-3">
|
|
9
|
+
<%= form.check_box :terms_accepted,
|
|
10
|
+
required: true,
|
|
11
|
+
class: "mt-1 size-4 shrink-0 accent-primary focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-primary",
|
|
12
|
+
checked: (["1", true].include?(resource.terms_accepted) && resource.current_registration_documents?),
|
|
13
|
+
aria: { describedby: "registration-privacy-notice", invalid: resource.errors.any? } %>
|
|
14
|
+
<%= form.label :terms_accepted, class: "cursor-pointer" do %>
|
|
15
|
+
<%= t("overrides.lesli_shield.devise_registrations.label_terms_html",
|
|
16
|
+
default: :"lesli_shield.devise_registrations.label_terms_html",
|
|
17
|
+
terms: link_to(
|
|
18
|
+
t("lesli_shield.devise_registrations.link_terms"),
|
|
19
|
+
legal.fetch(:terms_url), target: "_blank", rel: "noopener",
|
|
20
|
+
class: "text-primary-strong underline underline-offset-2 focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-primary",
|
|
21
|
+
aria: { label: t("lesli_shield.devise_registrations.link_terms_new_tab") }
|
|
22
|
+
)) %>
|
|
23
|
+
<% end %>
|
|
24
|
+
</div>
|
|
25
|
+
<p id="registration-privacy-notice" class="mt-3 text-xs leading-relaxed">
|
|
26
|
+
<%= t("lesli_shield.devise_registrations.view_privacy_notice_html",
|
|
27
|
+
privacy: link_to(
|
|
28
|
+
t("lesli_shield.devise_registrations.link_privacy"),
|
|
29
|
+
legal.fetch(:privacy_url), target: "_blank", rel: "noopener",
|
|
30
|
+
class: "text-primary-strong underline underline-offset-2 focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-primary",
|
|
31
|
+
aria: { label: t("lesli_shield.devise_registrations.link_privacy_new_tab") }
|
|
32
|
+
)) %>
|
|
33
|
+
</p>
|
|
34
|
+
</div>
|