From 83e781c877f40a617cfe5a54159758f752157660 Mon Sep 17 00:00:00 2001 From: Peter KW Date: Mon, 18 Mar 2024 18:31:58 +0100 Subject: [PATCH 01/10] Fixed getting the username and removed comment --- frontend/src/Components/UserProjectListAdmin.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/src/Components/UserProjectListAdmin.tsx b/frontend/src/Components/UserProjectListAdmin.tsx index 423e793..c4857db 100644 --- a/frontend/src/Components/UserProjectListAdmin.tsx +++ b/frontend/src/Components/UserProjectListAdmin.tsx @@ -9,7 +9,7 @@ const UserProjectListAdmin: React.FC = () => { const fetchProjects = async (): Promise => { try { const token = localStorage.getItem("accessToken") ?? ""; - const username = getUsernameFromContext(); // Assuming you have a function to get the username from your context + const username = localStorage.getItem("username") ?? ""; const response = await api.getUserProjects(username, token); if (response.success) { @@ -32,7 +32,6 @@ const UserProjectListAdmin: React.FC = () => { {projects.map((project) => (
  • {project.name} - {/* Add any additional project details you want to display */}
  • ))} From e55b380bb4148ba0e3297e81d95536b800307c06 Mon Sep 17 00:00:00 2001 From: Peter KW Date: Tue, 19 Mar 2024 00:14:55 +0100 Subject: [PATCH 02/10] Should be able to delete users except for self now --- backend/internal/handlers/handlers_user_related.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/internal/handlers/handlers_user_related.go b/backend/internal/handlers/handlers_user_related.go index 0619ea5..194f5d5 100644 --- a/backend/internal/handlers/handlers_user_related.go +++ b/backend/internal/handlers/handlers_user_related.go @@ -44,8 +44,8 @@ func (gs *GState) UserDelete(c *fiber.Ctx) error { // Read username from Locals auth_username := c.Locals("user").(*jwt.Token).Claims.(jwt.MapClaims)["name"].(string) - if username != auth_username { - return c.Status(403).SendString("You can only delete yourself") + if username == auth_username { + return c.Status(403).SendString("You can't delete yourself") } if err := gs.Db.RemoveUser(username); err != nil { From db4f86971239caad7dcdd61f3f394d75998f95f3 Mon Sep 17 00:00:00 2001 From: Peter KW Date: Tue, 19 Mar 2024 00:15:42 +0100 Subject: [PATCH 03/10] Delete user component --- frontend/src/Components/DeleteUser.tsx | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 frontend/src/Components/DeleteUser.tsx diff --git a/frontend/src/Components/DeleteUser.tsx b/frontend/src/Components/DeleteUser.tsx new file mode 100644 index 0000000..db49724 --- /dev/null +++ b/frontend/src/Components/DeleteUser.tsx @@ -0,0 +1,34 @@ +import { User } from "../Types/goTypes"; +import { api, APIResponse } from "../API/API"; + +/** + * Use to remove a user from the system + * @param props - The username of user to remove + * @returns {boolean} True if removed, false if not + * @example + * const exampleUsername = "user"; + * DeleteUser({ usernameToDelete: exampleUsername }); + */ + +function DeleteUser(props: { usernameToDelete: string }): boolean { + //console.log(props.usernameToDelete); FOR DEBUG + let removed = false; + api + .removeUser( + props.usernameToDelete, + localStorage.getItem("accessToken") ?? "", + ) + .then((response: APIResponse) => { + if (response.success) { + removed = true; + } else { + console.error(response.message); + } + }) + .catch((error) => { + console.error("An error occurred during creation:", error); + }); + return removed; +} + +export default DeleteUser; From a0759b099af6bf9bcf96119b710347f2f1475092 Mon Sep 17 00:00:00 2001 From: Peter KW Date: Tue, 19 Mar 2024 00:17:29 +0100 Subject: [PATCH 04/10] Modul for viewing user info in admin manage users page --- frontend/src/Components/UserInfoModal.tsx | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 frontend/src/Components/UserInfoModal.tsx diff --git a/frontend/src/Components/UserInfoModal.tsx b/frontend/src/Components/UserInfoModal.tsx new file mode 100644 index 0000000..fff6776 --- /dev/null +++ b/frontend/src/Components/UserInfoModal.tsx @@ -0,0 +1,46 @@ +import Button from "./Button"; +import DeleteUser from "./DeleteUser"; +import UserProjectListAdmin from "./UserProjectListAdmin"; + +function UserInfoModal(props: { + isVisible: boolean; + username: string; + onClose: () => void; +}): JSX.Element { + if (!props.isVisible) return <>; + + return ( +
    +
    +

    {props.username}

    +
    +

    + Member of these projects: +

    + +
    +
    +
    +
    +
    + ); +} + +export default UserInfoModal; From 36524e5cbb3ab99dbd0df10d97f8f0c3ef03b808 Mon Sep 17 00:00:00 2001 From: Peter KW Date: Tue, 19 Mar 2024 00:25:37 +0100 Subject: [PATCH 05/10] Changed so that it makes a modal for each user instead of a link --- frontend/src/Components/UserListAdmin.tsx | 54 +++++++++++++++++------ 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/frontend/src/Components/UserListAdmin.tsx b/frontend/src/Components/UserListAdmin.tsx index b86076a..3d2bcae 100644 --- a/frontend/src/Components/UserListAdmin.tsx +++ b/frontend/src/Components/UserListAdmin.tsx @@ -1,5 +1,6 @@ -import { Link } from "react-router-dom"; +import { useState } from "react"; import { PublicUser } from "../Types/goTypes"; +import UserInfoModal from "./UserInfoModal"; /** * The props for the UserProps component @@ -9,27 +10,52 @@ interface UserProps { } /** - * A list of users for admin manage users page, that links admin to the right user page - * thanks to the state property - * @param props - The users to display + * A list of users for admin manage users page, that sets an onClick + * function for eact user
  • element, which displays a modul with + * user info. + * @param props - An array of users users to display * @returns {JSX.Element} The user list * @example - * const users = [{ id: 1, userName: "Random name" }]; + * const users = [{ id: 1, userName: "ExampleName" }]; * return ; */ export function UserListAdmin(props: UserProps): JSX.Element { + const [modalVisible, setModalVisible] = useState(false); + const [username, setUsername] = useState(""); + + const handleClick = (username: string): void => { + setUsername(username); + setModalVisible(true); + }; + + const handleClose = (): void => { + setUsername(""); + setModalVisible(false); + }; + return ( -
    -
      - {props.users.map((user) => ( - -
    • + <> + +
      +
        + {props.users.map((user) => ( +
      • { + handleClick(user.username); + }} + > {user.username}
      • - - ))} -
      -
      + ))} +
    +
    + ); } From d2ff2428cd6a08aa440c10a11b9507ea6231694a Mon Sep 17 00:00:00 2001 From: Peter KW Date: Tue, 19 Mar 2024 00:26:05 +0100 Subject: [PATCH 06/10] Some corrections --- frontend/src/Components/UserProjectListAdmin.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/Components/UserProjectListAdmin.tsx b/frontend/src/Components/UserProjectListAdmin.tsx index c4857db..e4bf58c 100644 --- a/frontend/src/Components/UserProjectListAdmin.tsx +++ b/frontend/src/Components/UserProjectListAdmin.tsx @@ -1,15 +1,15 @@ -import React, { useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import { api } from "../API/API"; import { Project } from "../Types/goTypes"; -const UserProjectListAdmin: React.FC = () => { +function UserProjectListAdmin(props: { username: string }): JSX.Element { const [projects, setProjects] = useState([]); useEffect(() => { const fetchProjects = async (): Promise => { try { const token = localStorage.getItem("accessToken") ?? ""; - const username = localStorage.getItem("username") ?? ""; + const username = props.username; const response = await api.getUserProjects(username, token); if (response.success) { @@ -23,7 +23,7 @@ const UserProjectListAdmin: React.FC = () => { }; void fetchProjects(); - }, []); + }); return (
    @@ -37,6 +37,6 @@ const UserProjectListAdmin: React.FC = () => {
    ); -}; +} export default UserProjectListAdmin; From d2a8399bde8029b6fbbc8550d69a35dd70e8b901 Mon Sep 17 00:00:00 2001 From: pavel Hamawand Date: Tue, 19 Mar 2024 00:34:57 +0100 Subject: [PATCH 07/10] minor fix --- frontend/src/Pages/AdminPages/AdminViewUserInfo.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/Pages/AdminPages/AdminViewUserInfo.tsx b/frontend/src/Pages/AdminPages/AdminViewUserInfo.tsx index fc678e2..5127571 100644 --- a/frontend/src/Pages/AdminPages/AdminViewUserInfo.tsx +++ b/frontend/src/Pages/AdminPages/AdminViewUserInfo.tsx @@ -6,7 +6,7 @@ import UserProjectListAdmin from "../../Components/UserProjectListAdmin"; function AdminViewUserInfo(): JSX.Element { const content = ( <> - + ); From c072aff9da1c1dfb03d4a2143891a5b94d5f87b0 Mon Sep 17 00:00:00 2001 From: pavel Hamawand Date: Tue, 19 Mar 2024 01:02:39 +0100 Subject: [PATCH 08/10] added change username button --- frontend/src/Components/AdminUserList.tsx | 0 frontend/src/Components/UserInfoModal.tsx | 10 ++++++++++ frontend/src/Pages/AdminPages/AdminViewUserInfo.tsx | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 frontend/src/Components/AdminUserList.tsx diff --git a/frontend/src/Components/AdminUserList.tsx b/frontend/src/Components/AdminUserList.tsx new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/Components/UserInfoModal.tsx b/frontend/src/Components/UserInfoModal.tsx index fff6776..21970fb 100644 --- a/frontend/src/Components/UserInfoModal.tsx +++ b/frontend/src/Components/UserInfoModal.tsx @@ -1,3 +1,4 @@ +import { Link } from "react-router-dom"; import Button from "./Button"; import DeleteUser from "./DeleteUser"; import UserProjectListAdmin from "./UserProjectListAdmin"; @@ -30,6 +31,15 @@ function UserInfoModal(props: { }} type="button" /> + +