Merged in bugfix/VBV-769-expert-feedback-view (pull request #419)
Fix index, check if expert is in session and circle Approved-by: Elia Bieri
This commit is contained in:
commit
bc55b1b660
|
|
@ -10,7 +10,7 @@ import { Popover, PopoverButton, PopoverPanel } from "@headlessui/vue";
|
||||||
|
|
||||||
<PopoverPanel>
|
<PopoverPanel>
|
||||||
<div
|
<div
|
||||||
class="absolute right-0 z-10 mt-2 bg-white px-4 py-4 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none lg:right-2"
|
class="absolute right-0 z-30 mt-2 bg-white px-4 py-4 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none lg:right-2"
|
||||||
>
|
>
|
||||||
<!-- To close the popover withing your content, use the 'PopoverButton'
|
<!-- To close the popover withing your content, use the 'PopoverButton'
|
||||||
https://headlessui.com/vue/popover#closing-popovers-manually
|
https://headlessui.com/vue/popover#closing-popovers-manually
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ const removeNoScroll = () => {
|
||||||
<div
|
<div
|
||||||
v-if="show"
|
v-if="show"
|
||||||
data-cy="full-screen-modal"
|
data-cy="full-screen-modal"
|
||||||
class="fixed top-0 h-full w-full overflow-y-scroll bg-white px-4 py-16 lg:px-16 lg:py-24"
|
class="fixed top-0 z-20 h-full w-full overflow-y-scroll bg-white px-4 py-16 lg:px-16 lg:py-24"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,15 @@ class FeedbackRestApiTestCase(FeedbackBaseTestCase):
|
||||||
response.data[0], {"circle_id": self.circle_basis.id, "count": 3}
|
response.data[0], {"circle_id": self.circle_basis.id, "count": 3}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_detail_trainer_from_other_session_cannot_fetch_feedback(self):
|
||||||
|
trainer2 = User.objects.get(email="test-trainer2@example.com")
|
||||||
|
self.client.force_login(trainer2)
|
||||||
|
response = self.client.get(
|
||||||
|
f"/api/core/feedback/{self.course_session.id}/{self.circle_basis.id}/"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
def test_detail_student_cannot_fetch_feedback(self):
|
def test_detail_student_cannot_fetch_feedback(self):
|
||||||
self.client.force_login(self.student)
|
self.client.force_login(self.student)
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,10 @@ from rest_framework.response import Response
|
||||||
|
|
||||||
from vbv_lernwelt.feedback.models import FeedbackResponse
|
from vbv_lernwelt.feedback.models import FeedbackResponse
|
||||||
from vbv_lernwelt.feedback.utils import feedback_users
|
from vbv_lernwelt.feedback.utils import feedback_users
|
||||||
from vbv_lernwelt.iam.permissions import is_course_session_expert
|
from vbv_lernwelt.iam.permissions import (
|
||||||
|
is_circle_expert_by_circle_id,
|
||||||
|
is_course_session_expert,
|
||||||
|
)
|
||||||
|
|
||||||
logger = structlog.get_logger(__name__)
|
logger = structlog.get_logger(__name__)
|
||||||
|
|
||||||
|
|
@ -51,7 +54,9 @@ def get_expert_feedbacks_for_course(request, course_session_id):
|
||||||
|
|
||||||
@api_view(["GET"])
|
@api_view(["GET"])
|
||||||
def get_feedback_for_circle(request, course_session_id, circle_id):
|
def get_feedback_for_circle(request, course_session_id, circle_id):
|
||||||
if not is_course_session_expert(request.user, course_session_id):
|
if not is_circle_expert_by_circle_id(
|
||||||
|
request.user, course_session_id, circle_id, check_supervisor=True
|
||||||
|
):
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
|
|
||||||
feedbacks = FeedbackResponse.objects.filter(
|
feedbacks = FeedbackResponse.objects.filter(
|
||||||
|
|
|
||||||
|
|
@ -248,13 +248,31 @@ def is_circle_expert(user, course_session_id: int, learning_sequence_id: int) ->
|
||||||
|
|
||||||
circle_id = learning_sequence.get_parent().circle.id
|
circle_id = learning_sequence.get_parent().circle.id
|
||||||
|
|
||||||
return CourseSessionUser.objects.filter(
|
return is_circle_expert_by_circle_id(user, course_session_id, circle_id)
|
||||||
|
|
||||||
|
|
||||||
|
def is_circle_expert_by_circle_id(
|
||||||
|
user, course_session_id: int, circle_id: int, check_supervisor=False
|
||||||
|
) -> bool:
|
||||||
|
if user.is_superuser:
|
||||||
|
return True
|
||||||
|
|
||||||
|
is_supervisor = (
|
||||||
|
check_supervisor
|
||||||
|
and CourseSessionGroup.objects.filter(
|
||||||
|
supervisor=user, course_session__id=course_session_id
|
||||||
|
).exists()
|
||||||
|
)
|
||||||
|
|
||||||
|
is_expert = CourseSessionUser.objects.filter(
|
||||||
course_session_id=course_session_id,
|
course_session_id=course_session_id,
|
||||||
user=user,
|
user=user,
|
||||||
role=CourseSessionUser.Role.EXPERT,
|
role=CourseSessionUser.Role.EXPERT,
|
||||||
expert__id=circle_id,
|
expert__id=circle_id,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
|
return is_supervisor or is_expert
|
||||||
|
|
||||||
|
|
||||||
def can_view_course_session_group_statistics(
|
def can_view_course_session_group_statistics(
|
||||||
user: User, group: CourseSessionGroup
|
user: User, group: CourseSessionGroup
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue