lesli_shield 1.1.7 → 1.1.8

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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/lesli_shield/application.css +1082 -0
  3. data/app/assets/stylesheets/lesli_shield/invitations.css +1008 -0
  4. data/app/controllers/lesli_shield/invites_controller.rb +100 -49
  5. data/app/controllers/lesli_shield/profiles_controller.rb +9 -3
  6. data/app/controllers/lesli_shield/role/actions_controller.rb +134 -38
  7. data/app/controllers/lesli_shield/roles_controller.rb +114 -141
  8. data/app/controllers/lesli_shield/users_controller.rb +11 -4
  9. data/app/controllers/users/confirmations_controller.rb +2 -2
  10. data/app/controllers/users/invitations_controller.rb +101 -0
  11. data/app/controllers/users/passwords_controller.rb +1 -1
  12. data/app/controllers/users/registrations_controller.rb +2 -2
  13. data/app/controllers/users/sessions_controller.rb +3 -1
  14. data/app/jobs/lesli_shield/invitation_delivery_job.rb +123 -0
  15. data/app/mailers/lesli_shield/devise_mailer.rb +3 -3
  16. data/app/mailers/lesli_shield/invitation_mailer.rb +58 -0
  17. data/app/models/concerns/lesli_shield/role_management.rb +70 -0
  18. data/app/models/concerns/lesli_shield/user_security.rb +22 -19
  19. data/app/models/lesli_shield/invite.rb +183 -12
  20. data/app/services/lesli_shield/invitation_audit.rb +34 -0
  21. data/app/services/lesli_shield/invitation_email_policy.rb +64 -0
  22. data/app/services/lesli_shield/invitation_service.rb +405 -0
  23. data/app/services/lesli_shield/invite_service.rb +34 -5
  24. data/app/services/lesli_shield/profile_service.rb +1 -0
  25. data/app/services/lesli_shield/role_action_service.rb +37 -92
  26. data/app/services/lesli_shield/role_audit.rb +42 -0
  27. data/app/services/lesli_shield/role_permission_service.rb +347 -0
  28. data/app/services/lesli_shield/role_privilege_deployment_service.rb +79 -0
  29. data/app/services/lesli_shield/role_privilege_service.rb +69 -105
  30. data/app/services/lesli_shield/role_service.rb +431 -0
  31. data/app/services/lesli_shield/user_registration_service.rb +1 -1
  32. data/app/services/lesli_shield/user_validator_service.rb +9 -9
  33. data/app/views/devise/confirmations/new.html.erb +5 -5
  34. data/app/views/devise/confirmations/show.html.erb +3 -3
  35. data/app/views/devise/passwords/edit.html.erb +7 -7
  36. data/app/views/devise/passwords/new.html.erb +7 -7
  37. data/app/views/devise/registrations/new.html.erb +13 -13
  38. data/app/views/devise/sessions/new.html.erb +8 -8
  39. data/app/views/devise/shared/_demo.html.erb +3 -3
  40. data/app/views/devise/shared/_links.html.erb +8 -11
  41. data/app/views/lesli_shield/invites/_form.html.erb +64 -7
  42. data/app/views/lesli_shield/invites/_invite.html.erb +55 -2
  43. data/app/views/lesli_shield/invites/_invite_actions.html.erb +34 -0
  44. data/app/views/lesli_shield/invites/_status_badge.html.erb +13 -0
  45. data/app/views/lesli_shield/invites/index.html.erb +119 -63
  46. data/app/views/lesli_shield/invites/new.html.erb +11 -36
  47. data/app/views/lesli_shield/invites/show.html.erb +13 -52
  48. data/app/views/lesli_shield/profiles/_information-form.html.erb +11 -0
  49. data/app/views/lesli_shield/profiles/show.html.erb +1 -4
  50. data/app/views/lesli_shield/role/actions/_custom_actions.html.erb +24 -0
  51. data/app/views/lesli_shield/role/actions/_deployment_status.html.erb +14 -0
  52. data/app/views/lesli_shield/role/actions/_matrix.html.erb +69 -0
  53. data/app/views/lesli_shield/role/actions/_permissions.html.erb +95 -0
  54. data/app/views/lesli_shield/role/actions/_toggle.html.erb +34 -0
  55. data/app/views/lesli_shield/role/actions/index.html.erb +14 -10
  56. data/app/views/lesli_shield/roles/_deployment_badge.html.erb +15 -0
  57. data/app/views/lesli_shield/roles/_empty_state.html.erb +20 -0
  58. data/app/views/lesli_shield/roles/_field_errors.html.erb +5 -0
  59. data/app/views/lesli_shield/roles/_filters.html.erb +66 -0
  60. data/app/views/lesli_shield/roles/_form.html.erb +149 -18
  61. data/app/views/lesli_shield/roles/_management_menu.html.erb +37 -0
  62. data/app/views/lesli_shield/roles/_pagination.html.erb +43 -0
  63. data/app/views/lesli_shield/roles/_role_list.html.erb +116 -0
  64. data/app/views/lesli_shield/roles/_status_badge.html.erb +11 -0
  65. data/app/views/lesli_shield/roles/_type_badge.html.erb +9 -0
  66. data/app/views/lesli_shield/roles/index.html.erb +15 -38
  67. data/app/views/lesli_shield/roles/new.html.erb +11 -0
  68. data/app/views/lesli_shield/roles/show.html.erb +79 -7
  69. data/app/views/lesli_shield/users/_information-form.html.erb +6 -0
  70. data/app/views/users/invitations/show.html.erb +142 -0
  71. data/app/views/users/invitations/unavailable.html.erb +19 -0
  72. data/config/locales/devise.en.yml +8 -0
  73. data/config/locales/devise.es.yml +8 -0
  74. data/config/locales/translations.en.yml +313 -78
  75. data/config/locales/translations.es.yml +313 -78
  76. data/config/routes.rb +10 -3
  77. data/db/migrate/v1/0801120110_create_lesli_shield_invites.rb +40 -6
  78. data/lib/lesli_shield/engine.rb +4 -0
  79. data/lib/lesli_shield/router.rb +10 -0
  80. data/lib/lesli_shield/version.rb +2 -2
  81. data/lib/tasks/lesli_shield_tasks.rake +1 -1
  82. data/readme.md +13 -1
  83. metadata +35 -5
  84. data/app/mailers/lesli_shield/invitation.html.erb +0 -23
  85. data/app/views/lesli_shield/invites/edit.html.erb +0 -12
  86. data/app/views/lesli_shield/role/actions/_form.html.erb +0 -75
