Skip to content

Commit 12733dd

Browse files
authored
Merge branch 'TFNS:main' into main
2 parents 943b2f0 + b7f3848 commit 12733dd

27 files changed

+1001
-93
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
services:
1414
postgres:
15-
image: postgres:latest
15+
image: postgres@sha256:596e4c843a9db32269a3757624d8a6a6f633e01895acb83fe0842497fd897eb7
1616
env:
1717
POSTGRES_PASSWORD: ctfnote
1818
POSTGRES_USER: ctfnote
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- Migration: Assign users to tasks by managers (GraphQL integration)
2+
-- This migration introduces GraphQL functions to allow managers to assign/unassign any team member to a task.
3+
4+
-- GraphQL mutation for assign_user_to_task
5+
CREATE OR REPLACE FUNCTION ctfnote.assign_user_to_task(profile_id int, task_id int)
6+
RETURNS ctfnote.work_on_task
7+
AS $$
8+
WITH inserted AS (
9+
INSERT INTO ctfnote.work_on_task (task_id, profile_id, active)
10+
VALUES (assign_user_to_task.task_id, assign_user_to_task.profile_id, TRUE)
11+
ON CONFLICT (task_id, profile_id) DO UPDATE
12+
SET active = TRUE
13+
RETURNING *
14+
)
15+
SELECT * FROM inserted;
16+
$$
17+
LANGUAGE SQL;
18+
19+
GRANT EXECUTE ON FUNCTION ctfnote.assign_user_to_task(profile_id int, task_id int) TO user_manager;
20+
21+
-- GraphQL mutation for unassign_user_from_task
22+
CREATE OR REPLACE FUNCTION ctfnote.unassign_user_from_task(profile_id int, task_id int)
23+
RETURNS ctfnote.work_on_task
24+
AS $$
25+
WITH updated AS (
26+
UPDATE ctfnote.work_on_task
27+
SET active = FALSE
28+
WHERE task_id = unassign_user_from_task.task_id
29+
AND profile_id = unassign_user_from_task.profile_id
30+
RETURNING *
31+
)
32+
SELECT * FROM updated;
33+
$$ LANGUAGE SQL;
34+
35+
GRANT EXECUTE ON FUNCTION ctfnote.unassign_user_from_task(profile_id int, task_id int) TO user_manager;

api/src/discord/agile/hooks.ts

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@ async function handleUpdateTask(
100100
}
101101
}
102102

