8000 fix(auth): have open pages follow a change of access by mwoods79 · Pull Request #735 · huddlz-hq/huddlz · GitHub
[go: up one dir, main page]

Skip to content

fix(auth): have open pages follow a change of access - #735

Merged
mwoods79 merged 17 commits into
mainfrom
t3/liveview-access-revocation
Dec 1, 2026
Merged

mwoods79 merged 17 commits into
mainfrom
t3/liveview-access-revocation

Conversation

@mwoods79
@mwoods79 mwoods79 commented Nov 30, 2026 •
Copy link
Copy Markdown
Contributor

Summary

A page authorizes when it mounts and then keeps the account it loaded for as long as it stays open. A new password, a changed account role, a changed group role or the end of a membership now reach the pages that person already has open: each page visits itself again, so its own mount decides afresh.

password changed | account role changed | group role changed | membership ended | group permanently deleted
  Huddlz.Accounts.AccessEvents.changed(user_id)      # notifiers: after the outermost commit, never on rollback; skips the process that made the change
    every open page of that person                   # :app hook in LiveUserAuth
      navigate to its own address, replacing history
        fresh mount: verify the session, reload the account, run the page's own rules
          still allowed  -> same page, current access
          not allowed    -> wherever a new visit lands (sign-in, agenda, the group page)

Admin pages also stop trusting the account they mounted with:

 on_mount(:admin_required)
   admin?(current_user) or leave for the agenda
+  before each event and each change of address
+    read the role from the database
+    leave for the agenda once it is gone

Of the two ways to keep the administrator decision off 8000 a stale account, this is the smaller: one hook on the three admin pages, rather than a database read inside every admin policy. The policies still read the role off the actor they are given; every caller other than an open page loads that actor per request.

Notes for review:

  • The page a person changes their own password or leaves a group from is skipped, so it behaves as before. Joining a group or being added to one still only refreshes in place.
  • Pages that patched themselves in place for the affected person (group page, Groups list, organizer picker, roster, Social tab) now reload for that person instead. Their in-place handlers stay, for everyone else looking at the group. Steps that change someone's access "in another session" follow the open page before asserting on it.
  • The organizer workspace already left on a lost role; that is unchanged.
  • A connecting page listens first and then reads the account as it stands: an ended session sends it to sign in; otherwise it mounts with the current role and suspension details and the page's own rules decide, so a change that commits while the page is mounting is not missed and an allowed page keeps its address and fragment.
  • The revisit helper in the browser acts only on the visit it announced, within a short window, and leaves focus and scroll alone once the person has moved on or gone back.
  • The affected person's pages are told to visit themselves before any in-place refresh, so a page keeps its exact address (a second page of results stays on its second page). The organizer workspace follows the same path: it visits itself and the fresh visit is turned away.
  • An ownership transfer no longer sends its own in-place refresh: the two role changes inside it announce themselves after the outermost commit, so both people keep their exact address and a rolled-back transfer sends nothing.
  • An owner whose membership row is missing is still told: a handover names them, and a permanent deletion counts the group's owner among those it tells. The sign-out page listens like every other page.
  • Suspension is listened for before the same mount-time check, and the admin pages re-read the role only once connected.
  • Archiving a group is not a trigger: memberships stay, and open pages already follow the archive itself.
  • The signal is per person, not per group: a role change in one group reloads that person's pages everywhere, and an unsaved form on an unrelated page is lost. Chosen over a per-page check that a new page could silently miss.

Evidence

  • Before: on main, the new tests fail — the open page never moves and keeps acting.

    open /admin/users as an administrator, then the role is removed elsewhere
      promote someone from the open page   -> promoted            (expected: refused)
    open /profile, then the password is changed on another device
      open page                            -> still signed in     (expected: asks to sign in)
    open the new huddl form as an organizer, then made a member
      open page                            -> still there, address book in hand   (expected: turned away)
    

    open_page_access_test.exs: 15 of 19 fail (the 4 that pass assert pages that must be left alone). The admin re-check tests in admin_live/users_test.exs fail. open_pages_follow_access.feature: 0 of 6. Browser open_page_access.feature: 0 of 2.

    After: all pass, including in Chromium, where a page the person may still see is refreshed in place with no extra history entry.

    account role removed   -> /admin, /admin/users, /admin/reports leave for the agenda
    account role granted   -> the open page offers the admin area, same address
    password changed/reset -> /agenda, /profile, /profile/api-keys, /groups ask to sign in; the page that changed it stays
    made a member          -> new huddl form, add-address dialog, edit huddl form, Locations turned away
    removed, left, ownership moved -> the person's open group pages reload
    group permanently deleted      -> its members' open pages reload
    change rolled back             -> nobody's page moves
    viewing as someone     -> the borrowed page follows that person's access
    

