permission_forge 0.15.0 → 0.15.1

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +61 -0
  3. data/app/controllers/concerns/permission_forge/api/response_renderer.rb +5 -0
  4. data/app/controllers/permission_forge/api/audit_events_controller.rb +9 -0
  5. data/app/controllers/permission_forge/audit_events_controller.rb +11 -0
  6. data/app/controllers/permission_forge/people_controller.rb +3 -1
  7. data/app/controllers/permission_forge/permission_set_editor.rb +2 -0
  8. data/app/controllers/permission_forge/permission_sets_controller.rb +8 -43
  9. data/app/frontend/permission_forge/pf_admin.css +56 -3
  10. data/app/frontend/permission_forge/pf_admin.js +73 -0
  11. data/app/helpers/permission_forge/application_helper.rb +1 -0
  12. data/app/helpers/permission_forge/set_summaries_helper.rb +144 -0
  13. data/app/helpers/permission_forge/ui_helper.rb +4 -3
  14. data/app/views/permission_forge/audit_events/unavailable.html.erb +7 -0
  15. data/app/views/permission_forge/people/_audit_tab.html.erb +4 -0
  16. data/app/views/permission_forge/permission_sets/_audit_tab.html.erb +4 -0
  17. data/app/views/permission_forge/permission_sets/_overview_body.html.erb +58 -0
  18. data/app/views/permission_forge/permission_sets/_set_summary_cells.html.erb +53 -0
  19. data/app/views/permission_forge/permission_sets/_set_summary_links.html.erb +14 -0
  20. data/app/views/permission_forge/permission_sets/index.html.erb +20 -14
  21. data/app/views/permission_forge/permission_sets/overview.html.erb +24 -0
  22. data/app/views/permission_forge/shared/_audit_unavailable.html.erb +2 -0
  23. data/config/locales/permission_forge.en.yml +114 -0
  24. data/config/locales/permission_forge.mk.yml +117 -0
  25. data/config/locales/permission_forge.sq.yml +117 -0
  26. data/config/routes.rb +1 -0
  27. data/lib/permission_forge/admin/last_changes.rb +1 -1
  28. data/lib/permission_forge/admin/permission_set_list.rb +62 -0
  29. data/lib/permission_forge/admin/set_overview.rb +100 -0
  30. data/lib/permission_forge/admin/set_summaries.rb +174 -0
  31. data/lib/permission_forge/admin/state_label.rb +3 -1
  32. data/lib/permission_forge/api/schema.rb +4 -2
  33. data/lib/permission_forge/audit/audited_views.rb +20 -2
  34. data/lib/permission_forge/cache/rails_cache.rb +23 -6
  35. data/lib/permission_forge/concerns/masked_attributes/alias_access.rb +28 -2
  36. data/lib/permission_forge/version.rb +1 -1
  37. data/lib/permission_forge.rb +3 -0
  38. metadata +11 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18f24fa6f5c842347328a3050e4d4b92050d792cb6e9552ad29b93902f480def
4
- data.tar.gz: f8135e00a5decceeec38ee17f15be8c5c5001a0bdbd31fdfa3e22869c72d8810
3
+ metadata.gz: cfdc65c9b331c97f7c94fcc5a3b606f1e3089de94750e023834fa34fe13ea4ef
4
+ data.tar.gz: 452a23bcf55549252dad762db8f590c9025c3b375b41b549a6430ed27699e1fe
5
5
  SHA512:
