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
8 changes: 8 additions & 0 deletions @app/db/__tests__/app_private/functions/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ it("can login with username+password", () =>
expect(snapshotSafe(session)).toMatchInlineSnapshot(`
{
"created_at": "[DATE]",
"kind": "web",
"last_active": "[DATE]",
"oauth_sid": null,
"user_id": "[ID]",
"uuid": "[UUID]",
}
Expand All @@ -53,7 +55,9 @@ it("can login with uSeRnAmE+password", () =>
expect(snapshotSafe(session)).toMatchInlineSnapshot(`
{
"created_at": "[DATE]",
"kind": "web",
"last_active": "[DATE]",
"oauth_sid": null,
"user_id": "[ID]",
"uuid": "[UUID]",
}
Expand All @@ -69,7 +73,9 @@ it("can login with email+password", () =>
expect(snapshotSafe(session)).toMatchInlineSnapshot(`
{
"created_at": "[DATE]",
"kind": "web",
"last_active": "[DATE]",
"oauth_sid": null,
"user_id": "[ID]",
"uuid": "[UUID]",
}
Expand All @@ -85,7 +91,9 @@ it("can login with EmAiL+password", () =>
expect(snapshotSafe(session)).toMatchInlineSnapshot(`
{
"created_at": "[DATE]",
"kind": "web",
"last_active": "[DATE]",
"oauth_sid": null,
"user_id": "[ID]",
"uuid": "[UUID]",
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
--! Previous: sha1:eafce160dd3a8ec859a47bc11b5c9117cc07fd8e
--! Hash: sha1:d86e34f82d1579f1b5f6f91bd24ccb41f19b5d53

--! split: 1-current.sql
/*
* Admins manage every organization, the same way `manage_admin` on
* `app_public.events` and `app_public.registrations` already lets them manage
* every event. Without this, `update_owner` is the only route to updating an
* organization, so changing one's settings requires an `is_owner` row in
* `organization_memberships` — which admins have no reason to hold, and which
* nobody holds for an organization they did not create.
*
* Membership keeps its own meaning: the way a non-admin is given rights over a
* single organization's events.
*/

drop policy if exists manage_admin on app_public.organizations;

create policy manage_admin on app_public.organizations
for all using (app_public.current_user_is_admin());

--! split: 2-delete-omitted-quotas-and-questions.sql
/*
* The admin UI sends an event's kept quotas with their ids and newly added
* quotas with a null id. Deletion of omitted quotas is detected with
Expand Down Expand Up @@ -109,3 +131,40 @@ begin
return v_ret;
end;
$$ language plpgsql volatile security invoker set search_path = pg_catalog, public, pg_temp;

--! split: 3-mcp-sessions.sql
/*
* MCP requests authenticate with a Keycloak access token instead of a session
* cookie. The server turns each verified token into an ordinary
* app_private.sessions row so that current_user_id(), RLS and the ownership
* triggers work unchanged, and so that the database keeps identifying users by
* an unguessable session id rather than by a raw user id (see the comment on
* current_user_id).
*
* One MCP session exists per Keycloak session (`oauth_sid`, the token's `sid`
* claim): token refreshes reuse it. The rows are derived state — the server
* recreates one on the next request if it is gone — so inactive MCP sessions
* can be deleted aggressively by the sessions__delete_inactive_mcp_sessions
* task.
*/

alter table app_private.sessions
add column if not exists kind text not null default 'web',
add column if not exists oauth_sid text;

alter table app_private.sessions drop constraint if exists sessions_kind_check;
alter table app_private.sessions
add constraint sessions_kind_check check (kind in ('web', 'mcp'));

alter table app_private.sessions drop constraint if exists sessions_oauth_sid_check;
alter table app_private.sessions
add constraint sessions_oauth_sid_check check ((kind = 'mcp') = (oauth_sid is not null));

drop index if exists app_private.sessions_mcp_oauth_sid_key;
create unique index sessions_mcp_oauth_sid_key
on app_private.sessions (oauth_sid) where kind = 'mcp';

comment on column app_private.sessions.kind is
E'How the session was established: web (session cookie) or mcp (Keycloak access token on /mcp).';
comment on column app_private.sessions.oauth_sid is
E'Keycloak session id (the access token sid claim) of an mcp session.';
17 changes: 1 addition & 16 deletions @app/db/migrations/current/1-current.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
/*
* Admins manage every organization, the same way `manage_admin` on
* `app_public.events` and `app_public.registrations` already lets them manage
* every event. Without this, `update_owner` is the only route to updating an
* organization, so changing one's settings requires an `is_owner` row in
* `organization_memberships` — which admins have no reason to hold, and which
* nobody holds for an organization they did not create.
*
* Membership keeps its own meaning: the way a non-admin is given rights over a
* single organization's events.
*/

drop policy if exists manage_admin on app_public.organizations;

create policy manage_admin on app_public.organizations
for all using (app_public.current_user_is_admin());
-- Enter migration here
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
fragment McpEventSummary on Event {
id
slug
name
location
eventStartTime
eventEndTime
registrationStartTime
registrationEndTime
signupOpen
signupUpcoming
ownerOrganization {
name
__typename
}
category {
name
__typename
}
__typename
}
query McpEvent($slug: String!) {
currentUser {
name
primaryEmail
__typename
}
eventBySlug(slug: $slug) {
...McpEventSummary
description
isDraft
openQuotaSize
quotas(orderBy: POSITION_ASC) {
nodes {
id
title
size
registrations {
totalCount
__typename
}
__typename
}
__typename
}
eventQuestions(orderBy: POSITION_ASC) {
nodes {
id
type
label
isRequired
data
__typename
}
__typename
}
__typename
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
fragment McpEventSummary on Event {
id
slug
name
location
eventStartTime
eventEndTime
registrationStartTime
registrationEndTime
signupOpen
signupUpcoming
ownerOrganization {
name
__typename
}
category {
name
__typename
}
__typename
}
query McpEvents {
signupOpenEvents: events(
filter: {signupOpen: {equalTo: true}, isDraft: {equalTo: false}}
orderBy: [IS_HIGHLIGHTED_DESC, REGISTRATION_END_TIME_ASC]
) {
nodes {
...McpEventSummary
__typename
}
__typename
}
signupUpcomingEvents: events(
filter: {signupUpcoming: {equalTo: true}, isDraft: {equalTo: false}}
orderBy: [IS_HIGHLIGHTED_DESC, REGISTRATION_START_TIME_ASC]
) {
nodes {
...McpEventSummary
__typename
}
__typename
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
query McpEventOptions {
organizations {
nodes {
id
name
__typename
}
__typename
}
eventCategories(orderBy: NAME_ASC) {
nodes {
id
name
ownerOrganization {
id
__typename
}
__typename
}
__typename
}
}
5 changes: 4 additions & 1 deletion @app/graphql/client.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@
"SettingsPassword": "4ccd52e00c526690ac5b44ca911534e96f936acd4ff02a2785d9932bbe11ff6c",
"UnlinkUserAuthentication": "efef5d154b91120114a5ae97193bb83daee1223c150c8bda2d6655a47482fb70",
"UpdateUser": "f3860479c8aaf60b1901dca62029b57c96953064a5a65a4ed92cf8e5173ed441",
"VerifyEmail": "37dc92ddb2ef943241e08bdfa7ee71c207fc876df739992d93ded6b9e76819d1"
"VerifyEmail": "37dc92ddb2ef943241e08bdfa7ee71c207fc876df739992d93ded6b9e76819d1",
"McpEvents": "bff9fa131f81cd8910d662b816d207f92cd684511dce76c2b624187013be4600",
"McpEventOptions": "f7628c3bb9d2c33edc0ed649e869f4c22705211dfdb1f60642912a58c4954b44",
"McpEvent": "2703b7592181b359bf05cb2ab656c103127d6ee13d7cb8b2cea72e34568a1fdf"
}
4 changes: 3 additions & 1 deletion @app/graphql/codegen.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
overwrite: true
schema: "../../data/schema.graphql"
documents: "../client/src/**/*.graphql"
documents:
- "../client/src/**/*.graphql"
- "../server/src/**/*.graphql"
hooks:
afterAllFileWrite:
- node scripts/addToPersistedOperations.mjs
Expand Down
5 changes: 4 additions & 1 deletion @app/graphql/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@
"4ccd52e00c526690ac5b44ca911534e96f936acd4ff02a2785d9932bbe11ff6c": "query SettingsPassword {\n currentUser {\n id\n hasPassword\n primaryEmail\n __typename\n }\n}",
"efef5d154b91120114a5ae97193bb83daee1223c150c8bda2d6655a47482fb70": "mutation UnlinkUserAuthentication($id: UUID!) {\n deleteUserAuthentication(input: {id: $id}) {\n user {\n id\n userAuthenticationsList(first: 50) {\n id\n identifier\n service\n createdAt\n __typename\n }\n __typename\n }\n __typename\n }\n}",
"f3860479c8aaf60b1901dca62029b57c96953064a5a65a4ed92cf8e5173ed441": "mutation UpdateUser($id: UUID!, $patch: UserPatch!) {\n updateUser(input: {id: $id, patch: $patch}) {\n clientMutationId\n user {\n id\n name\n username\n __typename\n }\n __typename\n }\n}",
"37dc92ddb2ef943241e08bdfa7ee71c207fc876df739992d93ded6b9e76819d1": "mutation VerifyEmail($id: UUID!, $token: String!) {\n verifyEmail(input: {userEmailId: $id, token: $token}) {\n success\n query {\n currentUser {\n id\n isVerified\n __typename\n }\n __typename\n }\n __typename\n }\n}"
"37dc92ddb2ef943241e08bdfa7ee71c207fc876df739992d93ded6b9e76819d1": "mutation VerifyEmail($id: UUID!, $token: String!) {\n verifyEmail(input: {userEmailId: $id, token: $token}) {\n success\n query {\n currentUser {\n id\n isVerified\n __typename\n }\n __typename\n }\n __typename\n }\n}",
"bff9fa131f81cd8910d662b816d207f92cd684511dce76c2b624187013be4600": "fragment McpEventSummary on Event {\n id\n slug\n name\n location\n eventStartTime\n eventEndTime\n registrationStartTime\n registrationEndTime\n signupOpen\n signupUpcoming\n ownerOrganization {\n name\n __typename\n }\n category {\n name\n __typename\n }\n __typename\n}\nquery McpEvents {\n signupOpenEvents: events(\n filter: {signupOpen: {equalTo: true}, isDraft: {equalTo: false}}\n orderBy: [IS_HIGHLIGHTED_DESC, REGISTRATION_END_TIME_ASC]\n ) {\n nodes {\n ...McpEventSummary\n __typename\n }\n __typename\n }\n signupUpcomingEvents: events(\n filter: {signupUpcoming: {equalTo: true}, isDraft: {equalTo: false}}\n orderBy: [IS_HIGHLIGHTED_DESC, REGISTRATION_START_TIME_ASC]\n ) {\n nodes {\n ...McpEventSummary\n __typename\n }\n __typename\n }\n}",
"f7628c3bb9d2c33edc0ed649e869f4c22705211dfdb1f60642912a58c4954b44": "query McpEventOptions {\n organizations {\n nodes {\n id\n name\n __typename\n }\n __typename\n }\n eventCategories(orderBy: NAME_ASC) {\n nodes {\n id\n name\n ownerOrganization {\n id\n __typename\n }\n __typename\n }\n __typename\n }\n}",
"2703b7592181b359bf05cb2ab656c103127d6ee13d7cb8b2cea72e34568a1fdf": "fragment McpEventSummary on Event {\n id\n slug\n name\n location\n eventStartTime\n eventEndTime\n registrationStartTime\n registrationEndTime\n signupOpen\n signupUpcoming\n ownerOrganization {\n name\n __typename\n }\n category {\n name\n __typename\n }\n __typename\n}\nquery McpEvent($slug: String!) {\n currentUser {\n name\n primaryEmail\n __typename\n }\n eventBySlug(slug: $slug) {\n ...McpEventSummary\n description\n isDraft\n openQuotaSize\n quotas(orderBy: POSITION_ASC) {\n nodes {\n id\n title\n size\n registrations {\n totalCount\n __typename\n }\n __typename\n }\n __typename\n }\n eventQuestions(orderBy: POSITION_ASC) {\n nodes {\n id\n type\n label\n isRequired\n data\n __typename\n }\n __typename\n }\n __typename\n }\n}"
}
Loading
Loading