Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/hooram/ownphotos into add-se…
Browse files Browse the repository at this point in the history
…parate-image-similarity-flask-server
  • Loading branch information
Hooram Nam committed Mar 27, 2019
2 parents 26a4b61 + 171ba50 commit 2577a32
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 12 additions & 1 deletion api/permissions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from rest_framework import permissions

from constance import config as site_config


class IsOwnerOrReadOnly(permissions.BasePermission):
"""
Expand Down Expand Up @@ -47,4 +49,13 @@ def has_object_permission(self, request, view, obj):
if request.user in album.shared_to.all():
return True

return False
return False


class IsRegistrationAllowed(permissions.BasePermission):
"""
Custom permission to only allow if registration is allowed globally.
"""

def has_permission(self, request, view):
return bool(site_config.ALLOW_REGISTRATION)
8 changes: 6 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from api.serializers_serpy import PhotoSuperSimpleSerializer as PhotoSuperSimpleSerializerSerpy
from api.serializers_serpy import PhotoSuperSimpleSerializerWithAddedOn as PhotoSuperSimpleSerializerWithAddedOnSerpy
from api.serializers_serpy import SharedPhotoSuperSimpleSerializer as SharedPhotoSuperSimpleSerializerSerpy
from api.permissions import IsOwnerOrReadOnly, IsUserOrReadOnly, IsPhotoOrAlbumSharedTo
from api.permissions import IsOwnerOrReadOnly, IsUserOrReadOnly, IsPhotoOrAlbumSharedTo, IsRegistrationAllowed

from api.face_classify import train_faces, cluster_faces
from api.social_graph import build_social_graph, build_ego_graph
Expand Down Expand Up @@ -1225,7 +1225,11 @@ def get_queryset(self):
return queryset

def get_permissions(self):
if self.request.method == 'GET' or self.request.method == 'POST':
if self.action == 'create':
self.permission_classes = (IsRegistrationAllowed, )
elif self.action == 'list':
self.permission_classes = (IsAdminUser, )
elif self.request.method == 'GET' or self.request.method == 'POST':
self.permission_classes = (AllowAny, )
else:
self.permission_classes = (IsUserOrReadOnly, )
Expand Down

0 comments on commit 2577a32

Please sign in to comment.