diff --git a/@app/client/src/pages/update-registration/[updateToken]/index.tsx b/@app/client/src/pages/update-registration/[updateToken]/index.tsx
index 80e74bfa..3a53cc32 100644
--- a/@app/client/src/pages/update-registration/[updateToken]/index.tsx
+++ b/@app/client/src/pages/update-registration/[updateToken]/index.tsx
@@ -7,7 +7,7 @@ import {
} from "@app/components"
import { useUpdateEventRegistrationPageQuery } from "@app/graphql"
import { filterObjectByKeys } from "@app/lib"
-import { Col, Row } from "antd"
+import { Alert, Col, Row } from "antd"
import { useRouter } from "next/router"
import type { NextPage } from "next"
@@ -55,16 +55,29 @@ const UpdateEventRegistrationPage: NextPage = () => {
{event?.name[lang]} - {quota?.title[lang]}
-
+ {event && !event.signupOpen ? (
+
+
+
+
+
+ ) : (
+
+ )}
)
}
diff --git a/@app/client/src/translations/en/register_event.json b/@app/client/src/translations/en/register_event.json
index ffb1a98d..428d47e8 100644
--- a/@app/client/src/translations/en/register_event.json
+++ b/@app/client/src/translations/en/register_event.json
@@ -30,6 +30,7 @@
},
"title": "Register to event:",
"updateRegistration": {
+ "closed": "Registration for this event has closed, so your registration can no longer be changed. Please contact the event organizers.",
"title": "Update event registration information"
},
"you": "You!"
diff --git a/@app/client/src/translations/fi/register_event.json b/@app/client/src/translations/fi/register_event.json
index 4c439c23..3db2ece7 100644
--- a/@app/client/src/translations/fi/register_event.json
+++ b/@app/client/src/translations/fi/register_event.json
@@ -30,6 +30,7 @@
},
"title": "Ilmoittaudu tapahtumaan:",
"updateRegistration": {
+ "closed": "Ilmoittautuminen tähän tapahtumaan on päättynyt, joten ilmoittautumistasi ei voi enää muuttaa. Ota yhteyttä tapahtuman järjestäjiin.",
"title": "Päivitä rekisteröitymistiedot"
},
"you": "Sinä!"
diff --git a/@app/client/src/translations/se/register_event.json b/@app/client/src/translations/se/register_event.json
index f003ddc3..bb4e2809 100644
--- a/@app/client/src/translations/se/register_event.json
+++ b/@app/client/src/translations/se/register_event.json
@@ -30,6 +30,7 @@
},
"title": "Registrera dig till event:",
"updateRegistration": {
+ "closed": "Registreringen till detta evenemang har stängt, så din registrering kan inte längre ändras. Kontakta evenemangets arrangörer.",
"title": "Uppdatera information om händelseregistrering"
},
"you": "du!"
diff --git a/@app/db/migrations/current/3-block-registration-update-after-close.sql b/@app/db/migrations/current/3-block-registration-update-after-close.sql
new file mode 100644
index 00000000..2e698cb6
--- /dev/null
+++ b/@app/db/migrations/current/3-block-registration-update-after-close.sql
@@ -0,0 +1,50 @@
+/*
+ * A registration is editable through its update token only while event signup
+ * is open, matching `delete_registration`. Admins edit registrations through
+ * the same function (after fetching the token with
+ * `admin_update_registration`), so they are exempt and can correct
+ * registrations after signup has closed.
+ */
+
+create or replace function app_public.update_registration(
+ "updateToken" text,
+ "firstName" text,
+ "lastName" text,
+ answers jsonb default null
+)
+returns app_public.registrations as $$
+declare
+ v_registration_secret app_private.registration_secrets;
+ v_registration app_public.registrations;
+ v_event app_public.events;
+ v_required_question_ids uuid[];
+begin
+ select * into v_registration_secret
+ from app_private.registration_secrets
+ where update_token = "updateToken";
+
+ if v_registration_secret is null then
+ raise exception 'Registration matching token was not found.' using errcode = 'NTFND';
+ end if;
+
+ select * into v_event from app_public.events where id = v_registration_secret.event_id;
+
+ if not app_public.current_user_is_admin()
+ and ((v_event is null) or not (select app_public.events_signup_open(v_event))) then
+ raise exception 'Updating a registration after event signup has closed is not allowed. Please contact the event organizers.' using errcode = 'DNIED';
+ end if;
+
+ -- If the registration doesn't provide answers to all of the required questions it is invalid.
+ -- This is double validated in the _200_registration_is_valid trigger.
+ v_required_question_ids := array(select id from app_public.event_questions where event_id = v_registration_secret.event_id and is_required = True);
+ perform app_public.validate_registration_answers(v_registration_secret.event_id, v_required_question_ids, answers);
+
+ update app_public.registrations
+ set first_name = "firstName", last_name = "lastName", answers = update_registration.answers
+ where id = v_registration_secret.registration_id
+ returning
+ * into v_registration;
+
+ return v_registration;
+end;
+$$ language plpgsql volatile security definer set search_path to pg_catalog, public, pg_temp;
diff --git a/@app/server/__tests__/mutations/__snapshots__/updateRegistration.test.ts.snap b/@app/server/__tests__/mutations/__snapshots__/updateRegistration.test.ts.snap
index a9e22aa4..4c609831 100644
--- a/@app/server/__tests__/mutations/__snapshots__/updateRegistration.test.ts.snap
+++ b/@app/server/__tests__/mutations/__snapshots__/updateRegistration.test.ts.snap
@@ -1,5 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`UpdateRegistration admin can update registration after event signup has closed 1`] = `
+{
+ "data": {
+ "updateRegistration": {
+ "registration": {
+ "answers": "[random-3]",
+ "createdAt": "[timestamp-1]",
+ "firstName": "Päivi",
+ "fullName": "Päivi Tetty",
+ "id": "[id-1]",
+ "lastName": "Tetty",
+ "position": 1,
+ "quota": {
+ "id": "[id-2]",
+ "position": 0,
+ "size": "[random-2]",
+ "title": "[random-1]",
+ },
+ "status": "IN_QUOTA",
+ "updatedAt": "[timestamp-2]",
+ },
+ },
+ },
+}
+`;
+
exports[`UpdateRegistration can update a registration with a valid updateToken 1`] = `
{
"data": {
@@ -37,7 +63,7 @@ exports[`UpdateRegistration can't update registration if registration token is n
"exception": {
"code": "NTFND",
"severity": "ERROR",
- "where": "PL/pgSQL function app_public.update_registration(text,text,text,jsonb) line 12 at RAISE",
+ "where": "PL/pgSQL function app_public.update_registration(text,text,text,jsonb) line 13 at RAISE",
},
},
"locations": [
@@ -68,7 +94,7 @@ exports[`UpdateRegistration can't update registration if required answers are no
"severity": "ERROR",
"where": "PL/pgSQL function app_public.validate_registration_answers(uuid,uuid[],jsonb) line 50 at RAISE
SQL statement "SELECT app_public.validate_registration_answers(v_registration_secret.event_id, v_required_question_ids, answers)"
-PL/pgSQL function app_public.update_registration(text,text,text,jsonb) line 18 at PERFORM",
+PL/pgSQL function app_public.update_registration(text,text,text,jsonb) line 26 at PERFORM",
},
},
"locations": [
@@ -85,3 +111,32 @@ PL/pgSQL function app_public.update_registration(text,text,text,jsonb) line 18 a
],
}
`;
+
+exports[`UpdateRegistration can't update registration once event signup has closed 1`] = `
+{
+ "data": {
+ "updateRegistration": null,
+ },
+ "errors": [
+ {
+ "extensions": {
+ "exception": {
+ "code": "DNIED",
+ "severity": "ERROR",
+ "where": "PL/pgSQL function app_public.update_registration(text,text,text,jsonb) line 20 at RAISE",
+ },
+ },
+ "locations": [
+ {
+ "column": 3,
+ "line": 2,
+ },
+ ],
+ "message": "Updating a registration after event signup has closed is not allowed. Please contact the event organizers.",
+ "path": [
+ "updateRegistration",
+ ],
+ },
+ ],
+}
+`;
diff --git a/@app/server/__tests__/mutations/updateRegistration.test.ts b/@app/server/__tests__/mutations/updateRegistration.test.ts
index a9d1f8e0..3e6b22c2 100644
--- a/@app/server/__tests__/mutations/updateRegistration.test.ts
+++ b/@app/server/__tests__/mutations/updateRegistration.test.ts
@@ -1,4 +1,5 @@
import { UpdateEventRegistrationDocument } from "@app/graphql"
+import dayjs from "dayjs"
import {
asRoot,
@@ -7,9 +8,27 @@ import {
removePropFromObject,
runGraphQLQuery,
setup,
+ sleep,
teardown,
} from "../helpers"
+// Event times where signup is open for one second from now. NOW() runs in the
+// database, so tests sleep past the window instead of faking timers.
+function shortSignupTimes() {
+ const registrationStartTime = dayjs().toDate()
+ const registrationEndTime = dayjs(registrationStartTime)
+ .add(1, "second")
+ .toDate()
+ const eventStartTime = dayjs(registrationEndTime).add(7, "day").toDate()
+ const eventEndTime = dayjs(eventStartTime).add(7, "day").toDate()
+ return [
+ registrationStartTime,
+ registrationEndTime,
+ eventStartTime,
+ eventEndTime,
+ ]
+}
+
beforeEach(deleteTestData)
beforeAll(setup)
afterAll(teardown)
@@ -133,4 +152,90 @@ describe("UpdateRegistration", () => {
}
)
})
+
+ it("can't update registration once event signup has closed", async () => {
+ const { registrations, registrationSecrets } =
+ await createEventDataAndLogin({
+ eventOptions: { create: true, times: shortSignupTimes() },
+ })
+ const { update_token: updateToken } = registrationSecrets[0]
+ const answers = registrations[0].answers
+
+ await sleep(1000)
+
+ await runGraphQLQuery(
+ UpdateEventRegistrationDocument,
+
+ // GraphQL variables:
+ {
+ input: {
+ updateToken,
+ firstName: "Päivi",
+ lastName: "Tetty",
+ answers,
+ },
+ },
+
+ // Additional props to add to `req` (e.g. `user: {sessionId: '...'}`)
+ {},
+
+ // This function runs all your test assertions:
+ async (json) => {
+ expect(json.errors).toBeTruthy()
+
+ const message = json.errors![0].message
+ const code = json.errors![0].extensions.exception.code
+ expect(message).toEqual(
+ "Updating a registration after event signup has closed is not allowed. Please contact the event organizers."
+ )
+ expect(code).toEqual("DNIED")
+ }
+ )
+ })
+
+ it("admin can update registration after event signup has closed", async () => {
+ const { registrations, registrationSecrets, session } =
+ await createEventDataAndLogin({
+ userOptions: {
+ create: true,
+ amount: 1,
+ isVerified: true,
+ isAdmin: true,
+ },
+ eventOptions: { create: true, times: shortSignupTimes() },
+ })
+ const { update_token: updateToken } = registrationSecrets[0]
+ const answers = registrations[0].answers
+
+ await sleep(1000)
+
+ await runGraphQLQuery(
+ UpdateEventRegistrationDocument,
+
+ // GraphQL variables:
+ {
+ input: {
+ updateToken,
+ firstName: "Päivi",
+ lastName: "Tetty",
+ answers,
+ },
+ },
+
+ // Additional props to add to `req` (e.g. `user: {sessionId: '...'}`)
+ {
+ user: { sessionId: session.uuid },
+ },
+
+ // This function runs all your test assertions:
+ async (json) => {
+ expect(json.errors).toBeFalsy()
+
+ const { firstName, lastName } =
+ json.data!.updateRegistration.registration
+ expect(firstName).toEqual("Päivi")
+ expect(lastName).toEqual("Tetty")
+ }
+ )
+ })
})