Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ written while it was being built. See [RELEASING.md](RELEASING.md).

### Added

- Platform admins can filter the user list by platform role — Admin, Hackathon
Organizer or none — with a count beside each, and combine it with the search.
- Teams can now give a submission a description, with formatting, and a link to
a folder of attachments, alongside the link to their repository. A new version
starts out filled in from the previous one, so fixing a single link means
Expand Down
63 changes: 63 additions & 0 deletions components/frontend/src/lib/utils/globalRole.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { describe, expect, it } from "vitest"
import {
ASSIGNABLE_GLOBAL_ROLES,
GLOBAL_ROLE_FILTERS,
displayableGlobalRoles,
globalRoleBadgeVariant,
globalRoleDescription,
globalRoleFilterLabel,
globalRoleLabel,
matchesGlobalRoleFilter,
} from "./globalRole"

// GlobalRole numeric values.
Expand Down Expand Up @@ -81,3 +84,63 @@ describe("globalRoleDescription", () => {
expect(globalRoleDescription(99)).toBeUndefined()
})
})

describe("GLOBAL_ROLE_FILTERS", () => {
// Adding a role to ASSIGNABLE_GLOBAL_ROLES has to give it a filter, or its
// holders could only be found under "All".
it("offers a slice for every assignable role", () => {
for (const role of ASSIGNABLE_GLOBAL_ROLES) {
expect(GLOBAL_ROLE_FILTERS).toContain(role)
}
})

it("opens on everyone and closes on no role", () => {
expect(GLOBAL_ROLE_FILTERS[0]).toBe("all")
expect(GLOBAL_ROLE_FILTERS.at(-1)).toBe("none")
})

it("labels every slice", () => {
for (const filter of GLOBAL_ROLE_FILTERS) {
expect(globalRoleFilterLabel(filter)).not.toBe("Unknown")
}
})
})