103-
async function handleStartWorkingOn(
104-
guild: Guild,
105-
taskId: bigint,
106-
userId: bigint
107-
) {
108-
await moveChannel(guild, taskId, null, ChannelMovingEvent.START);
109-
await sendStartWorkingOnMessage(guild, userId, taskId);
110-
}
111-
112103
async function handleUpdateUserRole(
113104
guild: Guild,
114105
userId: bigint,
@@ -177,7 +168,9 @@ const discordMutationHook = (_build: Build) => (fieldContext: Context<any>) => {
177168
fieldContext.scope.fieldName !== "deleteCtf" &&
178169
fieldContext.scope.fieldName !== "updateUserRole" &&
179170
fieldContext.scope.fieldName !== "setDiscordEventLink" &&
180-
fieldContext.scope.fieldName !== "registerWithToken"
171+
fieldContext.scope.fieldName !== "registerWithToken" &&
172+
fieldContext.scope.fieldName !== "assignUserToTask" &&
173+
fieldContext.scope.fieldName !== "unassignUserFromTask"
181174
) {
182175
return null;
183176
}
@@ -198,7 +191,7 @@ const discordMutationHook = (_build: Build) => (fieldContext: Context<any>) => {
198191
//add challenges to the ctf channel discord
199192
switch (fieldContext.scope.fieldName) {
200193
case "createTask":
201-
handleCreateTask(
194+
await handleCreateTask(
202195
guild,
203196
args.input.ctfId,
204197
args.input.title,
@@ -225,7 +218,7 @@ const discordMutationHook = (_build: Build) => (fieldContext: Context<any>) => {
225218
});
226219
break;
227220
case "startWorkingOn":
228-
handleStartWorkingOn(
221+
sendStartWorkingOnMessage(
229222
guild,
230223
args.input.taskId,
231224
context.jwtClaims.user_id
@@ -285,6 +278,27 @@ const discordMutationHook = (_build: Build) => (fieldContext: Context<any>) => {
285278
console.error("Failed to register with token.", err);
286279
});
287280
break;
281+
case "assignUserToTask":
282+
sendStartWorkingOnMessage(
283+
guild,
284+
args.input.profileId,
285+
args.input.taskId,
286+
context.jwtClaims.user_id
287+
).catch((err) => {
288+
console.error("Failed to start working on task.", err);
289+
});
290+
break;
291+
case "unassignUserFromTask":
292+
sendStopWorkingOnMessage(
293+
guild,
294+
args.input.profileId,
295+
args.input.taskId,
296+
false,
297+
context.jwtClaims.user_id
298+
).catch((err) => {
299+
console.error("Failed to stop working on task.", err);
300+
});
301+
break;
288302
default:
289303
break;
290304
}
@@ -348,31 +362,37 @@ const discordMutationHook = (_build: Build) => (fieldContext: Context<any>) => {
348362
export async function sendStartWorkingOnMessage(
349363
guild: Guild,
350364
userId: bigint,
351-
task: Task | bigint
365+
task: Task | bigint,
366+
assignedBy: bigint | null = null
352367
) {
353368
await moveChannel(guild, task, null, ChannelMovingEvent.START);
354-
return sendMessageToTask(
355-
guild,
356-
task,
357-
`${await convertToUsernameFormat(userId)} is working on this task!`
358-
);
369+
370+
let msg = `${await convertToUsernameFormat(userId)} is working on this task!`;
371+
if (assignedBy != null) {
372+
msg += ` (assigned by: ${await convertToUsernameFormat(assignedBy)})`;
373+
}
374+
375+
return sendMessageToTask(guild, task, msg);
359376
}
360377

361378
export async function sendStopWorkingOnMessage(
362379
guild: Guild,
363380
userId: bigint,
364381
task: Task | bigint,
365-
cancel = false
382+
cancel = false,
383+
assignedBy: bigint | null = null
366384
) {
367385
let text = "stopped";
368386
if (cancel) {
369387
text = "cancelled";
370388
}
371-
return sendMessageToTask(
372-
guild,
373-
task,
374-
`${await convertToUsernameFormat(userId)} ${text} working on this task!`
375-
);
389+
390+
let msg = `${await convertToUsernameFormat(userId)} ${text} working on this task!`;
391+
if (assignedBy != null) {
392+
msg += ` (assigned by: ${await convertToUsernameFormat(assignedBy)})`;
393+
}
394+
395+
return sendMessageToTask(guild, task, msg);
376396
}
377397

378398
export async function handleDeleteCtf(ctfId: string | bigint, guild: Guild) {

docker-compose.dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ services:
1515
ports:
1616
- "5432:5432"
1717
hedgedoc:
18-
image: quay.io/hedgedoc/hedgedoc:1.10.0
18+
image: quay.io/hedgedoc/hedgedoc:1.10.3
1919
environment:
2020
CMD_DB_URL: "postgres://ctfnote:ctfnote@db:5432/hedgedoc"
2121
CMD_URL_PATH: "pad"
2222
CMD_IMAGE_UPLOAD_TYPE: "filesystem"
2323
CMD_CSP_ENABLE: "false"
24+
CMD_RATE_LIMIT_NEW_NOTES: "0"
2425
depends_on:
2526
- db
2627
restart: unless-stopped

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ services:
6060
ports:
6161
- 127.0.0.1:8080:80
6262
hedgedoc:
63-
image: quay.io/hedgedoc/hedgedoc:1.10.0
63+
image: quay.io/hedgedoc/hedgedoc:1.10.3
6464
environment:
6565
- CMD_DB_URL=postgres://ctfnote:ctfnote@db:5432/hedgedoc
6666
- CMD_URL_PATH=pad
6767
- CMD_DOMAIN
6868
- CMD_PROTOCOL_USESSL
69+
- CMD_RATE_LIMIT_NEW_NOTES=0
6970
- CMD_CSP_ENABLE=${CMD_CSP_ENABLE:-false}
7071
- CMD_IMAGE_UPLOAD_TYPE=${CMD_IMAGE_UPLOAD_TYPE:-imgur}
7172
- CMD_DOCUMENT_MAX_LENGTH=${CMD_DOCUMENT_MAX_LENGTH:-100000}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)