Merge Danger

Door: two-way

No schema or data change; reverting restores the old behaviour.

Blast Radius: sessions

  • Anyone whose role changes, whose membership ends or whose password changes sees their open pages reload once. Unsaved input on those pages is lost, including on pages unrelated to the group concerned.
  • After a password reset finished in a browser that was still signed in, that browser's other open tabs reload with the session they were rendered with and can land on sign-in or the home page rather than staying put.
  • Admin pages make one extra read of the administrator's own account per event.
  • Not covered here: an administrator who is viewing as someone keeps that view after losing the role, until they stop it. That is decided per request rather than by an open page, and is worth its own change.

An admin page checked the role once, as it mounted, and then handed every
later action the account it had loaded then. The admin policies read the
role off that account, so an administrator whose role was removed could
keep promoting, suspending, restoring and working the report queue from a
page that was already open.

The admin pages now read the role from the database before each event and
each change of address, and leave for the agenda once it is gone.

The policies still read the role off the actor they are given. Every other
caller loads that actor per request, so only an open page could hold a
stale one, and asking again here is a smaller change than a database read
in every admin policy.
A page authorizes when it mounts and then keeps the account it loaded for
as long as it stays open. Three changes left that copy behind:

- a new password revoked every session, but a page already open kept
  working until its socket happened to reconnect
- an account role change reached nobody's open pages
- a change of group role or the end of a membership refreshed the sidebar
  and left the page in place, so the huddl forms and the Locations page
  kept the group's address book after an organizer lost the role

Each of these now announces itself on a per-person topic once it has
committed, and every open page of that person visits itself again. The
fresh mount verifies the session, reloads the account and lets the page's
own rules decide: someone still allowed stays where they were, anyone
else lands where a new visit would.

The process that made the change is skipped, so the page a person changes
their password or leaves a group from behaves as it did. Joining a group
or being added to one still only refreshes in place; nothing is taken
away by those.

Pages that patched themselves in place for the affected person now reload
instead, so the steps that change someone's access from another session
follow the open page before asserting on it.
A member's role change or removal told their open pages as soon as the
action finished, so a change rolled back by a surrounding transaction
still reloaded them. Both now go out through the membership notifier,
which speaks only after the outermost commit. Permanently deleting a
group now reaches its members' open pages too: the memberships go with
the group.
The members told about a deleted group were read before the group's row
was locked, so someone whose membership committed in between lost it
without their open pages hearing. The row is locked first, as joining
and adding a member already do.
…vocation