6
- metadata.gz: 54095cad99febbc8b214ee3f51583de33a842a7403b09ff8821441784d0dd310d7ac76637cce378dd04256d13da12551df1ccac56a0fe276e80d01329f946a74
7
- data.tar.gz: 0a41b292de1cd954238981110e1ccd95f58bef7c640791c7f8dc81157ee2a6149dddee286cb7b1ccbba654d010882a57c4035379882a05100601ccbe447f4481
6
+ metadata.gz: 9a553355ade53517006ac4bc8d2fbb014bf04dd74defa902722b35f195f265af18507a9bca034abe9e33445a33d529d14c0a7e0652e6ebbdb54a9a34ba49f884
7
+ data.tar.gz: e5926123f004dec7944d26c1c5fad2905268ad37562f933f8638fac9cb87176702ec992397a7ae471da3d434388feac279651ed79e3001f3554df115087a9471
data/CHANGELOG.md CHANGED
@@ -6,6 +6,67 @@ defaults, and every such change is listed under **Changed** with its opt-out.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.15.1] - 2026-11-17
10
+
11
+ ### Added
12
+
13
+ - **The Permission Sets list summarises each set.** New columns give the number of Resources (and the share of the
14
+ app's models), what they allow (Full access, Read-only, Some changes, or Takes access away for a muting set, with
15
+ the Read, Create, Edit and Delete counts and how many Resources have View All and Modify All) and what narrows them
16
+ (active row rules and masked fields, each with the number of Resources it is on; rules that View All bypasses are
17
+ counted as ignored). The counts read `PermissionHashBuilder.granted_flags` and `FieldLevel`, so a row written past
18
+ the validations counts for what it grants, and the list reads the same number of queries whatever the number of
19
+ sets and Resources (#24).
20
+ <!-- pin: test/permission_forge/html/permission_sets_index_summary_test.rb#a row summarises the set instead of listing its Resource names -->
21
+ <!-- pin: test/permission_forge/admin/set_summaries_test.rb#every granting flag combination is counted as PermissionHashBuilder.granted_flags grants it -->
22
+ <!-- pin: test/permission_forge/html/permission_sets_index_summary_test.rb#the list reads a constant number of queries, however many sets and Resources -->
23
+ - **A set's Resources open in place, by model group or one by one.** "Show model groups" and "Show Resources" on each row
24
+ load the new page `/permission_sets/:id/overview` under the row (without JavaScript it opens as a page): model groups by
25
+ namespace, then every Resource with its flags (`R C E D │ V M`) and its marks for row rules, rules View All bypasses
26
+ and masked fields. The counts in the Narrowed by column open the Resources they count.
27
+ <!-- pin: test/permission_forge/html/permission_sets_index_summary_test.rb#the overview page: groups, then one family, then the narrowed Resources -->
28
+ <!-- pin: test/permission_forge/html/permission_sets_index_summary_test.rb#with X-PF-Fragment the overview is the bare body the list loads in place -->
29
+ - **The Permission Sets search also finds a set by the name of one of its Resources**, and the row says which ones.
30
+ <!-- pin: test/permission_forge/html/permission_sets_index_summary_test.rb#a search finds a set by the name of one of its Resources and says which -->
31
+
32
+ ### Changed
33
+
34
+ - **The Permission Sets list no longer prints every Resource name under each set** (a set with a hundred Resources
35
+ made a row taller than the screen); the names are one click away in the overview above. **No opt-out:** the list's
36
+ layout is not configurable; the set's Resources tab is unchanged.
37
+ <!-- pin: test/permission_forge/html/permission_sets_index_summary_test.rb#a row summarises the set instead of listing its Resource names -->
38
+
39
+ ### Fixed
40
+
41
+ - **The audit screens no longer fail with a 500 while the audit table does not exist.** `config.audit_events = :auto`
42
+ promises that an unrun migration breaks nothing, but the Audit log page, an event page, the log's CSV and JSON exports,
43
+ the audit tabs of a person and of a Permission Set and `GET /api/audit_events` queried the table anyway
44
+ (`PG::UndefinedTable`). They now check `Admin::AuditLog.table?`, the check the Home card and the security audit already
45
+ use, on every request, so they recover as soon as the migration has run. The pages render a notice (run
46
+ `bin/rails generate permission_forge:upgrade` and migrate, or "audit events are turned off" for `false`); the exports
47
+ answer 503, and the API answers 503 in its usual error envelope. With `audit_events = true` the screens explain too
48
+ rather than raise: that setting makes a missing table fail changes loudly, and a screen that only reads has nothing to
49
+ fail, so a notice is more useful than a 500 (a view of the log is not recorded while there is no table). Only that
50
+ view is left out: an export that still has data without the table (who holds what, the changes CSVs) and a view of
51
+ someone's effective access are recorded as ever, so with `true` they still fail rather than go through unrecorded.
52
+ The API's 503 is declared in `Api::Schema::ERRORS`.
53
+ <!-- pin: test/permission_forge/html/audit_screens_without_table_test.rb#the log page and one event show the upgrade notice instead of failing -->
54
+ <!-- pin: test/permission_forge/html/audit_screens_without_table_test.rb#with audit_events true the screens still render with the failing notice -->
55
+ <!-- pin: test/permission_forge/api/audit_events_controller_test.rb#without the audit table the endpoints answer 503 in the error envelope, never 500 -->
56
+ <!-- pin: test/permission_forge/html/audit_screens_without_table_test.rb#with audit_events true an export or an effective access view is refused, never unrecorded -->
57
+ - **On Rails 8.2 (main), an alias an abstract class declares is guarded on the models below it.** Rails 8.2 generates
58
+ an abstract class's `alias_attribute` methods in each model below it, in front of the guarded reader and writer the
59
+ gem had placed on the abstract class: with `MaskedAttributes` on such a model, `record.mail` returned a hidden or
60
+ masked `email` as stored and a mask posted back through the alias was written. The accessors are now defined where
61
+ that Rails generates the methods (`AliasAccess.generated_in`; canary `inherited_alias_generation`). Rails 7.1 to 8.1
62
+ are not affected. <!-- pin: test/permission_forge/concerns/masked_attribute_aliases_test.rb#PfAliasConcrete: the alias reader returns what the column's getter returns -->
63
+ - **On Rails 8.2 (main), the memory, null and Memcached stores are written key by key again.** Rails 8.2's local-cache
64
+ layer overrides `write_multi_entries` only to forget the request's copies, and the memory and null stores now have
65
+ that layer, so `RailsCache.multi_write?` took them for stores that send one batch and trusted one answer for all
66
+ keys; Rails 8.2's Memcached store does send one batch but answers nil either way, so every bulk invalidation there
67
+ was reported as not confirmed. The check now looks past the layers named in `RailsCache::UNJUDGED_BATCHES`.
68
+ <!-- pin: test/permission_forge/cache/rails_cache_test.rb#a layer that only hands a batch on does not make a store a batching one -->
69
+
9
70
  ## [0.15.0] - 2026-10-19
10
71
 
11
72
  Upgrading from 0.14 is the three steps of the
@@ -93,6 +93,11 @@ module PermissionForge
93
93
  render json: { error: { status: 404, messages: msg } }, status: :not_found
94
94
  end
95
95
 
96
+ # 503: what the endpoint reads is not there (Api::Schema::ERRORS).
97
+ def render_unavailable(message)
98
+ render json: { error: { status: 503, messages: message } }, status: :service_unavailable
99
+ end
100
+
96
101
  def ams_serializer?(serializer_class)
97
102
  defined?(ActiveModel::Serializer) && serializer_class < ActiveModel::Serializer
98
103
  end
@@ -7,6 +7,7 @@ module PermissionForge
7
7
  # (Audit::LogAccess). Rows are tenant-scoped by the model.
8
8
  class AuditEventsController < BaseController
9
9
  before_action :authorize_audit_log!
10
+ before_action :require_audit_store!
10
11
 
11
12
  rescue_from PermissionForge::Audit::EventQuery::Invalid do |error|
12
13
  render_unprocessable(error.errors)
@@ -22,6 +23,14 @@ module PermissionForge
22
23
 
23
24
  private
24
25
 
26
+ # 503 in the usual error envelope while the audit table does not exist.
27
+ def require_audit_store!
28
+ return if PermissionForge::Admin::AuditLog.table?
29
+
30
+ key = PermissionForge::Admin::AuditLog.recording_problem == :off ? 'audit_unavailable_off' : 'audit_unavailable_missing'
31
+ render_unavailable(I18n.t("permission_forge.api.errors.#{key}"))
32
+ end
33
+
25
34
  def authorize_audit_log!
26
35
  return if PermissionForge::Audit::LogAccess.allowed?(self)
27
36
 
@@ -13,6 +13,7 @@ module PermissionForge
13
13
 
14
14
  pf_exports EXPORT_FORMATS.map(&:to_sym), only: %i[index holdings]
15
15
  before_action :pf_require_audit_log!
16
+ before_action :pf_require_audit_store!, except: :holdings
16
17
 
17
18
  def index
18
19
  @log = PermissionForge::Admin::AuditLog.new(params, include_views: export?)
@@ -39,6 +40,16 @@ module PermissionForge
39
40
 
40
41
  private
41
42
 
43
+ # Without the audit table there is nothing to read: the page says why
44
+ # (Admin::AuditLog.recording_problem), a file or a JSON read is a 503.
45
+ def pf_require_audit_store!
46
+ return if PermissionForge::Admin::AuditLog.table?
47
+ return head(:service_unavailable) unless request.format.html?
48
+
49
+ @problem = PermissionForge::Admin::AuditLog.recording_problem
50
+ render :unavailable
51
+ end
52
+
42
53
  def export?
43
54
  EXPORT_FORMATS.include?(request.format.symbol.to_s)
44
55
  end
@@ -147,10 +147,12 @@ module PermissionForge
147
147
  @why = params[:why].to_s
148
148
  end
149
149
 
150
- def load_audit_tab
150
+ def load_audit_tab # rubocop:disable Metrics/AbcSize -- the changes, then the timeline unless the table is missing
151
151
  @changes = audit.changes_by(@person.id, limit: CHANGES_SHOWN)
152
152
  @changes_capped = audit.capped?
153
153
  @views = pf_text_param(:views).presence # a Hash or a list is no toggle (it would reach url_for)
154
+ return unless PermissionForge::Admin::AuditLog.table? # no timeline without the table (the tab says so)
155
+
154
156
  @timeline_log = PermissionForge::Admin::AuditLog.new({ views: @views },
155
157
  scope: PermissionForge::Admin::AuditLog.for_person(@person.id))
156
158
  @timeline = @timeline_log.page(params[:page], per_page: TIMELINE_PER_PAGE)
@@ -57,6 +57,8 @@ module PermissionForge
57
57
 
58
58
  # The set's events, newest first (the log filtered by this set).
59
59
  def load_audit_timeline
60
+ return unless PermissionForge::Admin::AuditLog.table? # the tab says the log is not available
61
+
60
62
  @timeline_log = PermissionForge::Admin::AuditLog.new({ views: @views },
61
63
  scope: PermissionForge::Admin::AuditLog.for_permission_set(@permission_set))
62
64
  @timeline = @timeline_log.page(params[:page], per_page: AUDIT_TIMELINE_PER_PAGE)
@@ -10,30 +10,22 @@ module PermissionForge
10
10
  include PermissionForge::CopyRefusal
11
11
  include PermissionForge::CacheConfirmation
12
12
 
13
- FILTERS = %w[all granting muting conditional off].freeze
14
13
  TABS = %w[resources assignments conditions audit].freeze
15
14
 
16
- # List filter => predicate on a set ('all' and unknown filters match everything).
17
- FILTER_MATCHERS = {
18
- 'granting' => ->(set) { !set.is_muting },
19
- 'muting' => lambda(&:is_muting),
20
- 'conditional' => lambda(&:conditional?),
21
- 'off' => ->(set) { !set.is_active }
22
- }.freeze
23
-
24
15
  pf_exports %i[csv], only: :show # the audit tab
25
16
  before_action :set_permission_set, except: %i[index new create]
26
17
  before_action :reject_locked, only: %i[review apply destroy confirm_destroy switch_mode confirm_switch_mode conditions]
27
18
  before_action :reject_locked_group_move, only: %i[create review apply]
28
19
 
29
20
  def index
30
- @query = params[:q].to_s.strip
31
- @filter = filter_param
32
- all = PermissionForge::PermissionSet.includes(:permission_set_group, :resources).order(:name).to_a
33
- @total = all.size
34
- @counts = filter_counts(all)
35
- @permission_sets = all.select { |ps| filter_match?(ps, @filter) && query_match?(ps) }
36
- @people_counts = people_counts
21
+ @list = PermissionForge::Admin::PermissionSetList.new(query: pf_text_param(:q), filter: pf_text_param(:filter))
22
+ end
23
+
24
+ # One set's Resources by model family or one by one: a page of its own,
25
+ # and the fragment the list opens in place under the set's row.
26
+ def overview
27
+ @overview = PermissionForge::Admin::SetOverview.new(@permission_set, view: pf_text_param(:view),
28
+ only: pf_text_param(:only))
37
29
  end
38
30
 
39
31
  def new
@@ -173,33 +165,6 @@ module PermissionForge
173
165
  PermissionForge::Admin::ChangeSet.new(permission_set: @permission_set, params: pf_hash_param(:pf))
174
166
  end
175
167
 
176
- # --- list -----------------------------------------------------------------
177
-
178
- def filter_param
179
- filter = params[:filter]
180
- FILTERS.include?(filter) ? filter : 'all'
181
- end
182
-
183
- def filter_counts(sets)
184
- FILTERS.index_with { |filter| sets.count { |ps| filter_match?(ps, filter) } }
185
- end
186
-
187
- def filter_match?(set, filter)
188
- matcher = FILTER_MATCHERS[filter]
189
- matcher ? matcher.call(set) : true
190
- end
191
-
192
- def query_match?(set)
193
- return true if @query.empty?
194
-
195
- needle = @query.downcase
196
- [set.name, set.description].compact.any? { |v| v.downcase.include?(needle) }
197
- end
198
-
199
- def people_counts
200
- PermissionForge::PermissionSetUser.active_assignments.group(:permission_set_id).count
201
- end
202
-
203
168
  # --- create / duplicate -----------------------------------------------------
204
169
 
205
170
  def load_new_form
@@ -453,8 +453,59 @@
453
453
  .pf-root .pf-table__row--link a.pf-cell-person, .pf-root .pf-table__row--link a.pf-table__link { color: inherit; text-decoration: none; }
454
454
  .pf-table__row--link a.pf-cell-person::after, .pf-table__row--link a.pf-table__link::after { content: ''; position: absolute; inset: 0; }
455
455
  .pf-table--people .pf-table__head, .pf-table--people .pf-table__row { grid-template-columns: minmax(0, 1.2fr) minmax(0, 2fr) minmax(110px, .8fr); }
456
- .pf-table--sets { min-width: 560px; }
457
- .pf-table--sets .pf-table__head, .pf-table--sets .pf-table__row { grid-template-columns: minmax(0, 2fr) 56px 76px minmax(0, .8fr) auto; }
456
+ .pf-table--sets { min-width: 980px; }
457
+ .pf-table--sets .pf-table__row { align-items: start; }
458
+ .pf-table--sets .pf-table__head, .pf-table--sets .pf-table__row { grid-template-columns: minmax(0, 2fr) 96px 172px minmax(0, 1fr) 72px 76px minmax(0, .8fr) auto; }
459
+ /* The Permission Sets list: each set's counts (Admin::SetSummaries) and the
460
+ overview a row opens in place (Admin::SetOverview, data-pf-expand). A bar is
461
+ drawn in tenths: the admin's CSP allows no inline style. */
462
+ .pf-set-count { font-size: 18px; font-weight: 600; line-height: 1.1; }
463
+ .pf-bar { display: block; height: 4px; border-radius: 2px; background: var(--pf-surface-2); overflow: hidden; }
464
+ .pf-bar__fill { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--pf-accent); }
465
+ .pf-access-count .pf-bar__fill { background: var(--pf-grant); }
466
+ .pf-bar__fill.pf-bar__fill--muting { background: var(--pf-block); }
467
+ .pf-bar__fill--1 { width: 10%; } .pf-bar__fill--2 { width: 20%; } .pf-bar__fill--3 { width: 30%; }
468
+ .pf-bar__fill--4 { width: 40%; } .pf-bar__fill--5 { width: 50%; } .pf-bar__fill--6 { width: 60%; }
469
+ .pf-bar__fill--7 { width: 70%; } .pf-bar__fill--8 { width: 80%; } .pf-bar__fill--9 { width: 90%; }
470
+ .pf-bar__fill--10 { width: 100%; }
471
+ .pf-access-profile { font-size: 13px; font-weight: 600; }
472
+ .pf-access-profile b { font-weight: 400; }
473
+ .pf-access-profile--full b, .pf-access-profile--read_only b, .pf-access-profile--mixed b { color: var(--pf-grant); }
474
+ .pf-access-profile--takes_away b { color: var(--pf-block); }
475
+ .pf-access-counts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
476
+ .pf-access-count { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--pf-text-3); white-space: nowrap; }
477
+ .pf-access-count b { color: var(--pf-text-2); }
478
+ .pf-narrow-link { display: flex; flex-direction: column; }
479
+ .pf-overview-links { display: flex; flex-wrap: wrap; gap: 2px 14px; }
480
+ .pf-table__detail { border-top: 1px dashed var(--pf-border); padding: 12px 18px 16px; min-width: 0; }
481
+ .pf-overview { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
482
+ .pf-overview__families { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
483
+ .pf-family { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border: 1px solid var(--pf-border); border-radius: var(--pf-radius-sm); background: var(--pf-surface-2); color: var(--pf-text) !important; text-decoration: none !important; font-size: 12px; }
484
+ .pf-family:hover, .pf-family:focus-visible { border-color: var(--pf-border-strong); }
485
+ .pf-family__name { font-family: var(--pf-mono); font-size: 12px; }
486
+ .pf-family__count { color: var(--pf-text-3); font-variant-numeric: tabular-nums; }
487
+ .pf-marks { display: inline-flex; flex-wrap: wrap; gap: 4px; }
488
+ .pf-mark { font-size: 10.5px; font-weight: 600; line-height: 16px; padding: 0 5px; border-radius: var(--pf-radius-xs); white-space: nowrap; }
489
+ .pf-mark--view-all { background: var(--pf-grant-soft); color: var(--pf-grant); }
490
+ .pf-mark--rules { background: var(--pf-warn-soft); color: var(--pf-warn); }
491
+ .pf-mark--ignored { border: 1px dashed var(--pf-warn-border); color: var(--pf-text-3); text-decoration: line-through; }
492
+ .pf-mark--masked { background: var(--pf-mask-soft); color: var(--pf-mask); }
493
+ .pf-mark--hidden { background: var(--pf-block-soft); color: var(--pf-block); }
494
+ .pf-overview__legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; }
495
+ .pf-overview__cols { columns: 4 240px; column-gap: 24px; }
496
+ .pf-overview__family { break-inside: avoid; margin-bottom: 14px; min-width: 0; }
497
+ .pf-overview__family .pf-h3 { margin: 0 0 4px; font-size: 12px; }
498
+ .pf-overview__list { margin: 0; padding: 0; list-style: none; }
499
+ .pf-overview__res { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 1px 0; font-size: 12px; }
500
+ .pf-overview__name { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; min-width: 0; overflow-wrap: anywhere; }
501
+ .pf-overview__name code { font-family: var(--pf-mono); font-size: 11.5px; color: var(--pf-text-2); }
502
+ .pf-overview__res--narrowed .pf-overview__name code { color: var(--pf-text); }
503
+ .pf-flags { display: inline-flex; gap: 2px; flex: none; }
504
+ .pf-flag { min-width: 15px; padding: 0 2px; text-align: center; border-radius: 3px; font-family: var(--pf-mono); font-size: 10.5px; line-height: 15px; }
505
+ .pf-flag:nth-child(5) { margin-left: 5px; }
506
+ .pf-flag--on { background: var(--pf-grant-soft); color: var(--pf-grant); font-weight: 600; }
507
+ .pf-flag--on.pf-flag--muting { background: var(--pf-block-soft); color: var(--pf-block); }
508
+ .pf-flag--off { color: var(--pf-text-3); }
458
509
  .pf-table--assignments { min-width: 640px; }
459
510
  .pf-table--assignments .pf-table__head, .pf-table--assignments .pf-table__row { grid-template-columns: auto minmax(0, 1.5fr) minmax(0, 1.2fr) minmax(0, 1fr) auto; }
460
511
  .pf-table--audit { min-width: 640px; }
@@ -465,8 +516,9 @@
465
516
  `auto` or `fr` (never a fixed width): a subgrid adds its padding to them. */
466
517
  @supports (grid-template-columns: subgrid) {
467
518
  .pf-table--sets, .pf-table--assignments { display: grid; column-gap: 12px; }
468
- .pf-table--sets { grid-template-columns: minmax(0, 2fr) 56px 76px minmax(0, .8fr) auto; }
519
+ .pf-table--sets { grid-template-columns: minmax(0, 2fr) 96px 172px minmax(0, 1fr) 72px 76px minmax(0, .8fr) auto; }
469
520
  .pf-table--assignments { grid-template-columns: auto minmax(0, 1.5fr) minmax(0, 1.2fr) minmax(0, 1fr) fit-content(40%); }
521
+ .pf-table--sets > .pf-table__detail { grid-column: 1 / -1; }
470
522
  .pf-table--sets > .pf-table__head, .pf-table--sets > .pf-table__row,
471
523
  .pf-table--assignments > .pf-table__head, .pf-table--assignments > .pf-table__row { grid-column: 1 / -1; grid-template-columns: subgrid; }
472
524
  }
@@ -846,3 +898,4 @@
846
898
  people <select> with long labels shrinks with it instead of pushing the form past the page. */
847
899
  .pf-reason-form { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; min-width: 0; }
848
900
  .pf-reason-form .pf-reason--compact[open] { flex-basis: 100%; }
901
+ .pf-root a[data-pf-expand][aria-busy="true"]::after { content: " …"; }
@@ -496,6 +496,78 @@
496
496
  });
497
497
  });
498
498
 
499
+ /* ------------------------------------------- open a row in place */
500
+ // A link marked data-pf-expand="<slot id>" (the Permission Sets list) opens
501
+ // its page, the no-JS path, in place: the page's fragment fills a slot
502
+ // inserted after the row named by data-pf-expand-row, and a link that
503
+ // carries data-pf-expand-hide closes the slot it opened. Only the latest
504
+ // request fills a slot; an answer that is no fragment (a redirect, a whole
505
+ // document) or an error follows the link instead. On the page itself the
506
+ // row is not there and the link is a plain link. Each slot has one request
507
+ // at a time: a newer click on the same row, or closing it, aborts the one
508
+ // before; an answer for a row the live search has replaced is dropped.
509
+ const expandRequests = new Map();
510
+ function syncExpandToggles(rowId, slot) {
511
+ $$('a[data-pf-expand-hide]').forEach(function (a) {
512
+ if (a.getAttribute('data-pf-expand-row') !== rowId) return;
513
+ if (!a.hasAttribute('data-pf-expand-show')) a.setAttribute('data-pf-expand-show', a.textContent);
514
+ const open = !!slot && slot.getAttribute('data-pf-expanded') === a.getAttribute('href');
515
+ a.setAttribute('aria-expanded', open ? 'true' : 'false');
516
+ if (open) a.setAttribute('aria-controls', slot.id); else a.removeAttribute('aria-controls');
517
+ a.textContent = open ? a.getAttribute('data-pf-expand-hide') : a.getAttribute('data-pf-expand-show');
518
+ });
519
+ }
520
+
521
+ function expandSlot(id, row) {
522
+ let slot = document.getElementById(id);
523
+ if (slot) return slot;
524
+ slot = document.createElement('div');
525
+ slot.id = id;
526
+ slot.className = 'pf-table__detail';
527
+ slot.setAttribute('role', 'row');
528
+ const cell = document.createElement('div');
529
+ cell.setAttribute('role', 'cell');
530
+ slot.appendChild(cell);
531
+ row.after(slot);
532
+ return slot;
533
+ }
534
+
535
+ on('click', 'a[data-pf-expand]', function (e, a) {
536
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.button === 1) return;
537
+ const row = document.getElementById(a.getAttribute('data-pf-expand-row'));
538
+ if (!row) return;
539
+ e.preventDefault();
540
+ const id = a.getAttribute('data-pf-expand');
541
+ const href = a.getAttribute('href');
542
+ const current = document.getElementById(id);
543
+ const pending = expandRequests.get(id);
544
+ if (pending) pending.abort();
545
+ if (current && a.hasAttribute('data-pf-expand-hide') && current.getAttribute('data-pf-expanded') === href) {
546
+ current.replaceWith();
547
+ syncExpandToggles(row.id, null);
548
+ return;
549
+ }
550
+ const request = new AbortController();
551
+ expandRequests.set(id, request);
552
+ a.setAttribute('aria-busy', 'true');
553
+ fetch(href, { headers: { [FRAGMENT_HEADER]: '1' }, credentials: 'same-origin', signal: request.signal })
554
+ .then(function (res) { return res.ok && !res.redirected ? res.text() : Promise.reject(res.status); })
555
+ .then(function (html) {
556
+ if (request !== expandRequests.get(id) || !row.isConnected) return;
557
+ if (/<html[\s>]/i.test(html)) { window.location.href = href; return; }
558
+ const slot = expandSlot(id, row);
559
+ setContent(slot.firstElementChild, html);
560
+ slot.setAttribute('data-pf-expanded', href);
561
+ enhance(slot);
562
+ syncExpandToggles(row.id, slot);
563
+ })
564
+ .catch(function (err) { if (!(err && err.name === 'AbortError')) window.location.href = href; })
565
+ .then(function () {
566
+ a.removeAttribute('aria-busy');
567
+ if (expandRequests.get(id) === request) expandRequests.delete(id);
568
+ });
569
+ });
570
+
499
571
  /* ------------------------------------------------------- enhance */
