lesli_shield 1.1.7 → 1.1.9
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/stylesheets/lesli_shield/application.css +1036 -32
- data/app/assets/stylesheets/lesli_shield/confirmations.css +89 -557
- data/app/assets/stylesheets/lesli_shield/invitations.css +544 -0
- data/app/assets/stylesheets/lesli_shield/passwords.css +76 -542
- data/app/assets/stylesheets/lesli_shield/registrations.css +66 -539
- data/app/assets/stylesheets/lesli_shield/sessions.css +98 -564
- data/app/controllers/lesli_shield/invites_controller.rb +100 -49
- data/app/controllers/lesli_shield/profiles_controller.rb +9 -3
- data/app/controllers/lesli_shield/role/actions_controller.rb +134 -38
- data/app/controllers/lesli_shield/roles_controller.rb +114 -141
- data/app/controllers/lesli_shield/users_controller.rb +11 -4
- data/app/controllers/users/confirmations_controller.rb +2 -2
- data/app/controllers/users/invitations_controller.rb +101 -0
- data/app/controllers/users/passwords_controller.rb +1 -1
- data/app/controllers/users/registrations_controller.rb +2 -2
- data/app/controllers/users/sessions_controller.rb +3 -1
- data/app/jobs/lesli_shield/invitation_delivery_job.rb +123 -0
- data/app/mailers/lesli_shield/devise_mailer.rb +3 -3
- data/app/mailers/lesli_shield/invitation_mailer.rb +58 -0
- data/app/models/concerns/lesli_shield/role_management.rb +70 -0
- data/app/models/concerns/lesli_shield/user_security.rb +22 -19
- data/app/models/lesli_shield/invite.rb +183 -12
- data/app/services/lesli_shield/invitation_audit.rb +34 -0
- data/app/services/lesli_shield/invitation_email_policy.rb +64 -0
- data/app/services/lesli_shield/invitation_service.rb +405 -0
- data/app/services/lesli_shield/invite_service.rb +34 -5
- data/app/services/lesli_shield/profile_service.rb +1 -0
- data/app/services/lesli_shield/role_action_service.rb +37 -92
- data/app/services/lesli_shield/role_audit.rb +42 -0
- data/app/services/lesli_shield/role_permission_service.rb +347 -0
- data/app/services/lesli_shield/role_privilege_deployment_service.rb +79 -0
- data/app/services/lesli_shield/role_privilege_service.rb +69 -105
- data/app/services/lesli_shield/role_service.rb +431 -0
- data/app/services/lesli_shield/user_registration_service.rb +1 -1
- data/app/services/lesli_shield/user_validator_service.rb +9 -9
- data/app/views/devise/confirmations/new.html.erb +6 -6
- data/app/views/devise/confirmations/show.html.erb +6 -6
- data/app/views/devise/passwords/edit.html.erb +8 -8
- data/app/views/devise/passwords/new.html.erb +9 -9
- data/app/views/devise/registrations/new.html.erb +16 -16
- data/app/views/devise/sessions/new.html.erb +9 -9
- 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 +5 -5
- data/app/views/devise/shared/_error_messages.html.erb +5 -5
- data/app/views/devise/shared/_links.html.erb +12 -15
- data/app/views/lesli_shield/invites/_form.html.erb +64 -7
- data/app/views/lesli_shield/invites/_invite.html.erb +55 -2
- data/app/views/lesli_shield/invites/_invite_actions.html.erb +34 -0
- data/app/views/lesli_shield/invites/_status_badge.html.erb +13 -0
- data/app/views/lesli_shield/invites/index.html.erb +119 -63
- data/app/views/lesli_shield/invites/new.html.erb +11 -36
- data/app/views/lesli_shield/invites/show.html.erb +13 -52
- data/app/views/lesli_shield/profiles/_information-form.html.erb +11 -0
- data/app/views/lesli_shield/profiles/_password-form.html.erb +1 -1
- data/app/views/lesli_shield/profiles/show.html.erb +1 -4
- data/app/views/lesli_shield/role/actions/_custom_actions.html.erb +24 -0
- data/app/views/lesli_shield/role/actions/_deployment_status.html.erb +14 -0
- data/app/views/lesli_shield/role/actions/_matrix.html.erb +69 -0
- data/app/views/lesli_shield/role/actions/_permissions.html.erb +95 -0
- data/app/views/lesli_shield/role/actions/_toggle.html.erb +34 -0
- data/app/views/lesli_shield/role/actions/index.html.erb +13 -10
- data/app/views/lesli_shield/roles/_deployment_badge.html.erb +15 -0
- data/app/views/lesli_shield/roles/_empty_state.html.erb +20 -0
- data/app/views/lesli_shield/roles/_field_errors.html.erb +5 -0
- data/app/views/lesli_shield/roles/_filters.html.erb +66 -0
- data/app/views/lesli_shield/roles/_form.html.erb +149 -18
- data/app/views/lesli_shield/roles/_management_menu.html.erb +37 -0
- data/app/views/lesli_shield/roles/_pagination.html.erb +43 -0
- data/app/views/lesli_shield/roles/_role_list.html.erb +116 -0
- data/app/views/lesli_shield/roles/_status_badge.html.erb +11 -0
- data/app/views/lesli_shield/roles/_type_badge.html.erb +9 -0
- data/app/views/lesli_shield/roles/index.html.erb +15 -38
- data/app/views/lesli_shield/roles/new.html.erb +11 -0
- data/app/views/lesli_shield/roles/show.html.erb +79 -7
- data/app/views/lesli_shield/users/_information-card.html.erb +3 -3
- data/app/views/lesli_shield/users/_information-form.html.erb +6 -0
- data/app/views/lesli_shield/users/_management-privileges.html.erb +2 -2
- data/app/views/users/invitations/show.html.erb +142 -0
- data/app/views/users/invitations/unavailable.html.erb +19 -0
- data/config/locales/devise.en.yml +8 -0
- data/config/locales/devise.es.yml +8 -0
- data/config/locales/translations.en.yml +313 -78
- data/config/locales/translations.es.yml +313 -78
- data/config/routes.rb +10 -3
- data/db/migrate/v1/0801120110_create_lesli_shield_invites.rb +40 -6
- data/lib/lesli_shield/engine.rb +4 -0
- data/lib/lesli_shield/router.rb +10 -0
- data/lib/lesli_shield/version.rb +2 -2
- data/lib/tasks/lesli_shield_tasks.rake +1 -1
- data/readme.md +13 -1
- metadata +35 -11
- 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/mailers/lesli_shield/invitation.html.erb +0 -23
- data/app/views/lesli_shield/invites/edit.html.erb +0 -12
- data/app/views/lesli_shield/role/actions/_form.html.erb +0 -75
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LesliShield
|
|
4
|
+
# Owns role administration rules. Every lookup starts from the actor's
|
|
5
|
+
# account and is restricted by the actor's active permission level.
|
|
6
|
+
class RoleService
|
|
7
|
+
DEFAULT_PER_PAGE = 12
|
|
8
|
+
MAX_PER_PAGE = 100
|
|
9
|
+
|
|
10
|
+
STATUS_FILTERS = %w[active inactive].freeze
|
|
11
|
+
TYPE_FILTERS = %w[system custom].freeze
|
|
12
|
+
WRITABLE_ATTRIBUTES = %i[
|
|
13
|
+
name
|
|
14
|
+
description
|
|
15
|
+
active
|
|
16
|
+
path_default
|
|
17
|
+
permission_level
|
|
18
|
+
].freeze
|
|
19
|
+
|
|
20
|
+
SORT_COLUMNS = {
|
|
21
|
+
"id" => "lesli_roles.id",
|
|
22
|
+
"name" => "LOWER(lesli_roles.name)",
|
|
23
|
+
"description" => "LOWER(lesli_roles.description)",
|
|
24
|
+
"active" => "lesli_roles.active",
|
|
25
|
+
"permission_level" => "lesli_roles.permission_level",
|
|
26
|
+
"modified_at" => "COALESCE(lesli_roles.modified_at, lesli_roles.updated_at)",
|
|
27
|
+
"users" => "users",
|
|
28
|
+
"actions" => "actions"
|
|
29
|
+
}.freeze
|
|
30
|
+
|
|
31
|
+
SYSTEM_ROLE_SQL = RoleManagement::SYSTEM_ROLE_NAMES.map do |name|
|
|
32
|
+
"LOWER(COALESCE(lesli_roles.code, '')) = " \
|
|
33
|
+
"'#{name}' || CAST(lesli_roles.id AS VARCHAR)"
|
|
34
|
+
end.join(" OR ").freeze
|
|
35
|
+
|
|
36
|
+
ACTIVE_USERS_SQL = <<~SQL.squish.freeze
|
|
37
|
+
(
|
|
38
|
+
SELECT COUNT(DISTINCT role_users.user_id)
|
|
39
|
+
FROM lesli_shield_user_roles role_users
|
|
40
|
+
INNER JOIN lesli_users users
|
|
41
|
+
ON users.id = role_users.user_id
|
|
42
|
+
WHERE role_users.role_id = lesli_roles.id
|
|
43
|
+
AND role_users.deleted_at IS NULL
|
|
44
|
+
AND users.deleted_at IS NULL
|
|
45
|
+
AND users.active = TRUE
|
|
46
|
+
)
|
|
47
|
+
SQL
|
|
48
|
+
|
|
49
|
+
ACTIVE_ACTIONS_SQL = <<~SQL.squish.freeze
|
|
50
|
+
(
|
|
51
|
+
SELECT COUNT(DISTINCT role_actions.action_id)
|
|
52
|
+
FROM lesli_shield_role_actions role_actions
|
|
53
|
+
WHERE role_actions.role_id = lesli_roles.id
|
|
54
|
+
AND role_actions.deleted_at IS NULL
|
|
55
|
+
)
|
|
56
|
+
SQL
|
|
57
|
+
|
|
58
|
+
class Error < StandardError
|
|
59
|
+
attr_reader :record
|
|
60
|
+
|
|
61
|
+
def initialize(message, record: nil)
|
|
62
|
+
@record = record
|
|
63
|
+
super(message)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
class DuplicateNameError < Error; end
|
|
68
|
+
class PermissionLevelError < Error; end
|
|
69
|
+
class ProtectedRoleError < Error; end
|
|
70
|
+
class SystemRoleError < Error; end
|
|
71
|
+
class AssignedUsersError < Error; end
|
|
72
|
+
|
|
73
|
+
class ValidationError < Error
|
|
74
|
+
def initialize(record)
|
|
75
|
+
super(record.errors.full_messages.to_sentence, record: record)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def initialize(actor, query = {})
|
|
80
|
+
@actor = actor
|
|
81
|
+
@query = query || {}
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def list(filters = {})
|
|
85
|
+
roles = visible_roles
|
|
86
|
+
roles = apply_search(roles, filters)
|
|
87
|
+
roles = apply_status(roles, filters)
|
|
88
|
+
roles = apply_type(roles, filters)
|
|
89
|
+
|
|
90
|
+
roles
|
|
91
|
+
.select(
|
|
92
|
+
"lesli_roles.*",
|
|
93
|
+
"#{ACTIVE_USERS_SQL} AS users",
|
|
94
|
+
"#{ACTIVE_ACTIONS_SQL} AS actions"
|
|
95
|
+
)
|
|
96
|
+
.order(Arel.sql("#{sort_column} #{sort_direction}"))
|
|
97
|
+
.order(id: :asc)
|
|
98
|
+
.page(page)
|
|
99
|
+
.per(per_page)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def find!(id, manageable: false)
|
|
103
|
+
role = visible_roles.find(id)
|
|
104
|
+
|
|
105
|
+
if manageable && !role.manageable_by?(actor)
|
|
106
|
+
raise ActiveRecord::RecordNotFound
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
role
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def build(attributes = {})
|
|
113
|
+
actor.account.roles.new(
|
|
114
|
+
initial_attributes.merge(normalize_attributes(attributes))
|
|
115
|
+
)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def summary(role_or_id)
|
|
119
|
+
role = find!(record_id(role_or_id))
|
|
120
|
+
|
|
121
|
+
{
|
|
122
|
+
members: User::Role
|
|
123
|
+
.where(role_id: role.id)
|
|
124
|
+
.distinct
|
|
125
|
+
.count(:user_id),
|
|
126
|
+
permissions: role.actions.distinct.count(:action_id)
|
|
127
|
+
}
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def create!(attributes)
|
|
131
|
+
Lesli::Role.transaction do
|
|
132
|
+
role = persist_new_role!(attributes)
|
|
133
|
+
audit!(:role_created, role)
|
|
134
|
+
role
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def update!(role_or_id, attributes)
|
|
139
|
+
role = manageable_role!(role_or_id)
|
|
140
|
+
|
|
141
|
+
role.with_lock do
|
|
142
|
+
manageable_role!(role.id)
|
|
143
|
+
role.assign_attributes(normalize_attributes(attributes))
|
|
144
|
+
|
|
145
|
+
validate_permission_level!(role)
|
|
146
|
+
validate_unique_name!(role)
|
|
147
|
+
changes = role.changes.slice(*WRITABLE_ATTRIBUTES.map(&:to_s))
|
|
148
|
+
next if changes.empty?
|
|
149
|
+
|
|
150
|
+
# Capture changes before saving: model callbacks may perform
|
|
151
|
+
# another save and replace Active Record's saved_changes.
|
|
152
|
+
operation = update_operation(role, changes)
|
|
153
|
+
save!(role)
|
|
154
|
+
audit!(operation, role, changes: changes)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
role
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def deactivate!(role_or_id)
|
|
161
|
+
update!(role_or_id, active: false)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def destroy!(role_or_id)
|
|
165
|
+
role = manageable_role!(role_or_id)
|
|
166
|
+
|
|
167
|
+
role.with_lock do
|
|
168
|
+
manageable_role!(role.id)
|
|
169
|
+
|
|
170
|
+
if role.system_role?
|
|
171
|
+
raise SystemRoleError.new(
|
|
172
|
+
I18n.t("lesli_shield.roles.errors_system_role"),
|
|
173
|
+
record: role
|
|
174
|
+
)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
if role.assigned?
|
|
178
|
+
raise AssignedUsersError.new(
|
|
179
|
+
I18n.t("lesli_shield.roles.errors_assigned_users"),
|
|
180
|
+
record: role
|
|
181
|
+
)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
role.destroy!
|
|
185
|
+
audit!(:role_deleted, role)
|
|
186
|
+
end
|
|
187
|
+
role
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Copies configuration and selected active actions, but never user
|
|
191
|
+
# assignments, compiled privileges, or deployment state.
|
|
192
|
+
def duplicate!(role_or_id, attributes = {})
|
|
193
|
+
source = find!(record_id(role_or_id))
|
|
194
|
+
overrides = normalize_attributes(attributes)
|
|
195
|
+
overrides[:name] ||= available_copy_name(source.name)
|
|
196
|
+
|
|
197
|
+
Lesli::Role.transaction do
|
|
198
|
+
# Duplication is one operation, not a separate creation event.
|
|
199
|
+
duplicate = persist_new_role!(
|
|
200
|
+
{
|
|
201
|
+
name: overrides.delete(:name),
|
|
202
|
+
description: source.description,
|
|
203
|
+
path_default: source.path_default,
|
|
204
|
+
permission_level: source.permission_level,
|
|
205
|
+
active: false
|
|
206
|
+
}.merge(overrides)
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
RolePermissionService
|
|
210
|
+
.new(actor)
|
|
211
|
+
.duplicate_from!(source, duplicate)
|
|
212
|
+
audit!(
|
|
213
|
+
:role_duplicated,
|
|
214
|
+
duplicate,
|
|
215
|
+
source_role_id: source.id,
|
|
216
|
+
source_role_name: source.name
|
|
217
|
+
)
|
|
218
|
+
duplicate.reload
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
private
|
|
223
|
+
|
|
224
|
+
attr_reader :actor, :query
|
|
225
|
+
|
|
226
|
+
# Shared persistence without auditing. Public operations own their
|
|
227
|
+
# transaction and record exactly one event with the correct meaning.
|
|
228
|
+
def persist_new_role!(attributes)
|
|
229
|
+
role = build(attributes)
|
|
230
|
+
validate_permission_level!(role)
|
|
231
|
+
validate_unique_name!(role)
|
|
232
|
+
save!(role)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def update_operation(role, changes)
|
|
236
|
+
return :role_updated unless changes.key?("active")
|
|
237
|
+
|
|
238
|
+
role.active? ? :role_activated : :role_deactivated
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def audit!(operation, role, **details)
|
|
242
|
+
RoleAudit.record!(
|
|
243
|
+
operation,
|
|
244
|
+
role: role,
|
|
245
|
+
actor: actor,
|
|
246
|
+
source: self.class,
|
|
247
|
+
details: details
|
|
248
|
+
)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def visible_roles
|
|
252
|
+
actor.account.roles.where(
|
|
253
|
+
permission_level: ..actor.max_level_permission
|
|
254
|
+
)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def manageable_role!(role_or_id)
|
|
258
|
+
role = visible_roles.find(record_id(role_or_id))
|
|
259
|
+
|
|
260
|
+
if role.protected_role?
|
|
261
|
+
raise ProtectedRoleError.new(
|
|
262
|
+
I18n.t("lesli_shield.roles.errors_protected_role"),
|
|
263
|
+
record: role
|
|
264
|
+
)
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
unless role.manageable_by?(actor)
|
|
268
|
+
raise PermissionLevelError.new(
|
|
269
|
+
I18n.t(
|
|
270
|
+
"lesli_shield.roles.errors_permission_level",
|
|
271
|
+
maximum: actor.max_level_permission
|
|
272
|
+
),
|
|
273
|
+
record: role
|
|
274
|
+
)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
role
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def record_id(role_or_id)
|
|
281
|
+
role_or_id.respond_to?(:id) ? role_or_id.id : role_or_id
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def initial_attributes
|
|
285
|
+
{
|
|
286
|
+
active: true,
|
|
287
|
+
isolated: false,
|
|
288
|
+
path_limited: false,
|
|
289
|
+
path_default: nil,
|
|
290
|
+
# Creating a role requires an explicit authorization level.
|
|
291
|
+
# Assigning nil also overrides the database column default,
|
|
292
|
+
# preventing callers from accidentally creating a level-10 role.
|
|
293
|
+
permission_level: nil
|
|
294
|
+
}
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def normalize_attributes(attributes)
|
|
298
|
+
normalized = attributes.to_h.symbolize_keys.slice(*WRITABLE_ATTRIBUTES)
|
|
299
|
+
|
|
300
|
+
if normalized.key?(:name)
|
|
301
|
+
normalized[:name] = normalized[:name].to_s.squish
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
if normalized.key?(:description)
|
|
305
|
+
normalized[:description] = normalized[:description]
|
|
306
|
+
.to_s
|
|
307
|
+
.squish
|
|
308
|
+
.presence
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
normalized
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
def validate_permission_level!(role)
|
|
315
|
+
return if role.permission_level.blank?
|
|
316
|
+
return if role.permission_level.between?(0, actor.max_level_permission)
|
|
317
|
+
|
|
318
|
+
message = I18n.t(
|
|
319
|
+
"lesli_shield.roles.errors_permission_level",
|
|
320
|
+
maximum: actor.max_level_permission
|
|
321
|
+
)
|
|
322
|
+
role.errors.add(:permission_level, message)
|
|
323
|
+
|
|
324
|
+
raise PermissionLevelError.new(
|
|
325
|
+
message,
|
|
326
|
+
record: role
|
|
327
|
+
)
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def validate_unique_name!(role)
|
|
331
|
+
return if role.name.blank?
|
|
332
|
+
|
|
333
|
+
duplicates = actor.account.roles
|
|
334
|
+
.where("LOWER(name) = ?", role.name.downcase)
|
|
335
|
+
duplicates = duplicates.where.not(id: role.id) if role.persisted?
|
|
336
|
+
return unless duplicates.exists?
|
|
337
|
+
|
|
338
|
+
role.errors.add(
|
|
339
|
+
:name,
|
|
340
|
+
I18n.t("lesli_shield.roles.errors_duplicate_name")
|
|
341
|
+
)
|
|
342
|
+
raise DuplicateNameError.new(
|
|
343
|
+
role.errors.full_messages.to_sentence,
|
|
344
|
+
record: role
|
|
345
|
+
)
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
def save!(role)
|
|
349
|
+
role.save!
|
|
350
|
+
role
|
|
351
|
+
rescue ActiveRecord::RecordInvalid
|
|
352
|
+
raise ValidationError, role
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
def available_copy_name(source_name)
|
|
356
|
+
base_name = "#{source_name} copy"
|
|
357
|
+
candidate = base_name
|
|
358
|
+
suffix = 2
|
|
359
|
+
|
|
360
|
+
while name_exists?(candidate)
|
|
361
|
+
candidate = "#{base_name} #{suffix}"
|
|
362
|
+
suffix += 1
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
candidate
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
def name_exists?(name)
|
|
369
|
+
actor.account.roles.where("LOWER(name) = ?", name.downcase).exists?
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
def apply_search(roles, filters)
|
|
373
|
+
search = filter_value(filters, :search) || query[:search]
|
|
374
|
+
search = search.to_s.strip.presence
|
|
375
|
+
return roles unless search
|
|
376
|
+
|
|
377
|
+
pattern = "%#{ActiveRecord::Base.sanitize_sql_like(search.downcase)}%"
|
|
378
|
+
roles.where(
|
|
379
|
+
"LOWER(lesli_roles.name) LIKE :pattern " \
|
|
380
|
+
"OR LOWER(COALESCE(lesli_roles.description, '')) LIKE :pattern",
|
|
381
|
+
pattern: pattern
|
|
382
|
+
)
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
def apply_status(roles, filters)
|
|
386
|
+
case filter_value(filters, :status).to_s
|
|
387
|
+
when "active"
|
|
388
|
+
roles.where(active: true)
|
|
389
|
+
when "inactive"
|
|
390
|
+
roles.where(active: false)
|
|
391
|
+
else
|
|
392
|
+
roles
|
|
393
|
+
end
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
def apply_type(roles, filters)
|
|
397
|
+
case filter_value(filters, :type).to_s
|
|
398
|
+
when "system"
|
|
399
|
+
roles.where(SYSTEM_ROLE_SQL)
|
|
400
|
+
when "custom"
|
|
401
|
+
roles.where("NOT (#{SYSTEM_ROLE_SQL})")
|
|
402
|
+
else
|
|
403
|
+
roles
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
def filter_value(filters, key)
|
|
408
|
+
filters&.[](key) || filters&.[](key.to_s)
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
def sort_column
|
|
412
|
+
SORT_COLUMNS.fetch(query.dig(:order, :by).to_s, SORT_COLUMNS.fetch("id"))
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
def sort_direction
|
|
416
|
+
query.dig(:order, :dir).to_s.casecmp?("asc") ? "ASC" : "DESC"
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
def page
|
|
420
|
+
requested = query.dig(:pagination, :page).to_i
|
|
421
|
+
requested.positive? ? requested : 1
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
def per_page
|
|
425
|
+
requested = query.dig(:pagination, :perPage).to_i
|
|
426
|
+
return DEFAULT_PER_PAGE unless requested.positive?
|
|
427
|
+
|
|
428
|
+
[requested, MAX_PER_PAGE].min
|
|
429
|
+
end
|
|
430
|
+
end
|
|
431
|
+
end
|
|
@@ -52,7 +52,7 @@ module LesliShield
|
|
|
52
52
|
def password_complexity(password)
|
|
53
53
|
|
|
54
54
|
if password.blank?
|
|
55
|
-
|
|
55
|
+
errors.push('error_password_cannot_be_blank')
|
|
56
56
|
return self
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -91,7 +91,7 @@ module LesliShield
|
|
|
91
91
|
|
|
92
92
|
# exit validations if password complexity is not enabled
|
|
93
93
|
if settings[:name] == 'password_enforce_complexity' && settings[:value] != "1"
|
|
94
|
-
|
|
94
|
+
errors.clear
|
|
95
95
|
break
|
|
96
96
|
end
|
|
97
97
|
|
|
@@ -100,7 +100,7 @@ module LesliShield
|
|
|
100
100
|
|
|
101
101
|
# this regex removes all "normal" letters and numbers leaving special characters
|
|
102
102
|
if settings[:value].to_i > password.scan(/[^0-9A-Za-z]/).length
|
|
103
|
-
|
|
103
|
+
errors.push('error_password_special_char_count')
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
end
|
|
@@ -109,7 +109,7 @@ module LesliShield
|
|
|
109
109
|
if settings[:name] == 'password_lowercase_count'
|
|
110
110
|
|
|
111
111
|
if settings[:value].to_i > password_string_no_special.scan(/[^0-9A-Z]/).length
|
|
112
|
-
|
|
112
|
+
errors.push('error_password_lowercase_count')
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
end
|
|
@@ -118,7 +118,7 @@ module LesliShield
|
|
|
118
118
|
if settings[:name] == 'password_uppercase_count'
|
|
119
119
|
|
|
120
120
|
if settings[:value].to_i > password_string_no_special.scan(/[^0-9a-z]/).length
|
|
121
|
-
|
|
121
|
+
errors.push('error_password_uppercase_count')
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
end
|
|
@@ -127,7 +127,7 @@ module LesliShield
|
|
|
127
127
|
if settings[:name] == 'password_digit_count'
|
|
128
128
|
|
|
129
129
|
if settings[:value].to_i > password_string_no_special.scan(/[^A-Za-z]/).length
|
|
130
|
-
|
|
130
|
+
errors.push('error_password_digit_count')
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
end
|
|
@@ -136,7 +136,7 @@ module LesliShield
|
|
|
136
136
|
if settings[:name] == 'password_minimum_length'
|
|
137
137
|
|
|
138
138
|
if settings[:value].to_i > password.length
|
|
139
|
-
|
|
139
|
+
errors.push('error_password_minimum_length')
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
end
|
|
@@ -148,7 +148,7 @@ module LesliShield
|
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
def valid?
|
|
151
|
-
|
|
151
|
+
errors.empty?
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
private
|
|
@@ -211,7 +211,7 @@ module LesliShield
|
|
|
211
211
|
end
|
|
212
212
|
|
|
213
213
|
def log_failure(description)
|
|
214
|
-
|
|
214
|
+
errors.push(description) unless errors.include?(description)
|
|
215
215
|
end
|
|
216
216
|
end
|
|
217
217
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%= render(
|
|
2
2
|
"devise/shared/application-devise-simple",
|
|
3
|
-
title: I18n.t("lesli_shield.
|
|
3
|
+
title: I18n.t("lesli_shield.devise_confirmations.view_title")
|
|
4
4
|
) do %>
|
|
5
5
|
|
|
6
6
|
<%= form_for(
|
|
@@ -11,9 +11,9 @@
|
|
|
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
|
-
"lesli_shield.
|
|
16
|
+
"lesli_shield.devise_confirmations.view_description"
|
|
17
17
|
) %>
|
|
18
18
|
</p>
|
|
19
19
|
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
:email,
|
|
24
24
|
icon: "mail",
|
|
25
25
|
label: I18n.t(
|
|
26
|
-
"lesli_shield.
|
|
26
|
+
"lesli_shield.devise_confirmations.field_email"
|
|
27
27
|
),
|
|
28
28
|
message: resource.errors[:email].to_sentence.presence,
|
|
29
29
|
category: resource.errors[:email].any? ? :danger : nil,
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
|
|
39
39
|
<%= form.field_control_button(
|
|
40
40
|
I18n.t(
|
|
41
|
-
"lesli_shield.
|
|
41
|
+
"lesli_shield.devise_confirmations.button_send_instructions"
|
|
42
42
|
),
|
|
43
43
|
{
|
|
44
44
|
class: "w-full",
|
|
45
45
|
data: {
|
|
46
46
|
turbo_submits_with: I18n.t(
|
|
47
|
-
"lesli_shield.
|
|
47
|
+
"lesli_shield.devise_confirmations.button_sending"
|
|
48
48
|
)
|
|
49
49
|
}
|
|
50
50
|
},
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
<%= render(
|
|
2
2
|
"devise/shared/application-devise-simple",
|
|
3
|
-
title: I18n.t("lesli_shield.
|
|
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
|
-
"lesli_shield.
|
|
18
|
+
"lesli_shield.devise_confirmations.view_success_description"
|
|
19
19
|
) %>
|
|
20
20
|
</p>
|
|
21
21
|
|
|
22
22
|
<%= link_to(
|
|
23
|
-
I18n.t("lesli_shield.
|
|
23
|
+
I18n.t("lesli_shield.devise_shared.button_login"),
|
|
24
24
|
new_user_session_path,
|
|
25
25
|
class: "mt-6 inline-flex min-h-11 items-center justify-center rounded-lg bg-[var(--lesli-color-primary)] px-5 py-2.5 text-sm font-semibold text-white transition-opacity hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--lesli-color-primary)]"
|
|
26
26
|
) %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%= render(
|
|
2
2
|
"devise/shared/application-devise-simple",
|
|
3
|
-
title: I18n.t("lesli_shield.
|
|
3
|
+
title: I18n.t("lesli_shield.devise_passwords.view_update_title")
|
|
4
4
|
) do %>
|
|
5
5
|
|
|
6
6
|
<%= form_for(
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
builder: LesliView::Forms::Builder
|
|
12
12
|
) do |form| %>
|
|
13
13
|
|
|
14
|
-
<p class="mb-6 text-center text-sm leading-6 text-
|
|
15
|
-
<%= I18n.t("lesli_shield.
|
|
14
|
+
<p class="mb-6 text-center text-sm leading-6 text-neutral-600">
|
|
15
|
+
<%= I18n.t("lesli_shield.devise_passwords.view_update_description") %>
|
|
16
16
|
</p>
|
|
17
17
|
|
|
18
18
|
<%= render "devise/shared/error_messages", resource: resource %>
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
<%= form.field_control_password(
|
|
23
23
|
:password,
|
|
24
24
|
icon: "key",
|
|
25
|
-
label: I18n.t("lesli_shield.
|
|
25
|
+
label: I18n.t("lesli_shield.devise_passwords.field_password"),
|
|
26
26
|
message: I18n.t(
|
|
27
|
-
"lesli_shield.
|
|
27
|
+
"lesli_shield.devise_passwords.field_password_hint_#{@minimum_password_length == 1 ? 'one' : 'other'}",
|
|
28
28
|
count: @minimum_password_length
|
|
29
29
|
),
|
|
30
30
|
required: true,
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
:password_confirmation,
|
|
39
39
|
icon: "key",
|
|
40
40
|
label: I18n.t(
|
|
41
|
-
"lesli_shield.
|
|
41
|
+
"lesli_shield.devise_passwords.field_password_confirmation"
|
|
42
42
|
),
|
|
43
43
|
required: true,
|
|
44
44
|
autocomplete: "new-password",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
) %>
|
|
48
48
|
|
|
49
49
|
<%= form.field_control_button(
|
|
50
|
-
I18n.t("lesli_shield.
|
|
50
|
+
I18n.t("lesli_shield.devise_passwords.button_update_password"),
|
|
51
51
|
{
|
|
52
52
|
class: "is-fullwidth",
|
|
53
53
|
data: {
|
|
54
54
|
turbo_submits_with: I18n.t(
|
|
55
|
-
"lesli_shield.
|
|
55
|
+
"lesli_shield.devise_passwords.button_updating"
|
|
56
56
|
)
|
|
57
57
|
}
|
|
58
58
|
},
|