@@ -1,54 +1,15 @@
1
- <%#
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
- // ·
1
+ <%
2
+ recipient = @invite.full_name.presence || @invite.email
31
3
  %>
32
- <%= render LesliView::Layout::Container.new('shield-invites') do %>
33
- <%= render LesliView::Components::Header.new("Invite for #{ @invite.full_name.presence || @invite.email }") do %>
34
- <%= render(LesliView::Elements::Button.new(
35
- 'Send invitation',
36
- success:true,
37
- solid:true,
38
- icon:'send',
39
- url: invite_path(@invite),
40
- method: :put,
41
- params: { invite: { status: :sent } }
42
- )) %>
43
- <%= render(LesliView::Elements::Button.new(
44
- 'Cancel invitation',
45
- danger:true,
46
- solid:true,
47
- icon:'cancel',
48
- url: invite_path(@invite),
49
- method: :put,
50
- params: { invite: { status: :cancelled } }
51
- )) %>
4
+
5
+ <%= render LesliView::Layout::Container.new("shield-invites") do %>
6
+ <%= render LesliView::Components::Header.new(
7
+ I18n.t("lesli_shield.invites.detail_title", recipient: recipient),
8
+ nil,
9
+ back: invites_path
10
+ ) do %>
11
+ <%= render "invite_actions", invite: @invite, show_view: false %>
52
12
  <% end %>
53
- <%= render "form" %>
54
- <% end %>
13
+
14
+ <%= render "invite", invite: @invite %>
15
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <div id="shield-profile-information-form">
2
+ <% if @user.errors.any? %>
3
+ <div role="alert">
4
+ <% @user.errors.full_messages.each do |message| %>
5
+ <p><%= message %></p>
6
+ <% end %>
7
+ </div>
8
+ <% end %>
9
+
10
+ <%= render "lesli_shield/users/information-form", form_url: profile_path %>
11
+ </div>
@@ -9,10 +9,7 @@
9
9
  title: I18n.t("lesli_shield.profiles.information"),
10
10
  icon: "info"
11
11
  ) do %>
12
- <%= render(
13
- "lesli_shield/users/information-form",
14
- form_url: profile_path
15
- ) %>
12
+ <%= render "lesli_shield/profiles/information-form" %>
16
13
  <% end %>
17
14
 