500
572
  function enhance(ctx) {
501
573
  armToasts(ctx);
@@ -509,6 +581,7 @@
509
581
  if (btn) btn.disabled = input.value.trim() !== input.getAttribute('data-pf-confirm-match');
510
582
  });
511
583
  syncShowWhen(ctx);
584
+ $$('a[data-pf-expand-hide]:not([aria-expanded])', ctx).forEach(function (a) { a.setAttribute('aria-expanded', 'false'); });
512
585
  const focus = $('[data-pf-focus="true"]', ctx);
513
586
  if (focus && ctx === document) focus.scrollIntoView({ block: 'center' });
514
587
  }
@@ -14,6 +14,7 @@ module PermissionForge
14
14
  include PermissionForge::AuditRecordsHelper
15
15
  include PermissionForge::AuditAttributionHelper
16
16
  include PermissionForge::SettingsHelper
17
+ include PermissionForge::SetSummariesHelper
17
18
 
18
19
  # Sidebar link; the current section gets aria-current="page".
19
20
  def pf_nav_link(label, path, badge: nil, badge_label: nil, exact: false)
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PermissionForge
4
+ # The Permission Sets list's summary of each set and the overview it opens
5
+ # in place (Admin::SetSummaries, Admin::SetOverview): the access profile,
6
+ # the flag counts, the marks of a Resource or family (rules, masked and
7
+ # hidden fields) and the links that open the overview.
8
+ #
9
+ # @api private
10
+ module SetSummariesHelper
11
+ CRUD_FLAGS = %i[read_access create_access edit_access delete_access].freeze
12
+ ALL_FLAGS = (CRUD_FLAGS + %i[view_all modify_all]).freeze
13
+ # A bar is drawn in tenths (no inline style under the admin's CSP).
14
+ BAR_STEPS = 10
15
+
16
+ # "◐ Some changes": the set's access profile (StateLabel :access_profile).
17
+ def pf_access_profile(summary)
18
+ label = pf_state(:access_profile, summary.profile)
19
+ content_tag(:span, pf_state_parts(label, glyph_tag: :b, separator: ' '),
20
+ class: "pf-access-profile pf-access-profile--#{summary.profile}")
21
+ end
22
+
23
+ # Read · Create · Edit · Delete: each flag's count over the set's Resources, with a bar.
24
+ def pf_access_counts(summary)
25
+ flags = summary.flags
26
+ cells = CRUD_FLAGS.map { |flag| pf_access_count(flag, flags[flag], summary) }
27
+ content_tag(:span, safe_join(cells), class: 'pf-access-counts')
28
+ end
29
+
30
+ def pf_access_count(flag, count, summary)
31
+ total = summary.resources
32
+ words = t('permission_forge.permission_sets.summary.flag_count',
33
+ flag: t("permission_forge.ui.flags_short.#{flag}"), count: count, total: total)
34
+ content_tag(:span, class: 'pf-access-count') do
35
+ safe_join([content_tag(:span, safe_join([pf_flag_initial(flag), ' ', content_tag(:b, count)]), 'aria-hidden': true),
36
+ content_tag(:span, words, class: 'pf-sr-only'), pf_bar(count, total, muting: summary.muting)])
37
+ end
38
+ end
39
+
40
+ # A bar of `count` out of `total`, in tenths; a count above zero shows at least one.
41
+ def pf_bar(count, total, muting: false)
42
+ step = total.positive? ? ((count.to_f / total) * BAR_STEPS).round.clamp(0, BAR_STEPS) : 0
43
+ step = 1 if step.zero? && count.positive?
44
+ fill = content_tag(:span, nil, class: ['pf-bar__fill', "pf-bar__fill--#{step}", ('pf-bar__fill--muting' if muting)].compact)
45
+ content_tag(:span, fill, class: 'pf-bar', 'aria-hidden': true)
46
+ end
47
+
48
+ # The letter a flag is drawn with in a flag strip ("R" for Read).
49
+ def pf_flag_initial(flag)
50
+ t("permission_forge.permission_sets.summary.initials.#{flag}")
51
+ end
52
+
53
+ # R C E D │ V M: the six flags of one Resource, a lit letter for each one
54
+ # it grants (or, on a muting set, takes away); the words for assistive
55
+ # technology.
56
+ def pf_flag_strip(flags, muting:)
57
+ on = ALL_FLAGS.select { |flag| flags[flag] }
58
+ letters = ALL_FLAGS.map { |flag| pf_flag_letter(flag, on.include?(flag), muting) }
59
+ words = on.map { |flag| t("permission_forge.ui.flags_short.#{flag}") }
60
+ sentence = words.empty? ? t('permission_forge.permission_sets.summary.no_flags') : words.join(', ')
61
+ safe_join([content_tag(:span, safe_join(letters), class: 'pf-flags', 'aria-hidden': true),
62
+ content_tag(:span, sentence, class: 'pf-sr-only')])
63
+ end
64
+
65
+ def pf_flag_letter(flag, lit, muting)
66
+ return content_tag(:span, '·', class: 'pf-flag pf-flag--off') unless lit
67
+
68
+ content_tag(:span, pf_flag_initial(flag), class: ['pf-flag', 'pf-flag--on', ('pf-flag--muting' if muting)].compact)
69
+ end
70
+
71
+ # The marks of a Resource or a family (`#marks`: { kind => count }):
72
+ # View All, row rules, rules View All bypasses, masked (or force-masked)
73
+ # and hidden fields. Nothing when it carries none.
74
+ def pf_overview_marks(item)
75
+ marks = item.marks.select { |_kind, count| count.positive? }.map { |kind, count| pf_mark(kind, count) }
76
+ content_tag(:span, safe_join(marks, ' '), class: 'pf-marks') if marks.any?
77
+ end
78
+
79
+ # A mark: its glyph and count, and its words (shown on hover, read by assistive technology).
80
+ def pf_mark(kind, count)
81
+ text = t("permission_forge.permission_sets.summary.marks.#{kind}", count: count)
82
+ words = t("permission_forge.permission_sets.summary.mark_titles.#{kind}", count: count)
83
+ content_tag(:span, safe_join([content_tag(:span, text, 'aria-hidden': true), content_tag(:span, words, class: 'pf-sr-only')]),
84
+ class: "pf-mark pf-mark--#{kind.tr('_', '-')}", title: words)
85
+ end
86
+
87
+ # A link that opens a set's overview (`route`: `view:`, `only:`): a page of its
88
+ # own, which the list's script loads in place under the set's row
89
+ # (data-pf-expand); `hide:` is the link's text while what it opened is
90
+ # shown; `described: true` names the set the link belongs to (the set's
91
+ # name on the list) for assistive technology. Other options go to link_to.
92
+ def pf_overview_link(set, text, route, **options)
93
+ hide = options.delete(:hide)
94
+ described = options.delete(:described)
95
+ link_to(text, pf_overview_path(set, route), data: pf_overview_data(set, hide),
96
+ 'aria-describedby': (pf_set_name_id(set) if described), **options)
97
+ end
98
+
99
+ def pf_overview_path(set, route)
100
+ permission_forge.overview_permission_set_path(set, view: route.fetch(:view), only: route[:only].presence)
101
+ end
102
+
103
+ # The slot the overview fills, the row it goes under, and the link's text while it is open.
104
+ def pf_overview_data(set, hide)
105
+ { pf_expand: "pf-set-overview-#{set.id}", pf_expand_row: "pf-set-#{set.id}", pf_expand_hide: hide }.compact
106
+ end
107
+
108
+ # The id of the set's name on the list (what its overview links are described by).
109
+ def pf_set_name_id(set) = "pf-set-name-#{set.id}"
110
+
111
+ # "⛉ 2 row rules" over "on 2 Resources": a count in the Narrowed by column.
112
+ def pf_narrow_text(text, resources)
113
+ safe_join([content_tag(:span, text),
114
+ content_tag(:span, t('permission_forge.permission_sets.summary.on_resources', count: resources),
115
+ class: 'pf-fs-12 pf-text-3')])
116
+ end
117
+
118
+ # A Resource's label inside its family, without the family's namespace
119
+ # (`Line` under `Invoices`); the whole label as its title.
120
+ def pf_overview_resource_name(entry, family)
121
+ label = pf_resource_label(entry.name)
122
+ prefix = "#{family.name}::"
123
+ short = family.name && label.start_with?(prefix) ? label.delete_prefix(prefix) : label
124
+ content_tag(:code, short, title: (label unless short == label))
125
+ end
126
+
127
+ # The Resource's name, linked to its page; a name stored past the
128
+ # validation (blank, or not a constant path: no route carries it) is
129
+ # shown, never linked (a 500 otherwise).
130
+ def pf_overview_resource_link(set, entry, family)
131
+ name = pf_overview_resource_name(entry, family)
132
+ return name unless PermissionForge::RESOURCE_NAME_FORMAT.match?(entry.name)
133
+
134
+ link_to(name, permission_forge.permission_set_resource_path(set, entry.name))
135
+ end
136
+
137
+ # A family's name: its namespace, or "Other models".
138
+ def pf_family_name(family)
139
+ return t('permission_forge.permission_sets.overview.no_family') if family.name.nil?
140
+
141
+ content_tag(:code, family.name, class: 'pf-family__name')
142
+ end
143
+ end
144
+ end
@@ -179,9 +179,10 @@ module PermissionForge
179
179
 