describe("matchesGlobalRoleFilter", () => {
it("lets everyone through all", () => {
expect(matchesGlobalRoleFilter([], "all")).toBe(true)
expect(matchesGlobalRoleFilter([ADMIN], "all")).toBe(true)
expect(matchesGlobalRoleFilter([99], "all")).toBe(true)
})

it("matches the holders of a role", () => {
expect(matchesGlobalRoleFilter([ADMIN], ADMIN)).toBe(true)
expect(matchesGlobalRoleFilter([HACKATHON_ORGANIZER], ADMIN)).toBe(false)
expect(matchesGlobalRoleFilter([], ADMIN)).toBe(false)
})

// The roles are exclusive in the UI but not in the API, so a user granted
// both out of band has to turn up under each — the table shows both badges.
it("matches a user holding both roles under each", () => {
expect(matchesGlobalRoleFilter([ADMIN, HACKATHON_ORGANIZER], ADMIN)).toBe(
true,
)
expect(
matchesGlobalRoleFilter(
[ADMIN, HACKATHON_ORGANIZER],
HACKATHON_ORGANIZER,
),
).toBe(true)
})

it("matches no role only for an empty role list", () => {
expect(matchesGlobalRoleFilter([], "none")).toBe(true)
expect(matchesGlobalRoleFilter([ADMIN], "none")).toBe(false)
})

// Their row shows an "Unknown" badge rather than the grant picker, so they
// are not what "No role" promises.
it("keeps a user holding only an unnamed role out of no role", () => {
expect(matchesGlobalRoleFilter([99], "none")).toBe(false)
})
})
41 changes: 41 additions & 0 deletions components/frontend/src/lib/utils/globalRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,44 @@ export function globalRoleDescription(r: number): string | undefined {
export function displayableGlobalRoles(roles: number[]): number[] {
return ASSIGNABLE_GLOBAL_ROLES.filter((r) => roles.includes(r))
}

/**
* One slice of the admin user table: everyone, the holders of one role, or the
* users holding no role at all.
*
* Single-valued because the roles are mutually exclusive (see the users page),
* so a multi-select would only ever add slices together.
*/
export type GlobalRoleFilter = "all" | "none" | number

/** Every slice, in the order the filter shows them. */
export const GLOBAL_ROLE_FILTERS: GlobalRoleFilter[] = [
"all",
...ASSIGNABLE_GLOBAL_ROLES,
"none",
]

export function globalRoleFilterLabel(filter: GlobalRoleFilter): string {
if (filter === "all") return "All"
// "platform", because nearly everyone holds a role somewhere: owner or member
// of a hackathon. Those are per-hackathon and not what this filter reads.
if (filter === "none") return "No platform role"
return globalRoleLabel(filter) ?? "Unknown"
}

/**
* Whether a user holding `roles` belongs in the slice.
*
* "none" means an empty role list — the same test the users page uses to decide
* a row gets the grant picker, so the slice is exactly the rows showing one. A
* user holding only a role this build cannot name is therefore not in it: their
* row shows an "Unknown" badge, not a picker, and they appear under "all" only.
*/
export function matchesGlobalRoleFilter(
roles: number[],
filter: GlobalRoleFilter,
): boolean {
if (filter === "all") return true
if (filter === "none") return roles.length === 0
return roles.includes(filter)
}
97 changes: 80 additions & 17 deletions components/frontend/src/routes/(app)/manage/users/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import { SvelteSet } from 'svelte/reactivity';
import {
ASSIGNABLE_GLOBAL_ROLES,
GLOBAL_ROLE_FILTERS,
globalRoleBadgeVariant,
globalRoleDescription,
globalRoleFilterLabel,
globalRoleLabel,
matchesGlobalRoleFilter,
type GlobalRoleFilter,
} from '$lib/utils/globalRole';
import type { ActionData, PageData } from './$types';

Expand All @@ -17,6 +21,11 @@

let search = $state('');

// Page state rather than a query parameter, like the search beside it: it
// survives a grant or revoke because `enhance` re-runs the load without
// remounting the page.
let roleFilter = $state<GlobalRoleFilter>('all');

// Grant and revoke both take a row's whole control group out of service
// while either is in flight, so one submit handler serves both.
const pendingIds = new SvelteSet<string>();
Expand Down Expand Up @@ -57,7 +66,7 @@

// Matches every column the table actually shows, so a row the user can read
// on screen is never filtered out by a term visible in it.
const filtered = $derived(
const searched = $derived(
data.users.filter((u) => {
const q = search.trim().toLowerCase();
if (q === '') return true;
Expand All @@ -68,15 +77,46 @@
})
);

const filtered = $derived(searched.filter((u) => matchesGlobalRoleFilter(u.roles, roleFilter)));

// Counted within the search, so each chip says how many rows picking it
// would show — a count over all users would promise rows the search then
// hides.
const roleCounts = $derived(
new Map(
GLOBAL_ROLE_FILTERS.map((f) => [
f,
searched.filter((u) => matchesGlobalRoleFilter(u.roles, f)).length,
])
)
);

const searching = $derived(search.trim() !== '');
const narrowedBy = $derived(
searching && roleFilter !== 'all' ? 'filters' : searching ? 'search' : 'filter'
);

// Counts the rows on screen, not the rows loaded: a search that narrows 42
// users to 3 while the header still reads "42 users" is simply wrong. The
// total stays alongside it so the filter's effect is visible.
const countLabel = $derived(
filtered.length === data.users.length
? `${data.users.length} ${data.users.length === 1 ? 'user' : 'users'} registered on the platform`
: `${filtered.length} of ${data.users.length} users match your search`
: `${filtered.length} of ${data.users.length} users match your ${narrowedBy}`
);

// Names whatever is narrowing the list, so an empty table with only a role
// picked doesn't claim to have searched for “”.
const emptyLabel = $derived.by(() => {
const who =
roleFilter === 'all'
? 'users'
: roleFilter === 'none'
? 'users without a platform role'
: `${globalRoleFilterLabel(roleFilter)} users`;
return searching ? `No ${who} match “${search.trim()}”.` : `No ${who}.`;
});

// Keycloak may leave display_name empty, hence the username fallback; '?'
// covers both being blank, so the avatar is never an empty circle that
// reads as a rendering fault.
Expand Down Expand Up @@ -296,23 +336,27 @@
building. Built from the same descriptions the picker shows, so the page
cannot end up explaining a role one way here and another way there.
-->
<ul class="m-0 flex list-none flex-col gap-1 p-0">
{#each ASSIGNABLE_GLOBAL_ROLES as role (role)}
<li class="flex flex-wrap items-center gap-2">
<span class="badge {globalRoleBadgeVariant(role) ?? 'badge-neutral'}">
{globalRoleLabel(role)}
</span>
<span class="font-sans text-xs text-ink-3">
{globalRoleDescription(role) ?? 'no description'}
</span>
</li>
{/each}
</ul>
<div class="flex flex-col gap-2">
<h2 class="meta m-0">Platform roles</h2>
<ul class="m-0 flex list-none flex-col gap-1 p-0">
{#each ASSIGNABLE_GLOBAL_ROLES as role (role)}
<li class="flex flex-wrap items-center gap-2">
<span class="badge {globalRoleBadgeVariant(role) ?? 'badge-neutral'}">
{globalRoleLabel(role)}
</span>
<span class="font-sans text-xs text-ink-3">
{globalRoleDescription(role) ?? 'no description'}
</span>
</li>
{/each}
</ul>
</div>
<!-- Says why the picker is missing from most rows; without it the absence
reads as a bug or as a permission the viewer lacks. -->
<p class="m-0 text-xs text-ink-3">
A user holds one of these at a time. To change someone's role, revoke the one
they have and then grant the other.
they have and then grant the other. Roles inside a hackathon — owner or
member — are separate and not shown here.
</p>

{#if form?.message}
Expand All @@ -324,10 +368,29 @@
</p>
{/if}

<!-- Chips, not buttons: this picks which rows are showing, and a solid
accent would read as an action. Rendered even when the slice is
empty, so the way back out stays in view. -->
{#if data.users.length > 0}
<div class="flex flex-wrap gap-1" role="group" aria-label="Filter by role">
{#each GLOBAL_ROLE_FILTERS as filter (filter)}
<button
type="button"
onclick={() => (roleFilter = filter)}
aria-pressed={roleFilter === filter}
class="chip {roleFilter === filter ? 'chip-active' : ''}"
>
{globalRoleFilterLabel(filter)}
<span class="tnum">{roleCounts.get(filter) ?? 0}</span>
</button>
{/each}
</div>
{/if}

{#if data.users.length === 0}
<p class="m-0 py-6 text-center text-sm text-ink-3">No users found.</p>
{:else if filtered.length === 0}
<p class="m-0 py-6 text-center text-sm text-ink-3">No users match “{search}”.</p>
<p class="m-0 py-6 text-center text-sm text-ink-3">{emptyLabel}</p>
{:else}
<!--
Two presentations of one list. The table below buries Roles and Grant
Expand Down Expand Up @@ -411,7 +474,7 @@
never occupy a row at the same time. Split across two
columns every row showed one dash.
-->
<th class="px-3 py-2 font-semibold">Role</th>
<th class="px-3 py-2 font-semibold">Platform role</th>
</tr>
</thead>
<tbody>
Expand Down
78 changes: 78 additions & 0 deletions pr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# feat(frontend): filter the admin user list by platform role

As a platform admin, I want to see just the admins, just the hackathon
organizers, or just the people who hold no platform role yet. Then I can check
who holds the keys to the platform, and find whoever is still waiting for a
role, without scrolling the whole list.

**Before:** the Users page had only a free-text search. Typing "admin" happened
to match the Admin badge, but it also matched anyone with "admin" in their
username (such as `hackagon-admin`). There was no way to list the users who hold
no platform role.

**Now:** a row of buttons above the list narrows it to one group, and each
button shows how many users it covers. It works together with the search.

## What changed, page by page

### Users — `/manage/users` (platform admins only)

- **New role filter.** A row of chips sits between the role legend and the list:
`All · Admin · Hackathon Organizer · No platform role`. Each chip shows a
count. You pick one at a time, because a user holds at most one of these
roles.
- **"Platform role" wording.** The column is now "Platform role", the legend has
a "Platform roles" heading, and the note under it says that roles inside a
hackathon (owner, member) are separate and not shown here. Before, a user who
owns a hackathon could look as if they had no role at all.
- **Combines with the search.** A row is shown only if it matches both the
search and the selected chip. The chip counts are taken within the current
search, so each count is exactly how many rows that chip would show.
- **Count line under the title** now says what is narrowing the list: "3 of 12
users match your search", "… your filter" or "… your filters". With nothing
narrowing it, it still reads "12 users registered on the platform".
- **Empty state** names the filter instead of always quoting the search. For
example: "No Admin users.", "No users without a platform role." or "No
Hackathon Organizer users match “bob”."
- Both layouts get the filter: the desktop table and the phone card view.

No other page changes. The dashboard's own role badges use the same helper file,
but their behavior is unchanged.

## Details

- **"No platform role"** means the user holds no platform role at all. They may
still own or take part in hackathons. That is the same rule the page uses to
decide when to show the "Grant a role…" picker, so the filter lists exactly
the rows that have one.
- **A user holding both roles** (only possible if both were granted directly
through the API) shows up under each.
- **A user holding only a role this build doesn't recognize** shows up only
under "All". Their row already shows an "Unknown" badge.
- **The filter isn't saved in the page address**, the same as the search next to
it. It survives granting or revoking a role, but not a full page reload.
- **Revoking under a filter:** if you filter to a role and revoke it from
someone, their row leaves the filtered list. The "Revoked …" message at the
top of the page confirms the change.
- **Code:** the matching rules live in
`components/frontend/src/lib/utils/globalRole.ts`, next to the role labels
they build on, with unit tests in `globalRole.test.ts`.
- **`CHANGELOG.md`** has a new line under `[Unreleased]` → Added.

## Deliberately left out

- **Server-side filtering.** `UserService.List` takes no parameters and the page
already loads every user in one request, so filtering in the browser is enough
at this size. No backend or API change.
- **A shareable filtered link** (`?role=admin`). It would behave differently
from the search box beside it. It's easy to add later if links like that are
wanted.

## Verified

- Formatting (`treefmt`), lint (`eslint` + `tsc --noEmit`) and the frontend unit
tests pass, including the new tests for the matching rules.
- **Not checked in a browser.** No screenshots were taken of either the desktop
or the phone layout.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Loading