18
15
  <% tabs.with_tab(
@@ -0,0 +1,24 @@
1
+ <div class="divide-y divide-slate-200 border-t border-slate-200" data-custom-actions>
2
+ <h3 class="px-4 py-3 text-sm font-semibold text-slate-900 sm:px-5">
3
+ <%= t("lesli_shield.roles.permissions_custom_actions") %>
4
+ </h3>
5
+ <% resources.each do |resource| %>
6
+ <fieldset class="px-4 py-5 sm:px-5">
7
+ <legend class="w-full">
8
+ <span class="block text-sm font-semibold text-slate-900"><%= resource[:label] %></span>
9
+ <span class="mt-0.5 block break-all font-mono text-xs text-slate-500"><%= resource[:route] %></span>
10
+ </legend>
11
+ <div class="mt-4 grid gap-3 sm:grid-cols-2 xl:grid-cols-3">
12
+ <% resource[:actions].reject { |action| action[:standard] }.each do |action| %>
13
+ <div class="flex min-h-14 items-start gap-3 rounded-xl border border-slate-200 bg-white p-3">
14
+ <%= render "toggle", action: action %>
15
+ <span class="min-w-0 flex-1">
16
+ <span class="block text-sm font-semibold text-slate-900"><%= action[:display_label] %></span>
17
+ <span class="mt-0.5 block break-all font-mono text-xs text-slate-500"><%= action[:action] %></span>
18
+ </span>
19
+ </div>
20
+ <% end %>
21
+ </div>
22
+ </fieldset>
23
+ <% end %>
24
+ </div>
@@ -0,0 +1,14 @@
1
+ <div
2
+ id="role-permission-deployment-status"
3
+ class="flex min-h-10 items-center gap-2 rounded-xl border border-slate-200 bg-white px-3 shadow-sm"
4
+ >
5
+ <%= render "lesli_shield/roles/deployment_badge", role: @role %>
6
+ <% if @role.deployed_at.present? %>
7
+ <time
8
+ datetime="<%= @role.deployed_at.iso8601 %>"
9
+ class="hidden text-xs text-slate-500 sm:inline"
10
+ >
11
+ <%= l(@role.deployed_at, format: :short) %>
12
+ </time>
13
+ <% end %>
14
+ </div>
@@ -0,0 +1,69 @@
1
+ <%
2
+ standard_action_names = LesliShield::RolePermissionService::STANDARD_ACTION_ORDER
3
+ %>
4
+
5
+ <% @permission_matrix.each do |engine| %>
6
+ <%
7
+ engine_actions = engine[:resources].flat_map { |resource| resource[:actions] }
8
+ standard_resources = engine[:resources].select { |resource| resource[:actions].any? { |action| action[:standard] } }
9
+ custom_resources = engine[:resources].select { |resource| resource[:actions].any? { |action| !action[:standard] } }
10
+ %>
11
+ <section
12
+ id="permission-engine-<%= engine[:engine].parameterize %>"
13
+ class="scroll-mt-4 overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm"
14
+ >
15
+ <header class="flex items-center justify-between gap-4 border-b border-slate-200 bg-slate-50 px-4 py-4 sm:px-5">
16
+ <h2 class="font-semibold text-slate-900"><%= engine[:label] %></h2>
17
+ <p class="text-right text-xs text-slate-600">
18
+ <%= t(
19
+ "lesli_shield.roles.permissions_module_summary",
20
+ selected: engine_actions.count { |action| action[:assigned] },
21
+ total: engine_actions.size
22
+ ) %>
23
+ </p>
24
+ </header>
25
+
26
+ <% if standard_resources.any? %>
27
+ <table class="block w-full xl:table">
28
+ <thead class="hidden bg-slate-50 xl:table-header-group">
29
+ <tr>
30
+ <th scope="col" class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500 sm:px-5">
31
+ <%= t("lesli_shield.roles.permissions_resource") %>
32
+ </th>
33
+ <% standard_action_names.each do |action_name| %>
34
+ <th scope="col" class="px-2 py-3 text-center text-xs font-semibold uppercase tracking-wide text-slate-500">
35
+ <%= t("lesli_shield.roles.permissions_standard_actions_#{action_name}") %>
36
+ </th>
37
+ <% end %>
38
+ </tr>
39
+ </thead>
40
+ <tbody class="block divide-y divide-slate-200 xl:table-row-group">
41
+ <% standard_resources.each do |resource| %>
42
+ <tr class="block p-4 xl:table-row xl:p-0">
43
+ <th scope="row" class="block pb-3 text-left xl:table-cell xl:px-5 xl:py-4 xl:align-middle">
44
+ <span class="block text-sm font-semibold text-slate-900"><%= resource[:label] %></span>
45
+ <span class="mt-0.5 block break-all font-mono text-xs font-normal text-slate-500"><%= resource[:route] %></span>
46
+ </th>
47
+ <% standard_action_names.each do |action_name| %>
48
+ <% action = resource[:actions].find { |candidate| candidate[:action] == action_name } %>
49
+ <td class="block py-1 xl:table-cell xl:px-2 xl:py-4 xl:text-center xl:align-middle">
50
+ <% if action %>
51
+ <div class="flex min-h-11 items-center justify-between gap-3 rounded-lg px-2 py-2 transition hover:bg-sky-50 xl:flex-col xl:justify-center">
52
+ <span class="text-sm font-medium text-slate-700 xl:sr-only"><%= action[:display_label] %></span>
53
+ <%= render "toggle", action: action %>
54
+ </div>
55
+ <% else %>
56
+ <span class="hidden text-slate-300 xl:inline" aria-label="<%= t("lesli_shield.roles.permissions_not_available") %>">—</span>
57
+ <% end %>
58
+ </td>
59
+ <% end %>
60
+ </tr>
61
+ <% end %>
62
+ </tbody>
63
+ </table>
64
+ <% end %>
65
+ <% if custom_resources.any? %>
66
+ <%= render "custom_actions", resources: custom_resources %>
67
+ <% end %>
68
+ </section>
69
+ <% end %>
@@ -0,0 +1,95 @@
1
+ <%
2
+ index_path = if @engine_slug
3
+ engine_role_actions_path(@role, engine_slug: @engine_slug)
4
+ else
5
+ role_actions_path(@role)
6
+ end
7
+
8
+ navigation_items = [{
9
+ label: t("lesli_shield.roles.detail_summary_title"),
10
+ path: role_path(@role),
11
+ selected: false
12
+ }]
13
+ engines = [
14
+ {
15
+ slug: nil,
16
+ label: t("lesli_shield.roles.permissions_all_engines"),
17
+ count: @permission_engines.sum { |engine| engine[:count] }
18
+ },
19
+ *@permission_engines
20
+ ]
21
+ engines.each do |engine|
22
+ path = if engine[:slug]
23
+ engine_role_actions_path(@role, engine_slug: engine[:slug], search: @search.presence)
24
+ else
25
+ role_actions_path(@role, search: @search.presence)
26
+ end
27
+ navigation_items << {
28
+ label: engine[:label],
29
+ count: engine[:count],
30
+ path: path,
31
+ selected: @engine_slug == engine[:slug]
32
+ }
33
+ end
34
+ %>
35
+
36
+ <div id="shield-role-permissions" class="flex min-w-0 flex-col gap-6 lg:flex-row lg:items-start">
37
+ <%= render LesliView::Layout::NavigationSidebar.new(
38
+ items: navigation_items,
39
+ label: t("lesli_shield.roles.permissions_engine_navigation")
40
+ ) %>
41
+ <div class="min-w-0 flex-1 space-y-6">
42
+ <section class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm sm:p-5" aria-labelledby="permission-tools-title">
43
+ <h2 id="permission-tools-title" class="sr-only">
44
+ <%= t("lesli_shield.roles.permissions_tools") %>
45
+ </h2>
46
+
47
+ <%= form_with(
48
+ url: index_path,
49
+ method: :get,
50
+ data: { turbo_frame: "_top" },
51
+ class: "flex flex-col gap-3 sm:flex-row sm:items-end"
52
+ ) do |form| %>
53
+ <div class="min-w-0 flex-1">
54
+ <%= form.label :search,
55
+ t("lesli_shield.roles.permissions_search_label"),
56
+ class: "block text-sm font-medium text-slate-700" %>
57
+ <div class="relative mt-1.5">
58
+ <span class="pointer-events-none absolute inset-y-0 left-3 flex items-center text-slate-400" aria-hidden="true">
59
+ <span class="material-symbols">search</span>
60
+ </span>
61
+ <%= form.search_field :search,
62
+ value: @search,
63
+ autocomplete: "off",
64
+ class: "block min-h-11 w-full rounded-xl border border-slate-300 bg-white py-2.5 pl-10 pr-3 text-sm text-slate-900 shadow-sm outline-none transition placeholder:text-slate-400 focus:border-sky-500 focus:ring-4 focus:ring-sky-500/10",
65
+ placeholder: t("lesli_shield.roles.permissions_search_placeholder") %>
66
+ </div>
67
+ </div>
68
+ <div class="flex gap-2">
69
+ <%= render LesliView::Elements::Button.new(t("lesli_shield.roles.permissions_search"), type: :submit, icon: "search") %>
70
+ <% if @search.present? %>
71
+ <%= link_to t("lesli_shield.roles.permissions_clear_search"),
72
+ index_path,
73
+ data: { turbo_frame: "_top" },
74
+ class: "inline-flex min-h-11 items-center justify-center rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-700 transition hover:bg-slate-50 focus-visible:outline-none focus-visible:ring-4 focus-visible:ring-sky-500/20" %>
75
+ <% end %>
76
+ </div>
77
+ <% end %>
78
+ </section>
79
+
80
+ <div class="min-w-0 space-y-4">
81
+ <% if @permission_matrix.any? %>
82
+ <%= render "matrix" %>
83
+ <% else %>
84
+ <div class="rounded-xl border border-dashed border-slate-300 bg-slate-50 px-6 py-10 text-center">
85
+ <% if @search.present? %>
86
+ <p class="text-sm font-semibold text-slate-800"><%= t("lesli_shield.roles.permissions_no_matches") %></p>
87
+ <p class="mt-1 text-sm text-slate-500"><%= t("lesli_shield.roles.permissions_no_matches_hint") %></p>
88
+ <% else %>
89
+ <p class="text-sm font-medium text-slate-700"><%= t("lesli_shield.roles.permissions_empty") %></p>
90
+ <% end %>
91
+ </div>
92
+ <% end %>
93
+ </div>
94
+ </div>
95
+ </div>
@@ -0,0 +1,34 @@
1
+ <%
2
+ enabled = action[:assigned]
3
+ route_options = { search: @search.presence }
4
+ route_options[:engine_slug] = @engine_slug if @engine_slug
5
+ path = if enabled
6
+ role_action_path(@role, action[:id], **route_options)
7
+ else
8
+ role_actions_path(@role, **route_options)
9
+ end
10
+ method = enabled ? :delete : :post
11
+ request_params = enabled ? {} : { action_id: action[:id] }
12
+ label = t(
13
+ "lesli_shield.roles.permissions_toggle",
14
+ action: action[:display_label],
15
+ state: t("lesli_shield.roles.permissions_states_#{enabled ? 'enabled' : 'disabled'}")
16
+ )
17
+ %>
18
+
19
+ <%= button_to(
20
+ path,
21
+ method: method,
22
+ params: request_params,
23
+ form: { class: "shrink-0" },
24
+ class: class_names(
25
+ "inline-flex size-6 items-center justify-center rounded-md border transition focus-visible:outline-none focus-visible:ring-4 focus-visible:ring-sky-500/20",
26
+ "border-sky-600 bg-sky-600 text-white hover:bg-sky-700" => enabled,
27
+ "border-slate-300 bg-white text-transparent hover:border-sky-500" => !enabled
28
+ ),
29
+ role: "switch",
30
+ aria: { checked: enabled, label: label },
31
+ data: { turbo_submits_with: "…" }
32
+ ) do %>
33
+ <span class="material-symbols text-lg" aria-hidden="true">check</span>
34
+ <% end %>
@@ -1,14 +1,18 @@
1
1
  <%= render LesliView::Layout::Container.new("shield-role-actions") do %>
2
- <%= render LesliView::Components::Header.new("#{@role.name} privileges", :back => role_path(@role)) do %>
3
- <%= render(LesliView::Elements::Button.new('Deploy privileges',
4
- solid:true,
5
- danger:true,
6
- icon: 'shield',
7
- css_class: 'is-light is-hovered',
8
- url: deploy_role_path(@role.id),
2
+ <%= render LesliView::Components::Header.new(
3
+ t("lesli_shield.roles.permissions_title", role: @role.name),
4
+ back: role_path(@role)
5
+ ) do %>
6
+ <%= render "deployment_status" %>
7
+ <%= render(LesliView::Elements::Button.new(
8
+ t("lesli_shield.roles.permissions_deploy"),
9
+ solid: true,
10
+ danger: true,
11
+ icon: "shield",
12
+ url: deploy_role_path(@role, engine_slug: @engine_slug, search: @search.presence),
9
13
  method: :post
10
-
11
14
  )) %>
12
15
  <% end %>
13
- <%= render "form" %>
14
- <% end %>
16
+
17
+ <%= render "permissions" %>
18
+ <% end %>
@@ -0,0 +1,15 @@
1
+ <%
2
+ status = role.permissions_deployment_status
3
+ styles = {
4
+ pending: "bg-amber-100 text-amber-800 ring-amber-200",
5
+ deployed: "bg-emerald-100 text-emerald-700 ring-emerald-200",
6
+ never_deployed: "bg-slate-100 text-slate-600 ring-slate-200"
7
+ }
8
+ %>
9
+
10
+ <span
11
+ class="inline-flex items-center rounded-full px-2.5 py-1 text-xs font-semibold ring-1 ring-inset <%= styles.fetch(status) %>"
12
+ data-role-deployment-status="<%= status %>"
13
+ >
14
+ <%= t("lesli_shield.roles.deployment_statuses_#{status}") %>
15
+ </span>
@@ -0,0 +1,20 @@
1
+ <%
2
+ filtered = filters.values.any?(&:present?)
3
+ title_key = filtered ? "empty_filtered_title" : "empty_title"
4
+ description_key = filtered ? "empty_filtered_description" : "empty_description"
5
+ action_key = filtered ? "empty_filtered_action" : "action_create"
6
+ action_path = filtered ? roles_path : new_role_path
7
+ %>
8
+
9
+ <section class="rounded-2xl border border-dashed border-slate-300 bg-white px-6 py-16 text-center shadow-sm">
10
+ <span class="material-symbols mx-auto block text-5xl text-slate-300" aria-hidden="true">admin_panel_settings</span>
11
+ <h2 class="mt-4 text-lg font-semibold text-slate-900">
12
+ <%= t("lesli_shield.roles.#{title_key}") %>
13
+ </h2>
14
+ <p class="mx-auto mt-2 max-w-md text-sm leading-6 text-slate-500">
15
+ <%= t("lesli_shield.roles.#{description_key}") %>
16
+ </p>
17
+ <%= render LesliView::Elements::Button.new(t("lesli_shield.roles.#{action_key}"),
18
+ url: action_path,
19
+ solid: false, data: { turbo_frame: "_top" }) %>
20
+ </section>
@@ -0,0 +1,5 @@
1
+ <% record.errors[attribute].each do |message| %>
2
+ <p class="mt-1.5 text-sm text-red-600">
3
+ <%= message %>
4
+ </p>
5
+ <% end %>
@@ -0,0 +1,66 @@
1
+ <%= form_with url: roles_path,
2
+ method: :get,
3
+ local: true,
4
+ class: "mb-6 rounded-2xl border border-slate-200 bg-white p-4 shadow-sm",
5
+ role: "search",
6
+ data: { turbo_frame: "_top" } do %>
7
+
8
+ <% %w[perPage orderBy order].each do |parameter| %>
9
+ <%= hidden_field_tag parameter, params[parameter] if params[parameter].present? %>
10
+ <% end %>
11
+
12
+ <div class="grid gap-3 lg:grid-cols-[minmax(16rem,1fr)_13rem_13rem_auto] lg:items-end">
13
+ <div>
14
+ <%= label_tag :search,
15
+ t("lesli_shield.roles.filters_search_label"),
16
+ class: "mb-1.5 block text-sm font-medium text-slate-700" %>
17
+ <div class="relative">
18
+ <span class="material-symbols pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-xl text-slate-400" aria-hidden="true">search</span>
19
+ <%= search_field_tag :search,
20
+ filters[:search],
21
+ placeholder: t("lesli_shield.roles.filters_search_placeholder"),
22
+ autocomplete: "off",
23
+ class: "h-11 w-full rounded-xl border border-slate-300 bg-white py-2 pl-10 pr-10 text-sm text-slate-900 outline-none transition placeholder:text-slate-400 hover:border-slate-400 focus:border-sky-500 focus:ring-4 focus:ring-sky-500/10" %>
24
+ <% if filters[:search].present? %>
25
+ <%= link_to roles_path(request.query_parameters.except("search", "page")),
26
+ class: "absolute right-2 top-1/2 inline-flex h-7 w-7 -translate-y-1/2 items-center justify-center rounded-lg text-slate-400 transition hover:bg-slate-100 hover:text-slate-700",
27
+ data: { turbo_frame: "_top" },
28
+ aria: { label: t("lesli_shield.roles.filters_clear_search") } do %>
29
+ <span class="material-symbols text-lg" aria-hidden="true">close</span>
30
+ <% end %>
31
+ <% end %>
32
+ </div>
33
+ </div>
34
+
35
+ <div>
36
+ <%= label_tag :status,
37
+ t("lesli_shield.roles.filters_status_label"),
38
+ class: "mb-1.5 block text-sm font-medium text-slate-700" %>
39
+ <%= select_tag :status,
40
+ options_for_select([
41
+ [t("lesli_shield.roles.filters_status_all"), ""],
42
+ [t("lesli_shield.roles.statuses_active"), "active"],
43
+ [t("lesli_shield.roles.statuses_inactive"), "inactive"]
44
+ ], filters[:status]),
45
+ class: "h-11 w-full rounded-xl border border-slate-300 bg-white px-3 text-sm text-slate-700 outline-none transition hover:border-slate-400 focus:border-sky-500 focus:ring-4 focus:ring-sky-500/10" %>
46
+ </div>
47
+
48
+ <div>
49
+ <%= label_tag :type,
50
+ t("lesli_shield.roles.filters_type_label"),
51
+ class: "mb-1.5 block text-sm font-medium text-slate-700" %>
52
+ <%= select_tag :type,
53
+ options_for_select([
54
+ [t("lesli_shield.roles.filters_type_all"), ""],
55
+ [t("lesli_shield.roles.types_system"), "system"],
56
+ [t("lesli_shield.roles.types_custom"), "custom"]
57
+ ], filters[:type]),
58
+ class: "h-11 w-full rounded-xl border border-slate-300 bg-white px-3 text-sm text-slate-700 outline-none transition hover:border-slate-400 focus:border-sky-500 focus:ring-4 focus:ring-sky-500/10" %>
59
+ </div>
60
+
61
+ <%= render LesliView::Elements::Button.new(
62
+ t("lesli_shield.roles.filters_submit"), type: :submit, icon: "filter_alt",
63
+ data: { turbo_submits_with: t("lesli_shield.roles.filters_loading") }
64
+ ) %>
65
+ </div>
66
+ <% end %>
@@ -1,21 +1,152 @@
1
- <%= form_with(model: @role, builder: LesliView::Forms::Builder) do |form| %>
2
- <%= form.fieldset do %>
3
- <%= form.field_control(:name) %>
4
- <div class="columns">
5
- <div class="column">
6
- <%= form.field_control_select(:active, [["Activo", true], ["Desactivado", false]], label: "Status") %>
1
+ <%
2
+ editable = @role.new_record? || @role_editable
3
+ input_classes = "mt-1.5 block w-full rounded-xl border border-slate-300 bg-white px-3 py-2.5 text-sm text-slate-900 shadow-sm outline-none transition placeholder:text-slate-400 hover:border-slate-400 focus:border-sky-500 focus:ring-4 focus:ring-sky-500/10 disabled:cursor-not-allowed disabled:bg-slate-50 disabled:text-slate-500"
4
+ error_input_classes = "border-red-400 focus:border-red-500 focus:ring-red-500/10"
5
+ members_count = @role_summary&.fetch(:members, 0).to_i
6
+ members_plural = members_count == 1 ? "one" : "other"
7
+ %>
8
+
9
+ <div id="role-form">
10
+ <%= form_with model: @role,
11
+ id: "role-form-fields",
12
+ class: "space-y-6",
13
+ data: { turbo: true, turbo_frame: "_top" } do |form| %>
14
+ <% if @role.errors.any? %>
15
+ <div class="rounded-xl border border-red-200 bg-red-50 p-4" role="alert">
16
+ <div class="flex gap-3">
17
+ <span class="material-symbols text-red-500" aria-hidden="true">error</span>
18
+ <div>
19
+ <h2 class="text-sm font-semibold text-red-800">
20
+ <%= t("lesli_shield.roles.form_errors_title") %>
21
+ </h2>
22
+ <ul class="mt-2 list-disc space-y-1 pl-5 text-sm text-red-700">
23
+ <% @role.errors.full_messages.each do |message| %>
24
+ <li><%= message %></li>
25
+ <% end %>
26
+ </ul>
27
+ </div>
28
+ </div>
7
29
  </div>
8
- <div class="column">
9
- <%#= form.field_control_select(:isolated, LesliBabel::Label.prefixes) %>
30
+ <% end %>
31
+
32
+ <div class="space-y-5">
33
+ <div>
34
+ <%= form.label :name, t("lesli_shield.roles.fields_name"), class: "block text-sm font-medium text-slate-700" %>
35
+ <%= form.text_field :name,
36
+ autofocus: @role.new_record?,
37
+ disabled: !editable,
38
+ autocomplete: "off",
39
+ class: class_names(input_classes, error_input_classes => @role.errors[:name].any?) %>
40
+ <%= render "field_errors", record: @role, attribute: :name %>
41
+ </div>
42
+
43
+ <div>
44
+ <%= form.label :description, t("lesli_shield.roles.fields_description"), class: "block text-sm font-medium text-slate-700" %>
45
+ <%= form.text_area :description,
46
+ rows: 4,
47
+ disabled: !editable,
48
+ class: class_names(input_classes, "resize-y", error_input_classes => @role.errors[:description].any?) %>
49
+ <p class="mt-1.5 text-xs leading-5 text-slate-500">
50
+ <%= t("lesli_shield.roles.form_description_hint") %>
51
+ </p>
52
+ <%= render "field_errors", record: @role, attribute: :description %>
53
+ </div>
54
+ </div>
55
+
56
+ <% if @role.new_record? %>
57
+ <fieldset class="border-t border-slate-200 pt-6">
58
+ <legend class="text-sm font-medium text-slate-700">
59
+ <%= t("lesli_shield.roles.fields_status") %>
60
+ </legend>
61
+
62
+ <div class="mt-3 grid gap-3 sm:grid-cols-2">
63
+ <% [true, false].each do |active| %>
64
+ <label class="relative flex cursor-pointer gap-3 rounded-xl border border-slate-200 bg-white p-4 transition hover:border-sky-300 hover:bg-sky-50/40 has-[:checked]:border-sky-500 has-[:checked]:ring-4 has-[:checked]:ring-sky-500/10">
65
+ <%= form.radio_button :active,
66
+ active,
67
+ class: "mt-0.5 h-4 w-4 border-slate-300 text-sky-600 focus:ring-sky-500" %>
68
+ <span>
69
+ <span class="block text-sm font-semibold text-slate-900">
70
+ <%= t("lesli_shield.roles.statuses_#{active ? 'active' : 'inactive'}") %>
71
+ </span>
72
+ <span class="mt-1 block text-xs leading-5 text-slate-500">
73
+ <%= t("lesli_shield.roles.form_status_#{active ? 'active' : 'inactive'}_hint") %>
74
+ </span>
75
+ </span>
76
+ </label>
77
+ <% end %>
78
+ </div>
79
+ <%= render "field_errors", record: @role, attribute: :active %>
80
+ </fieldset>
81
+ <% end %>
82
+
83
+ <div class="space-y-5 border-t border-slate-200 pt-6">
84
+ <div>
85
+ <%= form.label :permission_level, t("lesli_shield.roles.fields_permission_level"), class: "block text-sm font-medium text-slate-700" %>
86
+ <%= form.number_field :permission_level,
87
+ min: 0,
88
+ max: current_user.max_level_permission,
89
+ step: 1,
90
+ required: true,
91
+ disabled: !editable,
92
+ inputmode: "numeric",
93
+ class: class_names(input_classes, error_input_classes => @role.errors[:permission_level].any?) %>
94
+ <p class="mt-1.5 text-xs leading-5 text-slate-500">
95
+ <%= t("lesli_shield.roles.form_permission_level_hint", maximum: current_user.max_level_permission) %>
96
+ </p>
97
+ <%= render "field_errors", record: @role, attribute: :permission_level %>
98
+ </div>
99
+
100
+ <div>
101
+ <%= form.label :path_default, t("lesli_shield.roles.fields_path_default"), class: "block text-sm font-medium text-slate-700" %>
102
+ <%= form.text_field :path_default,
103
+ disabled: !editable,
104
+ placeholder: "/dashboard",
105
+ class: class_names(input_classes, error_input_classes => @role.errors[:path_default].any?) %>
106
+ <p class="mt-1.5 text-xs leading-5 text-slate-500">
107
+ <%= t("lesli_shield.roles.form_path_default_hint") %>
108
+ </p>
109
+ <%= render "field_errors", record: @role, attribute: :path_default %>
10
110
  </div>
11
111
  </div>
12
- <%= form.field_control(:description) %>
13
- <%= form.field_control(:active) %>
14
- <%= form.field_control(:path_default) %>
15
- <%= form.field_control(:path_limited) %>
16
- <%= form.field_control(:isolated) %>
17
- <%= form.field_control(:permission_level) %>
18
- <hr/>
19
- <%= form.field_control_submit %>
20
- <% end %>
21
- <% end %>
112
+
113
+ <% if editable %>
114
+ <div class="flex flex-col gap-3 border-t border-slate-200 pt-6 sm:flex-row sm:items-center sm:justify-between">
115
+ <div>
116
+ <% if @role.persisted? %>
117
+ <% if @role.active? %>
118
+ <%= render LesliView::Elements::Button.new(t("lesli_shield.roles.detail_deactivate"),
119
+ type: "submit",
120
+ name: "role[active]",
121
+ value: false,
122
+ warning: true,
123
+ data: {
124
+ turbo_confirm: t("lesli_shield.roles.detail_confirm_deactivate_#{members_plural}", role: @role.name, count: members_count),
125
+ turbo_submits_with: t("lesli_shield.roles.detail_deactivating")
126
+ }) %>
127
+ <% else %>
128
+ <%= render LesliView::Elements::Button.new(t("lesli_shield.roles.detail_activate"),
129
+ type: "submit",
130
+ name: "role[active]",
131
+ value: true,
132
+ success: true,
133
+ data: { turbo_submits_with: t("lesli_shield.roles.detail_activating") }) %>
134
+ <% end %>
135
+ <% end %>
136
+ </div>
137
+
138
+ <div class="flex flex-col-reverse gap-3 sm:flex-row sm:justify-end">
139
+ <%= render LesliView::Elements::Button.new(t("lesli_shield.roles.form_cancel"),
140
+ url: @role.persisted? ? role_path(@role) : roles_path,
141
+ solid: false, data: { turbo_frame: "_top" }) %>
142
+ <%= render LesliView::Elements::Button.new(@role.persisted? ? t("lesli_shield.roles.action_update") : t("lesli_shield.roles.action_create"),
143
+ type: :submit, data: { turbo_submits_with: t("lesli_shield.roles.action_saving") }) %>
144
+ </div>
145
+ </div>
146
+ <% else %>
147
+ <div class="rounded-xl border border-amber-200 bg-amber-50 p-4 text-sm leading-6 text-amber-800">
148
+ <%= t("lesli_shield.roles.form_protected_notice") %>
149
+ </div>
150
+ <% end %>
151
+ <% end %>
152
+ </div>