Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #243

Merged
merged 13 commits into from
May 22, 2024
6 changes: 5 additions & 1 deletion backend/src/group/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from src.subject.utils import has_subject_privileges

from . import service
from .exceptions import AlreadyInGroup, GroupNotFound, MaxCapacity
from .exceptions import AlreadyInGroup, AlreadyInGroupOfProject, GroupNotFound, MaxCapacity


async def retrieve_group(
Expand Down Expand Up @@ -79,5 +79,9 @@ async def join_group(
if len(group.members) >= project.capacity:
raise MaxCapacity()

groups = await retrieve_groups_by_user(user, db)
if any([group.project_id == g.project_id for g in groups]):
raise AlreadyInGroupOfProject()

await service.join_group(db, group_id, uid)
return await service.get_group_by_id(db, group_id)
6 changes: 6 additions & 0 deletions backend/src/group/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ class MaxCapacity(HTTPException):
def __init__(self):
"""Raised when user wants to join group at max capacity"""
super().__init__(status_code=403, detail="Group at max capacity")


class AlreadyInGroupOfProject(HTTPException):
def __init__(self):
"""Raised when person is already in another group of the project"""
super().__init__(status_code=403, detail="Already in a Group for this project")
4 changes: 4 additions & 0 deletions backend/src/subject/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ async def create_subject_instructor(
):
if await service.is_instructor(db, subject_id, user.uid):
raise AlreadyInstructor()
if await service.is_student(db, subject_id, user.uid):
raise AlreadyRegistered()
await service.add_instructor_to_subject(db, subject_id, user.uid)


Expand Down Expand Up @@ -129,6 +131,8 @@ async def add_student_to_subject(
user: User = Depends(retrieve_user),
db: AsyncSession = Depends(get_async_db)
) -> Subject:
if await service.is_instructor(db, subject.id, user.uid):
raise AlreadyInstructor()
if await service.is_student(db, subject.id, user.uid):
raise AlreadyRegistered()
await service.create_subject_student(db, subject.id, user.uid)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/subject/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def is_instructor(db: AsyncSession, subject_id: int, uid: str) -> bool:

async def create_subject(db: AsyncSession, subject: SubjectCreate) -> Subject:
db_subject = Subject(
name=subject.name, academic_year=subject.academic_year)
name=subject.name, academic_year=subject.academic_year, email=subject.email)
db.add(db_subject)
await db.commit()
await db.refresh(db_subject)
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/components/form_elements/FilesInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ function onAddFilesClick() {
}

function updateFiles(event: Event) {
// todo: check of meerdere identieke filenames aanwezig zijn
const files = (event.target as HTMLInputElement).files!;
inputFiles.value.push(...files);
const unique_files = Array.from(files).filter(
(file) => !inputFiles.value.map((file) => file.name).includes(file.name)
);
inputFiles.value.push(...unique_files);
}

function onDeleteClick(index: number) {
Expand Down
48 changes: 25 additions & 23 deletions frontend/src/components/groups/GroupCard.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
<template>
<v-card class="groupcard" variant="flat">
<v-row>
<v-col cols="7">
<StudentsDialog
:students="group.members"
:title="$t('project.group', { number: group.num })"
/>
<v-btn v-if="isTeacher" variant="flat" @click="toGroupPage">
{{ $t("group.to_grouppage") }}
</v-btn>
</v-col>
<v-col cols="2">
{{ amountOfMembers + "/" + project.capacity }}
</v-col>
<v-col cols="3">
<GroupButtons
:amountOfMembers="amountOfMembers"
:group="group"
:project="project"
:user="user"
:isTeacher="isTeacher"
/>
</v-col>
</v-row>
<v-container>
<v-row>
<v-col cols="7">
<StudentsDialog
:students="group.members"
:title="$t('project.group', { number: group.num })"
/>
<v-btn v-if="isTeacher" variant="flat" @click="toGroupPage">
{{ $t("group.to_grouppage") }}
</v-btn>
</v-col>
<v-col cols="2">
{{ amountOfMembers + "/" + project.capacity }}
</v-col>
<v-col cols="3">
<GroupButtons
:amountOfMembers="amountOfMembers"
:group="group"
:project="project"
:user="user"
:isTeacher="isTeacher"
/>
</v-col>
</v-row>
</v-container>
</v-card>
</template>

Expand Down
11 changes: 4 additions & 7 deletions frontend/src/components/home/listcontent/DeadlineItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="projectbtn" @click="navigateToProject">
<router-link class="projectbtn" :to="`/project/${project.id}`">
<div :class="submissionToClass(latestSubmissionStatus)"></div>
<div class="leftcontent">
<h3>{{ project.name }}</h3>
Expand All @@ -8,12 +8,11 @@
<div class="rightcontent">
{{ $d(project.deadline, "short") }}
</div>
</div>
</router-link>
</template>

<script setup lang="ts">
import { computed, toRefs } from "vue";
import router from "@/router";
import type Project from "@/models/Project";
import type Submission from "@/models/Submission";
import { Status } from "@/models/Submission";
Expand Down Expand Up @@ -44,10 +43,6 @@ function submissionToClass(submission: Submission | null) {
none: !submission,
};
}

const navigateToProject = () => {
router.push(`/project/${project.value.id}`);
};
</script>

<style scoped>
Expand All @@ -60,6 +55,8 @@ const navigateToProject = () => {
cursor: pointer;
height: 65px;
border-radius: 2px;
text-decoration: none;
color: inherit;
}

.projectbtn:hover {
Expand Down
11 changes: 4 additions & 7 deletions frontend/src/components/home/listcontent/SubjectItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="coursebtn" @click="navigateToCourse">
<router-link class="coursebtn" :to="`/subjects/${subject.id}`">
<div>
<h3>{{ subject.name }}</h3>
<v-skeleton-loader v-if="isInstructorsLoading" type="text" />
Expand All @@ -8,12 +8,11 @@
</p>
</div>
<v-icon class="chevron" icon="mdi-chevron-right" />
</div>
</router-link>
</template>

<script setup lang="ts">
import type Subject from "@/models/Subject";
import router from "@/router";
import { toRefs, computed } from "vue";
import { useSubjectInstructorsQuery } from "@/queries/Subject";

Expand All @@ -34,10 +33,6 @@ const sortedInstructors = computed(() => {
return b.is_teacher - a.is_teacher;
});
});

