Skip to content

Commit

Permalink
Fix type error on view
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasdeluna committed Feb 24, 2024
1 parent 8a24356 commit cdd26f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lego/apps/forums/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def has_perm(
return False

def has_object_permissions(self, user, perm, obj):
return perm != DELETE and perm != EDIT
return not (perm == DELETE or perm == EDIT)


class ThreadPermissionHandler(PermissionHandler):
Expand All @@ -66,6 +66,8 @@ def has_perm(

# Check object permissions before keywork perms
if obj is not None:
if perm == DELETE:
return False

Check warning on line 70 in lego/apps/forums/permissions.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/forums/permissions.py#L70

Added line #L70 was not covered by tests
if self.has_object_permissions(user, perm, obj):
return True

Expand All @@ -85,8 +87,10 @@ def has_perm(
return False

Check warning on line 87 in lego/apps/forums/permissions.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/forums/permissions.py#L87

Added line #L87 was not covered by tests

def has_object_permissions(self, user, perm, obj):
if perm == DELETE:
return False

Check warning on line 91 in lego/apps/forums/permissions.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/forums/permissions.py#L91

Added line #L91 was not covered by tests
if perm == EDIT and obj.created_by == user:
return True

Check warning on line 93 in lego/apps/forums/permissions.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/forums/permissions.py#L93

Added line #L93 was not covered by tests
if perm == CREATE:
return True

Check warning on line 95 in lego/apps/forums/permissions.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/forums/permissions.py#L95

Added line #L95 was not covered by tests
return perm != DELETE and perm != EDIT
return not (perm == DELETE or perm == EDIT)
1 change: 1 addition & 0 deletions lego/apps/forums/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def get_serializer_class(self):
return PublicForumSerializer
if self.request and self.request.user.is_authenticated:
return DetailedAdminForumSerializer
return super().get_serializer_class()

def get_object(self) -> Forum:
queryset = self.get_queryset()
Expand Down
2 changes: 2 additions & 0 deletions lego/apps/tags/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def test_fetch_detail(self):
"quote": 0,
"joblisting": 0,
"poll": 0,
"forum": 0,
"thread": 0,
},
},
)
Expand Down

0 comments on commit cdd26f1

Please sign in to comment.