diff --git a/gradesa/src/app/admin/add-admin/page.js b/gradesa/src/app/admin/add-admin/page.js deleted file mode 100644 index 0c6dd10..0000000 --- a/gradesa/src/app/admin/add-admin/page.js +++ /dev/null @@ -1,38 +0,0 @@ -"use client"; -import { Button } from "@/components/ui/button"; -import { useRequest } from "@/shared/hooks/useRequest"; -import { useState } from "react"; - -export default function AddAdmin() { - const [email, setEmail] = useState(""); - const [error, setError] = useState(null); - const [success, setSuccess] = useState(null); - const request = useRequest(); - - const handleSubmit = async function (e) { - e.preventDefault(); - try { - const res = await request("admin/add-admin", { email }); - setSuccess(res.data.message || "user added as admin successfully"); - setError(null); // nollaa virhe jos onnistuu - } catch (err) { - setError(err.message || "Tuntematon virhe"); - setSuccess(null); - } - }; - - return ( -
- setEmail(e.target.value)} - /> -
- - - {error &&

{error}

} - {success &&

{success}

} -
- ); -} diff --git a/gradesa/src/app/api/admin/add-admin/add_admin.test.js b/gradesa/src/app/api/admin/add-admin/add_admin.test.js deleted file mode 100644 index db435ec..0000000 --- a/gradesa/src/app/api/admin/add-admin/add_admin.test.js +++ /dev/null @@ -1,87 +0,0 @@ -import { describe, it, expect, vi, beforeEach } from "vitest"; -import { POST } from "./route"; -import { useTestRequest } from "@/backend/test/mock-request"; -import { useTestDatabase } from "@/backend/test/testdb"; -import { TestFactory } from "@/backend/test/testfactory"; -import { checkSession } from "@/backend/auth/session"; -import { DB } from "@/backend/db"; - -vi.mock("@/backend/auth/session", () => ({ - checkSession: vi.fn(), -})); - -describe("GET /api/add-admin", () => { - useTestDatabase(); - - let adminUser; - let normalUser; - - beforeEach(async () => { - adminUser = await TestFactory.user({ is_admin: true }); - normalUser = await TestFactory.user({ is_admin: false }); - - vi.clearAllMocks(); - }); - - const postRequest = async (email, authUser) => { - const { mockPost } = useTestRequest(); - const request = mockPost("/api/add-admin", { email }, authUser); - - checkSession.mockImplementation(() => - Promise.resolve( - authUser - ? { - id: authUser.id, - email: authUser.email, - is_admin: authUser.is_admin, - } - : null - ) - ); - - return POST(request); - }; - - it("should allow an admin to promote a user to admin", async () => { - const response = await postRequest(normalUser.email, adminUser); - const result = await response.json(); - - expect(response.status).toBe(200); - expect(result.success).toBe(true); - expect(result.message).toBe( - "Benutzer erfolgreich als administrator hinzugefügt" - ); - - const dbUser = await DB.pool(`SELECT is_admin FROM users WHERE id = $1`, [ - normalUser.id, - ]); - expect(dbUser.rows[0].is_admin).toBe(true); - }); - - it("should return 404 if user with email does not exist", async () => { - const response = await postRequest("notfound@example.com", adminUser); - const result = await response.json(); - - expect(response.status).toBe(404); - expect(result.error).toBe( - "Ein Benutzer mit dieser E-Mail-Adresse existiert nicht." - ); - }); - - it("should require authentication", async () => { - const response = await postRequest(normalUser.email, null); - expect(response.status).toBe(401); - expect(checkSession).toHaveBeenCalled(); - }); - - it("should throw on database errors", async () => { - const originalPool = DB.pool; - DB.pool = vi.fn().mockRejectedValueOnce(new Error("DB failure")); - - await expect(postRequest(normalUser.email, adminUser)).rejects.toThrow( - "DB failure" - ); - - DB.pool = originalPool; - }); -}); diff --git a/gradesa/src/app/api/admin/add-admin/route.js b/gradesa/src/app/api/admin/add-admin/route.js deleted file mode 100644 index 3a900a9..0000000 --- a/gradesa/src/app/api/admin/add-admin/route.js +++ /dev/null @@ -1,55 +0,0 @@ -import { withAuth } from "@/backend/middleware/withAuth"; -import { DB } from "@/backend/db"; -import { NextResponse } from "next/server"; - -export const POST = withAuth( - async (req) => { - const body = await req.json(); - const { email } = body; - - // Check first if a user can be found with the email adress given: - - const userResult = await DB.pool( - ` - SELECT id FROM users - WHERE email = $1 - `, - [email] - ); - - // If not, return an error message - - if (userResult.rows.length === 0) { - return NextResponse.json( - { error: "Ein Benutzer mit dieser E-Mail-Adresse existiert nicht." }, - { status: 404 } - ); - } - - const userId = userResult.rows[0].id; - - // Below the user is updated to an admin: - - await DB.transaction(async (tx) => { - await tx.query( - ` - UPDATE users SET is_admin = true - WHERE id = $1 - `, - [userId] - ); - }); - - return NextResponse.json( - { - success: true, - message: "Benutzer erfolgreich als administrator hinzugefügt", - }, - { status: 200 } - ); - }, - { - requireAdmin: true, - requireAuth: true, - } -); diff --git a/gradesa/src/app/contact/contact.css b/gradesa/src/app/contact/contact.css index 1a76c70..3523613 100644 --- a/gradesa/src/app/contact/contact.css +++ b/gradesa/src/app/contact/contact.css @@ -33,9 +33,10 @@ } .auth-title { - text-align: left; + text-align: center; margin-bottom: var(--u-lg); color: var(--fg1); + font-size: 1.9em; } .talkback-message-input { @@ -44,6 +45,13 @@ max-width: 100%; } +.talkback-description { + color: var(--fg1); + margin-top: 0; + margin-bottom: var(--u-lg); + font-style: italic; +} + .form-group { display: flex; flex-direction: column; @@ -56,7 +64,6 @@ .form-label { display: block; - /* margin-bottom: var(--u-md); */ } .form-input { diff --git a/gradesa/src/app/contact/page.js b/gradesa/src/app/contact/page.js index b86ba1d..060778d 100644 --- a/gradesa/src/app/contact/page.js +++ b/gradesa/src/app/contact/page.js @@ -15,7 +15,7 @@ export default function ContactPage() { const [isSending, setIsSending] = useState(false); // Show nothing while session is being resolved, or if not logged in. - // Middleware already redirects unauthenticated requests to /auth/login. + // Middleware already redirects unauthenticated requests to /auth/register. if (!isAuthResolved || !isLoggedIn) return null; const handleSubmit = async (event) => { @@ -61,18 +61,25 @@ export default function ContactPage() { return (
-

Kontaktieren Sie unser Team

+

+ Kontaktieren Sie unser Team +

+

+ Bitte vergessen Sie Ihre eigene E-Mail-Adresse nicht, + damit wir Ihnen antworten können. +

{error &&

{error}

}
- */}