* origin/main:
  fix(api): accept only sign-in tokens on the GraphQL socket (#730)
  fix(huddl): tie organizer-only huddl details to the current role (#726)
  fix(groups): keep a group's address book with its organizers (#725)
  fix(discover): noindex empty filtered public discovery responses (#734)
…hanges

A connecting page read its account from the session and only then began
listening for changes to that person's access, so a new password or a
changed role that committed in between went unheard and the page stayed
signed in on a session that had just ended. The page now listens first
and then checks that the session's token still verifies and the account's
role and standing are the ones it loaded; if not, it visits itself again.
…vocation

* origin/main:
  fix(api): authenticate API, GraphQL and MCP from the bearer alone (#729)
…ion at mount

A role change told the person's pages to refresh in place before telling
them to visit themselves again, so a page of results had already moved to
its first page when it read its own address. The visit-again signal now
goes first. A connecting page also starts listening for suspension before
it checks what it loaded, and the admin pages read the role again only
once connected.
…vocation

* origin/main:
  fix(auth): bind administrator viewing credentials to the browser session (#736)

# Conflicts:
#	lib/huddlz_web/live_user_auth.ex
A transfer refreshed both people's pages in place from its own hook,
before the role changes told those pages to visit themselves again, and
it did so even when a surrounding transaction rolled back. The hook is
gone: the two role changes already announce themselves once the outermost
transaction commits, each person's page first and the roster after.
…e, about access changes

An owner whose membership row is missing had no role change to announce a
handover and was not among the members told of a permanent deletion, so
their open pages kept showing the group. The handover now names them and
the deletion counts the group's owner. The sign-out page ran only the
first of its two mount steps, so it never listened; it now runs both in
one stage.
…vocation

* origin/main:
  fix(groups): authorize membership changes against their roster (#739)

# Conflicts:
#	lib/huddlz/communities/group_member/changes/notify_role_changed.ex
A change is announced by its notifiers once the transaction that holds it
commits. The overlap tests held a change open in a bare repo transaction,
which Ash cannot see commit, so a promotion that committed while a second
request waited was never announced to the member's pages or an open roster.
No caller under lib/ wraps a membership action that way; the helper now
uses Ash.transact/2 as they do, and the overlap test observes both
transitions in order: the promotion, then the change back.
…llow it

A permanent deletion published the group's own change before it told each
member's open pages to visit themselves again. The organizer Social page
follows the group, so it heard the first, found no group and moved on with
a note about changed organizer access. The members' signal now goes out
first: the page visits its own address and its mount gives the answer a
new visit gets. Deletion is the only group action that sends both.
…isits itself

An address reaches the server without its fragment, so the visit a page
makes when its person's access changes came back at the path and query
alone: someone who had followed the skip link lost "#main-content" from
the address, and focus fell from the main landmark to the document body.

The server still sends the page at once, whatever the browser does, and
now says a visit is coming just before. The browser notes where the
person is and, when the page is back at the same path and query, returns
the fragment to the same history entry and returns focus to the element
that had it, or else to the one the fragment names. A page that is turned
away is at another address and is left as it landed.
A page mounting with a changed role now continues in place with the
current role and suspension details; only an ended session redirects.
The revisit helper acts only on the visit it announced, and the roster
concurrency test waits on the database's own lock report.
The admin pages ran their admin gate before the hook that re-reads the
account once the page is listening, so an administrator demoted while a
page connected passed the gate and the page's own mount was refused
mid-join. The gate now runs second, and the mount test runs each admin
page's hooks in the order it declares them, followed by its mount.
@mwoods79
mwoods79 enabled auto-merge (squash) December 1, 2026 20:14
@mwoods79
mwoods79 merged commit 9a455a1 into main Dec 1, 2026
5 checks passed
@mwoods79
mwoods79 deleted the t3/liveview-access-revocation branch December 1, 2026 20:16
mwoods79 added a commit that referenced this pull request Dec 1, 2026
* origin/main:
  fix(auth): have open pages follow a change of access (#735)
mwoods79 added a commit that referenced this pull request Dec 1, 2026
* origin/main:
  fix(auth): have open pages follow a change of access (#735)
mwoods79 added a commit that referenced this pull request Dec 1, 2026
* origin/main:
  fix(auth): have open pages follow a change of access (#735)
  fix(groups): authorize membership changes against their roster (#739)
  fix(auth): bind administrator viewing credentials to the browser session (#736)
  fix(api): authenticate API, GraphQL and MCP from the bearer alone (#729)
  fix(api): accept only sign-in tokens on the GraphQL socket (#730)
  fix(huddl): tie organizer-only huddl details to the current role (#726)
  fix(groups): keep a group's address book with its organizers (#725)
  fix(discover): noindex empty filtered public discovery responses (#734)
mwoods79 added a commit that referenced this pull request Dec 1, 2026
…n-escaping

* origin/main:
  fix(groups): hold a group's slug to one rule whenever it is set (#742)
  fix(huddl): copy only huddlz the actor can organize (#723)
  fix(auth): have open pages follow a change of access (#735)
  fix(groups): authorize membership changes against their roster (#739)
  fix(auth): bind administrator viewing credentials to the browser session (#736)
mwoods79 added a commit that referenced this pull request Dec 1, 2026
…d-sorts

* origin/main:
  fix(auth): have open pages follow a change of access (#735)
  fix(groups): authorize membership changes against their roster (#739)
  fix(auth): bind administrator viewing credentials to the browser session (#736)
  fix(api): authenticate API, GraphQL and MCP from the bearer alone (#729)
  fix(api): accept only sign-in tokens on the GraphQL socket (#730)
  fix(huddl): tie organizer-only huddl details to the current role (#726)
  fix(groups): keep a group's address book with its organizers (#725)
  fix(discover): noindex empty filtered public discovery responses (#734)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

3441
0