180
180
  # A section heading inside a drawer or confirmation page. The page's own title is the h1 when
181
181
  # the page stands alone and an h2 inside the dialog (the page behind has the h1), so a section
182
- # is one level below that.
183
- def pf_section_heading(text, id: nil)
184
- content_tag(pf_fragment? ? :h3 : :h2, text, class: 'pf-h3', id: id)
182
+ # is one level below that. A fragment loaded into the page itself (`in_page: true`: the
183
+ # Permission Sets list opens a set's Resources under its row) is under the page's h1: an h2.
184
+ def pf_section_heading(text, id: nil, in_page: false)
185
+ content_tag(pf_fragment? && !in_page ? :h3 : :h2, text, class: 'pf-h3', id: id)
185
186
  end
186
187
 
187
188
  # A frame that scrolls sideways when its content (a wide grid) is wider than the page: a
@@ -0,0 +1,7 @@
1
+ <% content_for :pf_title, t('permission_forge.audit_events.index.title') %>
2
+ <div class="pf-page-header">
3
+ <div class="pf-page-header__text">
4
+ <h1 class="pf-h1"><%= t('permission_forge.audit_events.index.title') %></h1>
5
+ </div>
6
+ </div>
7
+ <%= render 'permission_forge/shared/audit_off_note', problem: @problem %>
@@ -13,6 +13,7 @@
13
13
  </div>
