@@ -140,14 +143,17 @@
- {report.reported.username}
-
+ {report.reported?.username || ''}
+ {#if report.reported?.id}
+
+ {/if}
|
{new Intl.DateTimeFormat('de-DE', {
@@ -185,7 +191,7 @@
{#if activeReport}
@@ -226,19 +232,26 @@
}}>✕
- Report
-
- {activeReport.reporter.username} hat
- {activeReport.reported.username}
- am {new Intl.DateTimeFormat('de-DE', {
- year: 'numeric',
- month: 'long',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit'
- }).format(new Date(activeReport.createdAt))} Uhr reportet.
-
+ Report
+
+ Reporter
+
+
+ (activeReport.reported = {
+ ...activeReport.reported,
+ username: e.detail.input,
+ uuid: e.detail.value
+ })}
+ />
@@ -301,6 +314,11 @@
value="Speichern"
on:click={async () => {
await updateActiveReport();
+ if (activeReport.reported?.username && activeReport.reported?.id === undefined) {
+ activeReport.reported.id = -1;
+ } else {
+ activeReport.reported = undefined;
+ }
currentPageReports = [...currentPageReports];
if (activeReport.originalStatus !== 'reviewed' && activeReport.status === 'reviewed') {
$reportCount -= 1;
diff --git a/src/routes/admin/reports/+server.ts b/src/routes/admin/reports/+server.ts
index 2301f3e..eb45966 100644
--- a/src/routes/admin/reports/+server.ts
+++ b/src/routes/admin/reports/+server.ts
@@ -92,6 +92,7 @@ export const PATCH = (async ({ request, cookies }) => {
const data: {
id: number;
+ reported: string | null;
auditor: number;
notice: string | null;
statement: string | null;
@@ -102,9 +103,13 @@ export const PATCH = (async ({ request, cookies }) => {
const report = await Report.findOne({ where: { id: data.id } });
const admin = await Admin.findOne({ where: { id: data.auditor } });
- if (report === null || (admin === null && data.auditor != -1))
+ const reported = data.reported
+ ? await User.findOne({ where: { uuid: data.reported } })
+ : undefined;
+ if (report === null || (admin === null && data.auditor != -1) || reported === null)
return new Response(null, { status: 400 });
+ report.reported_id = reported?.id || null;
if (data.notice != null) report.notice = data.notice;
if (data.statement != null) report.statement = data.statement;
if (data.status != null) report.status = data.status;
@@ -115,7 +120,7 @@ export const PATCH = (async ({ request, cookies }) => {
return new Response();
}) satisfies RequestHandler;
-export const PUT = (async ({ request, cookies, url }) => {
+export const PUT = (async ({ request, cookies }) => {
if (getSession(cookies, { permissions: [Permissions.ReportWrite] }) == null) {
return new Response(null, {
status: 401
@@ -124,23 +129,18 @@ export const PUT = (async ({ request, cookies, url }) => {
const data: {
reporter: string;
- reported: string;
+ reported: string | null;
reason: string;
body: string | null;
} = await request.json();
- if (
- data.reporter == null ||
- data.reported == null ||
- data.reason == null ||
- data.body === undefined
- )
+ if (data.reporter == null || data.reason == null || data.body === undefined)
return new Response(null, { status: 400 });
const reporter = await User.findOne({ where: { uuid: data.reporter } });
- const reported = await User.findOne({ where: { uuid: data.reported } });
+ const reported = data.reported ? await User.findOne({ where: { uuid: data.reported } }) : null;
- if (reporter == null || reported == null) return new Response(null, { status: 400 });
+ if (reporter == null) return new Response(null, { status: 400 });
const report = await Report.create({
subject: data.reason,
@@ -150,10 +150,12 @@ export const PUT = (async ({ request, cookies, url }) => {
url_hash: crypto.randomBytes(18).toString('hex'),
completed: false,
reporter_id: reporter.id,
- reported_id: reported.id
+ reported_id: reported?.id || null
});
report.dataValues.reporter = await User.findOne({ where: { id: report.reporter_id } });
- report.dataValues.reported = await User.findOne({ where: { id: report.reported_id } });
+ report.dataValues.reported = report.reported_id
+ ? await User.findOne({ where: { id: report.reported_id } })
+ : null;
report.dataValues.auditor = null;
return new Response(JSON.stringify(report), {
diff --git a/src/routes/admin/reports/NewReportModal.svelte b/src/routes/admin/reports/NewReportModal.svelte
index 8957c09..fbb4ab0 100644
--- a/src/routes/admin/reports/NewReportModal.svelte
+++ b/src/routes/admin/reports/NewReportModal.svelte
@@ -4,6 +4,7 @@
import Textarea from '$lib/components/Input/Textarea.svelte';
import Search from '$lib/components/Input/Search.svelte';
import { createEventDispatcher } from 'svelte';
+ import { usernameSuggestions } from '$lib/utils';
const dispatch = createEventDispatcher();
@@ -12,27 +13,12 @@
let reason = '';
let body = '';
- async function usernameSuggestions(username: string): Promise<{ name: string; value: string }[]> {
- const response = await fetch(`${env.PUBLIC_BASE_PATH}/admin/users`, {
- method: 'POST',
- body: JSON.stringify({
- limit: 6,
- search: username,
- slim: true
- })
- });
- const json: { username: string; uuid: string }[] = await response.json();
- return json.map((v) => {
- return { name: v.username, value: v.uuid };
- });
- }
-
async function newReport() {
const response = await fetch(`${env.PUBLIC_BASE_PATH}/admin/reports`, {
method: 'PUT',
body: JSON.stringify({
reporter: reporter,
- reported: reported,
+ reported: reported || null,
reason: reason,
body: body || null
})
@@ -66,10 +52,10 @@
diff --git a/src/routes/report/+server.ts b/src/routes/report/+server.ts
index f222841..3981dba 100644
--- a/src/routes/report/+server.ts
+++ b/src/routes/report/+server.ts
@@ -8,15 +8,14 @@ export const POST = (async ({ request, url }) => {
if (env.REPORT_SECRET && url.searchParams.get('secret') !== env.REPORT_SECRET)
return new Response(null, { status: 401 });
- const data: { reporter: string; reported: string; reason: string } = await request.json();
+ const data: { reporter: string; reported: string | null; reason: string } = await request.json();
- if (data.reporter == null || data.reported == null || data.reason == null)
- return new Response(null, { status: 400 });
+ if (data.reporter == null || data.reason == null) return new Response(null, { status: 400 });
const reporter = await User.findOne({ where: { uuid: data.reporter } });
- const reported = await User.findOne({ where: { uuid: data.reported } });
+ const reported = data.reported ? await User.findOne({ where: { uuid: data.reported } }) : null;
- if (reporter == null || reported == null) return new Response(null, { status: 400 });
+ if (reporter == null) return new Response(null, { status: 400 });
const report = await Report.create({
subject: data.reason,
@@ -26,7 +25,7 @@ export const POST = (async ({ request, url }) => {
url_hash: crypto.randomBytes(18).toString('hex'),
completed: false,
reporter_id: reporter.id,
- reported_id: reported.id
+ reported_id: reported?.id || null
});
return new Response(
diff --git a/src/routes/report/[...url_hash]/+page.server.ts b/src/routes/report/[...url_hash]/+page.server.ts
index 139199f..b7ed125 100644
--- a/src/routes/report/[...url_hash]/+page.server.ts
+++ b/src/routes/report/[...url_hash]/+page.server.ts
@@ -22,7 +22,7 @@ export const load: PageServerLoad = async ({ params }) => {
name: report.reporter.username
},
reported: {
- name: report.reported.username
+ name: report.reported?.username || null
}
};
};
diff --git a/src/routes/report/[...url_hash]/+page.svelte b/src/routes/report/[...url_hash]/+page.svelte
index 6938b40..20f4915 100644
--- a/src/routes/report/[...url_hash]/+page.svelte
+++ b/src/routes/report/[...url_hash]/+page.svelte
@@ -18,6 +18,7 @@
(data.draft = false)}
/>
diff --git a/src/routes/report/[...url_hash]/ReportDraft.svelte b/src/routes/report/[...url_hash]/ReportDraft.svelte
index ed7bb63..77257d7 100644
--- a/src/routes/report/[...url_hash]/ReportDraft.svelte
+++ b/src/routes/report/[...url_hash]/ReportDraft.svelte
@@ -5,7 +5,8 @@
import { page } from '$app/stores';
import { createEventDispatcher } from 'svelte';
- export let reportedName: string;
+ export let reporterName: string;
+ export let reportedName: string | null;
export let reason: string;
let body: string;
@@ -25,7 +26,10 @@
- Report für {reportedName}
+
+ Report von {reporterName} gegen
+ {reportedName || 'unbekannt'}
+
|