diff --git a/apps/hub-server/.env.example b/apps/hub-server/.env.example index 22d86d8a..da0e331a 100644 --- a/apps/hub-server/.env.example +++ b/apps/hub-server/.env.example @@ -1,7 +1,8 @@ HUB_SERVER_PORT=3003 -MOODLE_TOKEN=ac346f0324647b68488d13fd52a9bbe8 +MOODLE_API_TOKEN=ac346f0324647b68488d13fd52a9bbe8 NEXT_PUBLIC_HUB_URL=http://localhost:3000 MOODLE_URL=http://localhost:8081 +NEXT_PUBLIC_MOODLE_URL= MAIL_SERVER="asmtp.mail.hostpoint.ch" MAIL_USER="noreply@virtualairrescue.com" MAIL_PASSWORD="b7316PB8aDPCC%-&" diff --git a/apps/hub-server/modules/moodle.ts b/apps/hub-server/modules/moodle.ts index 1d44882c..e03837e0 100644 --- a/apps/hub-server/modules/moodle.ts +++ b/apps/hub-server/modules/moodle.ts @@ -4,8 +4,12 @@ export const getMoodleUserById = async (id: string) => { const { data: user } = await axios.get( `${process.env.NEXT_PUBLIC_MOODLE_URL}/webservice/rest/server.php`, { + auth: { + username: "moodleuser", + password: "Xo1SXaLYBa7Yb6WW", + }, params: { - wstoken: process.env.MOODLE_TOKEN, + wstoken: process.env.MOODLE_API_TOKEN, wsfunction: "core_user_get_users_by_field", moodlewsrestformat: "json", field: "idnumber", @@ -33,8 +37,12 @@ export const getMoodleQuizResult = async (userId: string, quizId: string) => { const { data: quizzes } = await axios.get( `${process.env.NEXT_PUBLIC_MOODLE_URL}/webservice/rest/server.php`, { + auth: { + username: "moodleuser", + password: "Xo1SXaLYBa7Yb6WW", + }, params: { - wstoken: process.env.MOODLE_TOKEN, + wstoken: process.env.MOODLE_API_TOKEN, wsfunction: "mod_quiz_get_user_attempts", moodlewsrestformat: "json", quizid: quizId, @@ -49,8 +57,12 @@ export const getMoodleCourseCompletionStatus = async (userId: string, courseId: const { data: completionStatus } = await axios.get( `${process.env.NEXT_PUBLIC_MOODLE_URL}/webservice/rest/server.php`, { + auth: { + username: "moodleuser", + password: "Xo1SXaLYBa7Yb6WW", + }, params: { - wstoken: process.env.MOODLE_TOKEN, + wstoken: process.env.MOODLE_API_TOKEN, wsfunction: "core_completion_get_course_completion_status", moodlewsrestformat: "json", userid: userId, diff --git a/apps/hub-server/routes/event.ts b/apps/hub-server/routes/event.ts index 53018cf3..58bfdc30 100644 --- a/apps/hub-server/routes/event.ts +++ b/apps/hub-server/routes/event.ts @@ -25,7 +25,6 @@ router.post("/handle-participant-finished", async (req, res) => { }, }, }); - console.log("Handeling Participant-completed", participant?.User.publicId); if (!participant) { res.status(404).json({ error: "Participant not found" }); return; @@ -62,11 +61,16 @@ router.post("/check-moodle-results", async (req, res) => { res.status(400).json({ error: "Teilnehmer hat keine Moodle-ID" }); return; } - const quizzResult = await getMoodleCourseCompletionStatus( + const courseStatus = await getMoodleCourseCompletionStatus( participant.User.moodleId.toString(), participant.Event.finisherMoodleCourseId!, ); - if (quizzResult?.completionstatus?.completed === true) { + + if (courseStatus?.completionstatus?.completed === true) { + prisma.participant.update({ + where: { id: participant.id }, + data: { finisherMoodleCurseCompleted: true }, + }); await handleParticipantFinished(participant.Event, participant, participant.User); res .status(200) diff --git a/apps/hub/.env.example b/apps/hub/.env.example index 1e71eee0..ad2d3c90 100644 --- a/apps/hub/.env.example +++ b/apps/hub/.env.example @@ -9,6 +9,6 @@ DISCORD_BOT_TOKEN= NEXT_PUBLIC_DISCORD_URL= DISCORD_REDIRECT= MOODLE_PW=var-api-user-P1 -MOODLE_TOKEN=ac346f0324647b68488d13fd52a9bbe8 +MOODLE_API_TOKEN=ac346f0324647b68488d13fd52a9bbe8 NEXT_PUBLIC_MOODLE_URL=http://localhost:8081 NEXT_PUBLIC_DISPATCH_URL=http://localhost:3001 \ No newline at end of file diff --git a/apps/hub/app/(app)/admin/event/_components/AppointmentModal.tsx b/apps/hub/app/(app)/admin/event/_components/AppointmentModal.tsx index 8e6d7817..f1c98b86 100644 --- a/apps/hub/app/(app)/admin/event/_components/AppointmentModal.tsx +++ b/apps/hub/app/(app)/admin/event/_components/AppointmentModal.tsx @@ -62,15 +62,6 @@ export const AppointmentModal = ({ timeCaption="Uhrzeit" showTimeCaption /> - {/* */}
{ - if (!participantForm.watch("id")) return; + try { + if (!participantForm.watch("id")) return; - const participant = participantForm.getValues(); - await handleParticipantFinished(participant.id.toString()).catch((e) => { - const error = e as AxiosError; + const participant = participantForm.getValues(); + await handleParticipantFinished(participant.id.toString()).catch((e) => { + const error = e as AxiosError; + }); + + toast.success("Workflow erfolgreich ausgeführt"); + router.refresh(); + } catch (error) { + const e = error as AxiosError; if ( - error.response?.data && - typeof error.response.data === "object" && - "error" in error.response.data + e.response?.data && + typeof e.response.data === "object" && + "error" in e.response.data ) { - toast.error(`Fehler: ${error.response.data.error}`); + toast.error(`Fehler: ${e.response.data.error}`); } else { toast.error("Unbekannter Fehler beim ausführen des Workflows"); } - }); - toast.success("Workflow erfolgreich ausgeführt"); - router.refresh(); + } }} > Event-abgeschlossen Workflow ausführen diff --git a/apps/hub/app/(app)/admin/user/[id]/_components/forms.tsx b/apps/hub/app/(app)/admin/user/[id]/_components/forms.tsx index 69768464..4cbd85f2 100644 --- a/apps/hub/app/(app)/admin/user/[id]/_components/forms.tsx +++ b/apps/hub/app/(app)/admin/user/[id]/_components/forms.tsx @@ -158,7 +158,7 @@ export const ProfileForm: React.FC = ({ user }: ProfileFormPro form={form} name="permissions" label="Permissions" - isDisabled={user.permissions.length > (session.data?.user?.permissions?.length ?? 0)} + isDisabled={!session.data?.user.permissions.includes("ADMIN_USER_ADVANCED")} options={Object.entries(PERMISSION).map(([key, value]) => ({ label: value, value: key, @@ -325,6 +325,7 @@ export const ConnectionHistory: React.FC<{ user: User }> = ({ user }: { user: Us export const UserPenalties = ({ user }: { user: User }) => { const createdUser = useSession().data?.user; const penaltyTable = useRef(null); + const session = useSession(); return (

@@ -353,25 +354,27 @@ export const UserPenalties = ({ user }: { user: User }) => { btnTip="Timeban hinzufügen" showDatePicker={true} /> - } - onClick={async ({ reason }) => { - if (!reason) return toast.error("Bitte gib einen Grund für die Strafe an."); - if (!createdUser) - return toast.error("Du musst eingeloggt sein, um eine Strafe zu erstellen."); - await addPenalty({ - reason, - type: "BAN", - userId: user.id, - createdUserId: createdUser.id, - }); - await editUser(user.id, { isBanned: true }); - penaltyTable.current?.refresh(); - toast.success("Ban wurde hinzugefügt!"); - }} - btnClassName="btn btn-outline btn-error tooltip-error" - btnTip="Rechte-entzug hinzufügen" - /> + {session.data?.user.permissions.includes("ADMIN_USER_ADVANCED") && ( + } + onClick={async ({ reason }) => { + if (!reason) return toast.error("Bitte gib einen Grund für die Strafe an."); + if (!createdUser) + return toast.error("Du musst eingeloggt sein, um eine Strafe zu erstellen."); + await addPenalty({ + reason, + type: "BAN", + userId: user.id, + createdUserId: createdUser.id, + }); + await editUser(user.id, { isBanned: true }); + penaltyTable.current?.refresh(); + toast.success("Ban wurde hinzugefügt!"); + }} + btnClassName="btn btn-outline btn-error tooltip-error" + btnTip="Nutzerkonto sperren" + /> + )}

)} - {user.isBanned && ( + {user.isBanned && session?.user.permissions.includes("ADMIN_USER_ADVANCED") && (