14
14
  <% end %>
15
15
 
16
+ <% if @timeline %>
16
17
  <%= render 'permission_forge/shared/audit_timeline',
17
18
  title: t('.timeline', name: first_name), description: t('.timeline_desc', name: first_name),
18
19
  page: @timeline, lookups: @timeline_lookups,
@@ -20,6 +21,9 @@
20
21
  views_path: (permission_forge.person_path(@person, tab: 'audit', views: 1) unless @timeline_log.include_views?),
21
22
  links: [[t('.events_about', name: first_name), pf_audit_log_path(subject_user_id: @person.id)],
22
23
  [t('.events_by', name: first_name), pf_audit_log_path(actor_type: 'user', actor_id: @person.id)]] %>
24
+ <% else %>
25
+ <%= render 'permission_forge/shared/audit_unavailable' %>
26
+ <% end %>
23
27
 
24
28
  <section class="pf-card" aria-labelledby="pf-received">
25
29
  <div class="pf-card__header"><h2 class="pf-h2" id="pf-received"><%= t('.received') %></h2></div>
@@ -2,12 +2,16 @@
2
2
  <%= render 'permission_forge/shared/audit_refused_note' %>
3
3
  <% else %>
4
4
  <div class="pf-stack pf-stack--loose">
5
+ <% if @timeline %>
5
6
  <%= render 'permission_forge/shared/audit_timeline',
6
7
  title: t('.timeline'), description: t('.timeline_desc'),
7
8
  page: @timeline, lookups: @timeline_lookups,
8
9
  path: ->(number) { permission_forge.permission_set_path(set, tab: 'audit', who: @who, type: @type, days: @days, sort: @sort, views: @views, page: number) },
9
10
  views_path: (permission_forge.permission_set_path(set, tab: 'audit', who: @who, type: @type, days: @days, sort: @sort, views: 1) unless @timeline_log.include_views?),
10
11
  links: [[t('.open_log'), pf_audit_log_path(permission_set: set.id)]] %>
12
+ <% else %>
13
+ <%= render 'permission_forge/shared/audit_unavailable' %>
14
+ <% end %>
11
15
 
12
16
  <h2 class="pf-h2"><%= t('.records') %></h2>
13
17
  <% if PermissionForge.configuration.audit_trail_enabled %>