Skip to content

Commit

Permalink
fix: fixed some weird shizzles
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV committed May 23, 2024
1 parent 591e7e8 commit cb634d3
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 55 deletions.
9 changes: 1 addition & 8 deletions backend/api/permissions/group_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,7 @@ def has_object_permission(self, request: Request, view: ViewSet, group) -> bool:
class GroupSubmissionPermission(BasePermission):
"""Permission class for submission related group endpoints"""

def has_permission(self, request: Request, view: APIView) -> bool:
"""Check if user has permission to view a general group submission endpoint."""
user = request.user

# Get the individual permission clauses.
return request.method in SAFE_METHODS or is_teacher(user) or is_assistant(user)

def had_object_permission(self, request: Request, view: ViewSet, group: Group) -> bool:
def had_object_permission(self, request: Request, _: ViewSet, group: Group) -> bool:
"""Check if user has permission to view a detailed group submission endpoint"""
user = request.user
course = group.project.course
Expand Down
42 changes: 21 additions & 21 deletions backend/api/views/group_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ def submissions(self, request, **_):
)
return Response(serializer.data)

@submissions.mapping.post
@submissions.mapping.put
@swagger_auto_schema(request_body=SubmissionSerializer)
def _add_submission(self, request: Request, **_):
"""Add a submission to the group"""
group: Group = self.get_object()

# Add submission to course
serializer = SubmissionSerializer(
data=request.data, context={"group": group, "request": request}
)

if serializer.is_valid(raise_exception=True):
serializer.save(group=group)

return Response({
"message": gettext("group.success.submissions.add"),
"submission": serializer.data
})

@students.mapping.post
@students.mapping.put
@swagger_auto_schema(request_body=StudentJoinGroupSerializer)
Expand Down Expand Up @@ -109,24 +129,4 @@ def _remove_student(self, request, **_):

return Response({
"message": gettext("group.success.students.remove"),
})

@submissions.mapping.post
@submissions.mapping.put
@swagger_auto_schema(request_body=SubmissionSerializer)
def _add_submission(self, request: Request, **_):
"""Add a submission to the group"""
group: Group = self.get_object()

# Add submission to course
serializer = SubmissionSerializer(
data=request.data, context={"group": group, "request": request}
)

if serializer.is_valid(raise_exception=True):
serializer.save(group=group)

return Response({
"message": gettext("group.success.submissions.add"),
"submission": serializer.data
})
})
7 changes: 6 additions & 1 deletion backend/api/views/user_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ def notifications(self, request: Request, pk: str):
)

# Get the notifications for the user
notifications = Notification.objects.filter(user=pk).order_by("-created_at")[:count]
notifications = Notification.objects.filter(user=pk, is_read=False).order_by("-created_at")

if 0 < notifications.count() < count:
notifications = list(notifications) + list(
Notification.objects.filter(user=pk, is_read=True).order_by("-created_at")[:count - notifications.count()]
)

# Serialize the notifications
serializer = NotificationSerializer(
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/assets/lang/app/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"new": "New",
"title": "Notifications",
"markAsRead": "Mark as read",
"loadMore": "Load more"
"loadMore": "Load more",
"noNotifications": "No notifications available"
}
},
"footer": {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/assets/lang/app/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"new": "Nieuw",
"title": "Notificaties",
"markAsRead": "Markeer alles als gelezen",
"loadMore": "Laad meer notificaties"
"loadMore": "Laad meer notificaties",
"noNotifications": "Geen notificaties"
}
},
"footer": {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/courses/CourseForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const form = ref(new Course());
const rules = computed(() => {
return {
name: { required: helpers.withMessage(t('validations.required'), required) },
faculty: { required: helpers.withMessage(t('validations.required'), required) },
faculty: { required: helpers.withMessage(t('validations.required'), (faculty: Faculty) => faculty.id !== '') },
excerpt: { required: helpers.withMessage(t('validations.required'), required) },
};
});
Expand Down
32 changes: 15 additions & 17 deletions frontend/src/components/notifications/NotificationsOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,21 @@ function toggleNotificationOverlay(event: Event): void {
<h3>{{ t('layout.header.notifications.title') }}</h3>
<Badge :value="notifications.length.toString()" />
</div>
<template v-if="notifications.length > 0">
<NotificationsScrollPanel :notifications="notifications" />
<div class="flex align-items-center gap-2 mt-4">
<Button
:label="t('layout.header.notifications.loadMore')"
@click="notificationCount += notificationCount"
link
/>
<Button
class="ml-auto"
:label="t('layout.header.notifications.markAsRead')"
:disabled="!hasUnreadNotifications"
@click="markNotificationsAsRead"
outlined
/>
</div>
</template>
<NotificationsScrollPanel :notifications="notifications" />
<div class="flex align-items-center gap-2 mt-4">
<Button
:label="t('layout.header.notifications.loadMore')"
@click="notificationCount += notificationCount"
link
/>
<Button
class="ml-auto"
:label="t('layout.header.notifications.markAsRead')"
:disabled="!hasUnreadNotifications"
@click="markNotificationsAsRead"
outlined
/>
</div>
</OverlayPanel>
</template>
</template>
Expand Down
19 changes: 14 additions & 5 deletions frontend/src/components/notifications/NotificationsScrollPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@
import ScrollPanel from 'primevue/scrollpanel';
import { type Notification } from '@/types/Notification.ts';
import NotificationCard from '@/components/notifications/NotificationCard.vue';
import { useI18n } from 'vue-i18n';
/* Props */
defineProps<{
notifications: Notification[];
}>();
/* Composable injections */
const { t } = useI18n();
</script>

<template>
<ScrollPanel class="border-1 border-200 p-2 h-25rem">
<!-- Notification list -->
<div class="flex flex-column gap-3">
<!-- Single notification -->
<NotificationCard
:notification="notification"
v-for="notification in notifications"
:key="notification.id"
/>
<template v-if="notifications.length > 0">
<NotificationCard
:notification="notification"
v-for="notification in notifications"
:key="notification.id"
/>
</template>
<template v-else>
{{ t('layout.header.notifications.noNotifications') }}
</template>
</div>
</ScrollPanel>
</template>
Expand Down

0 comments on commit cb634d3

Please sign in to comment.