Commit c5c9bfaa authored by Sondre Westby Liestøl's avatar Sondre Westby Liestøl
Browse files

Refactoring...

parent be71832f
Pipeline #170116 passed with stage
in 1 minute and 10 seconds
......@@ -19,3 +19,4 @@ class IsCommentVisibleToUser(permissions.BasePermission):
or (obj.workout.visibility == "CO" and obj.owner.coach == request.user)
or obj.workout.owner == request.user
)
\ No newline at end of file
......@@ -32,10 +32,11 @@ class CommentList(
def get_queryset(self):
workout_pk = self.kwargs.get("pk")
qs = Comment.objects.none()
user = self.request.user
if workout_pk:
qs = Comment.objects.filter(workout=workout_pk)
elif self.request.user:
elif user:
"""A comment should be visible to the requesting user if any of the following hold:
- The comment is on a public visibility workout
- The comment was written by the user
......@@ -46,6 +47,8 @@ class CommentList(
# We should replace it with a better solution.
# Or maybe not.
# qs = Comment.objects.filter(IsCommentVisibleToUser.has_object_permission(self, user, None, object)) check?
qs = Comment.objects.filter(
Q(workout__visibility="PU")
| Q(owner=self.request.user)
......
......@@ -10,7 +10,7 @@ from django.core.files.storage import FileSystemStorage
from django.conf import settings
from django.contrib.auth import get_user_model
#This should be removed as it is unused
class OverwriteStorage(FileSystemStorage):
"""Filesystem storage for overwriting files. Currently unused."""
......
......@@ -89,11 +89,12 @@ class RememberMe(
user, sign = pickle.loads(decode)
# Validate signature
if sign == self.sign_user(user):
if sign == sign_user(user):
return user
def rememberme(self):
creds = [self.request.user, self.sign_user(str(self.request.user))]
"""Remember the user"""
creds = [self.request.user, sign_user(str(self.request.user))]
return base64.b64encode(pickle.dumps(creds))
#Could be a function
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment