From 8fedd4ef3bdd48dc42abc1d53006eefc145175e3 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 15 Feb 2023 14:34:12 +0100 Subject: [PATCH 1/2] Added delete check for citizen org ref #201 --- src/controllers/RunnerOrganizationController.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/controllers/RunnerOrganizationController.ts b/src/controllers/RunnerOrganizationController.ts index de19d49..5cf4183 100644 --- a/src/controllers/RunnerOrganizationController.ts +++ b/src/controllers/RunnerOrganizationController.ts @@ -1,4 +1,4 @@ -import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers'; +import { Authorized, BadRequestError, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { getConnectionManager, Repository } from 'typeorm'; import { RunnerOrganizationHasRunnersError, RunnerOrganizationHasTeamsError, RunnerOrganizationIdsNotMatchingError, RunnerOrganizationNotFoundError } from '../errors/RunnerOrganizationErrors'; @@ -114,6 +114,10 @@ export class RunnerOrganizationController { @OnUndefined(204) @OpenAPI({ description: 'Delete the organsisation whose id you provided.
If the organization still has runners and/or teams associated this will fail.
To delete the organization with all associated runners and teams set the force QueryParam to true (cascading deletion might take a while).
This won\'t delete the associated contact.
If no organization with this id exists it will just return 204(no content).' }) async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { + if (id == 1) { + throw new BadRequestError("You can't delete the citizen runner org."); + } + let organization = await this.runnerOrganizationRepository.findOne({ id: id }); if (!organization) { return null; } let runnerOrganization = await this.runnerOrganizationRepository.findOne(organization, { relations: ['contact', 'runners', 'teams'] }); -- 2.47.2 From d5c689d6937288df7dca14ce26fbbd4f46a8752a Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 15 Feb 2023 14:35:58 +0100 Subject: [PATCH 2/2] Updated tests ref #201 --- src/tests/runnerOrgs/org_delete.spec.ts | 6 ++++++ test.sqlite-journal | Bin 0 -> 12824 bytes 2 files changed, 6 insertions(+) create mode 100644 test.sqlite-journal diff --git a/src/tests/runnerOrgs/org_delete.spec.ts b/src/tests/runnerOrgs/org_delete.spec.ts index 92cbfce..293b5a6 100644 --- a/src/tests/runnerOrgs/org_delete.spec.ts +++ b/src/tests/runnerOrgs/org_delete.spec.ts @@ -22,6 +22,12 @@ describe('deletion (non-existant)', () => { expect(res2.status).toEqual(204); }); }); +describe('deletion of citizen sould fail', () => { + it('delete', async () => { + const res3 = await axios.delete(base + '/api/organizations/1', axios_config); + expect(res3.status).toEqual(400); + }); +}); // --------------- describe('adding + deletion (successfull)', () => { let added_org_id diff --git a/test.sqlite-journal b/test.sqlite-journal new file mode 100644 index 0000000000000000000000000000000000000000..b494b9359cdeb52cafea030d5e22f5109e6f4cc4 GIT binary patch literal 12824 zcmeHNPi))P85bqX)E`S!;<&8WxuWGc2`z6BMg7fTndYd07F%{48AwjT6ZzzDktmg- z+SC|U*hvHAHekhy4m-4`^|I5j6$N@|5un8`J+&CR-8!Jx?hq6hI-q@zlIZs+TXDSs z#V`txNWS-dAHU!4``-6HO8WE@|G$JcmA`sC9^Yfu`zLf<^mx4J5JPYG^?$&C5J4c% z2j22Cm>jqiae>g_l16)q@Y;`thUJKY8PWKmKB(nUj6L1Z&;8vjos1I z5sBq3^4Jg=mXY)khA4R6;#1#3mBQ*R%wbhBV3Y1j0QX)x7xT zNvyOk4R7`AWN8{v@(h+H5jkv=Ao4L(Gbj+F`tpQmi5ylW5fF;B`(kv0DDC^j2o@!M zC#{l>7iLhgpd7c0#S=VV31dytb5fIbeI+zWmiAo?Vp-C6$}Z`AF@P2r<@{llc!Kvy z7ORrpQ>wK4$?1v0wEru9EKK@OTc!X^IRPA2h$jK?Iens39RR!&g&hDGCjiKf=B432|3F+*R%$+~2sraPOe+1AfjuMBfSAw6uDYRS|sR;GhIW|u|~@q4fvJ<{T?*xNEXd=|MWzIws>sXx6ByU*W7i>sxRtC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