Skip to content

Commit

Permalink
fix query set
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 20, 2024
1 parent 4df195b commit 9abc2e7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name = "pypi"
# 5. Run `pipenv install --dev` in your terminal.

[packages]
codeforlife = {ref = "v0.18.12", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
codeforlife = {ref = "portal-frontend-52", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
# 🚫 Don't add [packages] below that are inherited from the CFL package.
pyjwt = "==2.6.0" # TODO: upgrade to latest version
# TODO: Needed by RR. Remove when RR has moved to new system.
Expand All @@ -32,7 +32,7 @@ django-sekizai = "==2.0.0"
django-classy-tags = "==2.0.0"

[dev-packages]
codeforlife = {ref = "v0.18.12", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]}
codeforlife = {ref = "portal-frontend-52", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]}
# codeforlife = {file = "../codeforlife-package-python", editable = true, extras = ["dev"]}
# 🚫 Don't add [dev-packages] below that are inherited from the CFL package.

Expand Down
14 changes: 7 additions & 7 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/api/views/klass.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ def get_serializer_class(self):

return ReadClassSerializer

def get_queryset(self):
if self.action in ["retrieve", "list"]:
return super().get_queryset()

Check warning on line 42 in src/api/views/klass.py

View check run for this annotation

Codecov / codecov/patch

src/api/views/klass.py#L42

Added line #L42 was not covered by tests

teacher = self.request.school_teacher_user.teacher
return (
teacher.classes
if teacher.is_admin
else teacher.classes.filter(teacher=teacher)
)

def destroy(self, request, *args, **kwargs):
klass = self.get_object()

Expand Down
11 changes: 2 additions & 9 deletions src/api/views/klass_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def test_get_permissions__destroy(self):
def test_get_permissions__list(self):
"""Only admin-teachers and class-teachers can list classes."""
self.assert_get_permissions(
permissions=[
OR(IsTeacher(is_admin=True), IsTeacher(in_class=True))
],
permissions=[IsTeacher(in_school=True)],
action="list",
)

Expand All @@ -96,12 +94,7 @@ def test_get_permissions__retrieve(self):
Only students, admin-teachers or class-teachers can retrieve a class.
"""
self.assert_get_permissions(
permissions=[
OR(
IsStudent(),
OR(IsTeacher(is_admin=True), IsTeacher(in_class=True)),
)
],
permissions=[OR(IsStudent(), IsTeacher(in_school=True))],
action="retrieve",
)

Expand Down

0 comments on commit 9abc2e7

Please sign in to comment.