const navigateToCourse = () => {
router.push(`/subjects/${subject.value.id}`);
};
</script>

<style scoped>
Expand All @@ -51,6 +46,8 @@ const navigateToCourse = () => {
cursor: pointer;
background-color: rgb(var(--v-theme-background));
border-radius: 2px;
text-decoration: none;
color: inherit;
}

.coursebtn:hover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
v-model="activeAcademicYear"
variant="outlined"
:items="academicYearItems"
:item-title="(item) => `20${item}-20${item + 1}`"
:item-title="(item) => `${item}-${item + 1}`"
:item-value="(item) => item"
:label="$t('subject.academy_year')"
required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
</div>
<v-card-text>
<v-chip color="secondary" variant="flat" label class="academyyear">
{{
`${$t("subject.academy_year")} 20${academicYear}-20${academicYear + 1}`
}}
{{ `${$t("subject.academy_year")} ${academicYear}-${academicYear + 1}` }}
</v-chip>
<v-row class="instr-container">
<v-chip
Expand Down
140 changes: 72 additions & 68 deletions frontend/src/components/submission/SubmissionCard.vue
Original file line number Diff line number Diff line change
@@ -1,76 +1,80 @@
<template>
<v-divider />
<v-card variant="flat">
<v-card-title>
{{ $t("submission.status") }}
<p v-if="new Date(submission.date) <= deadline" :class="Status[submission.status]">
{{ Status[submission.status] }}
</p>
<p v-else class="Deadline">{{ $t("submission.after_deadline") }}</p>
</v-card-title>
<v-card-subtitle>
{{ $t("submission.datetime") }} {{ $d(submission.date, "long") }}
</v-card-subtitle>
<v-card-item>
<div>
<v-divider />
<v-card variant="flat">
<v-card-title>
{{ $t("submission.remarks") }}
</v-card-title>
<v-card-text v-if="submission.remarks">
{{ submission.remarks }}
</v-card-text>
<v-card-subtitle v-else>
{{ $t("submission.remarks_empty") }}
</v-card-subtitle>
</v-card-item>
<v-card-item v-if="submission.stderr || submission.stdout || submission.testresults.length">
<v-card-title>{{ $t("submission.docker_test") }}</v-card-title>
<v-card-text>
<p v-if="submission.stdout">Stdout: {{ submission.stdout }}</p>
<p v-if="submission.stderr">Sterr: {{ submission.stderr }}</p>
<ul>
<li v-for="result in submission.testresults" :key="result">
<p v-if="result.succeeded" class="text-green">{{ result.value }}</p>
<p v-else class="text-red">{{ result.value }}</p>
</li>
</ul>
</v-card-text>
</v-card-item>
<v-card-item>
<v-card-title>
{{ $t("submission.files") }}
{{ $t("submission.status") }}
<p v-if="new Date(submission.date) <= deadline" :class="Status[submission.status]">
{{ Status[submission.status] }}
</p>
<p v-else class="Deadline">{{ $t("submission.after_deadline") }}</p>
</v-card-title>
<v-card-subtitle>
{{ $t("submission.download_info") }}
{{ $t("submission.datetime") }} {{ $d(submission.date, "long") }}
</v-card-subtitle>
<v-container>
<v-alert
v-if="isError"
title="Error"
color="error"
:text="error!.message"
></v-alert>
<v-skeleton-loader v-else :loading="isLoading" type="card">
<v-col>
<v-chip
class="ma-2"
v-for="(item, index) in files"
label
color="blue"
:key="item.filesortedname"
@click="() => downloadFile(index)"
>
{{ item.filename }}
</v-chip>
</v-col>
</v-skeleton-loader>
</v-container>
<v-card-actions>
<v-btn @click="downloadAll">
{{ $t("submission.download_all_files") }}
</v-btn>
</v-card-actions>
</v-card-item>
</v-card>
<v-card-item>
<v-card-title>
{{ $t("submission.remarks") }}
</v-card-title>
<v-card-text v-if="submission.remarks">
{{ submission.remarks }}
</v-card-text>
<v-card-subtitle v-else>
{{ $t("submission.remarks_empty") }}
</v-card-subtitle>
</v-card-item>
<v-card-item
v-if="submission.stderr || submission.stdout || submission.testresults.length"
>
<v-card-title>{{ $t("submission.docker_test") }}</v-card-title>
<v-card-text>
<p v-if="submission.stdout">Stdout: {{ submission.stdout }}</p>
<p v-if="submission.stderr">Sterr: {{ submission.stderr }}</p>
<ul>
<li v-for="result in submission.testresults" :key="result">
<p v-if="result.succeeded" class="text-green">{{ result.value }}</p>
<p v-else class="text-red">{{ result.value }}</p>
</li>
</ul>
</v-card-text>
</v-card-item>
<v-card-item>
<v-card-title>
{{ $t("submission.files") }}
</v-card-title>
<v-card-subtitle>
{{ $t("submission.download_info") }}
</v-card-subtitle>
<v-container>
<v-alert
v-if="isError"
title="Error"
color="error"
:text="error!.message"
></v-alert>
<v-skeleton-loader v-else :loading="isLoading" type="card">
<v-col>
<v-chip
class="ma-2"
v-for="(item, index) in files"
label
color="blue"
:key="item.filesortedname"
@click="() => downloadFile(index)"
>
{{ item.filename }}
</v-chip>
</v-col>
</v-skeleton-loader>
</v-container>
<v-card-actions>
<v-btn @click="downloadAll">
{{ $t("submission.download_all_files") }}
</v-btn>
</v-card-actions>
</v-card-item>
</v-card>
</div>
</template>

<script setup lang="ts">
Expand Down
Loading
Loading