Skip to content

Commit

Permalink
* Seeing if this helps.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgroff committed Jul 17, 2018
1 parent c82f36a commit a80c6d8
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ jobs:
# 'See docs on artifact collection here https://circleci.com/docs/2.0/artifacts/'
- run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
# This is based on your 1.0 configuration file or project settings
- run:
working_directory: ~/bgroff/kala-app/django_kala
command: if ["3.5.2" == "system"] || pyenv versions --bare | grep -x -q '3.5.2'; then pyenv global version;else pyenv install --skip-existing 3.5.2 && pyenv global version && pyenv rehash && pip install virtualenv && pip install nose && pip install pep8 && pyenv rehash;fi
#- run:
# working_directory: ~/bgroff/kala-app/django_kala
# command: if ["3.5.2" == "system"] || pyenv versions --bare | grep -x -q '3.5.2'; then pyenv global version;else pyenv install --skip-existing 3.5.2 && pyenv global version && pyenv rehash && pip install virtualenv && pip install nose && pip install pep8 && pyenv rehash;fi
# Dependencies
# This would typically go in either a build or a build-and-test job when using workflows
# Restore the dependency cache
Expand Down
2 changes: 1 addition & 1 deletion django_kala/api/basecamp_classic/people/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _xml_convert(self, element):
data['avatar_url'] = str(field.text)

if field.tag == 'administrator':
data['is_admin'] = bool(distutils.util.strtobool(field.text))
data['is_superuser'] = bool(distutils.util.strtobool(field.text))
if field.tag == 'deleted':
data['is_active'] = not(bool(distutils.util.strtobool(field.text)))
if field.tag == 'has-access-to-new-projects':
Expand Down
6 changes: 6 additions & 0 deletions django_kala/api/v1/projects/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
name='document',
view=DocumentView.as_view()
),

path(
'projects/<int:pk>/permissions/',
name='project_permissions',
view=ProjectPermissionsView.as_view()
),
#
# path(
# 'projects/<int:project_pk>/documents/<int:document_pk>/settings',
Expand Down
57 changes: 57 additions & 0 deletions django_kala/api/v1/projects/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext as _
from rest_framework.generics import ListCreateAPIView
from rest_framework.mixins import UpdateModelMixin
from rest_framework.response import Response
from rest_framework import status
from rest_framework.views import APIView

from api.v1.serializers.permission_serializer import PermissionsSerializer
from auth.models import Permissions
from projects.models import Project


class ProjectsView(APIView):
pass
Expand All @@ -16,3 +27,49 @@ class DocumentsView(APIView):
class DocumentView(APIView):
pass


class ProjectPermissionsView(ListCreateAPIView, UpdateModelMixin):
serializer_class = PermissionsSerializer
queryset = Permissions.objects.all().select_related('permission').prefetch_related('permission')

def dispatch(self, request, pk, *args, **kwargs):
self.project = get_object_or_404(Project.objects.active(), pk=pk)
if not Permissions.has_perms(
[
'change_project',
'add_project',
'delete_project'
], request.user, self.project.uuid) and not Permissions.has_perms([
'change_organization',
'add_organization',
'delete_organization'
], request.user, self.project.organization.uuid) and not self.project.document_set.filter(
uuid__in=Permissions.objects.filter(
permission__codename__in=[
'change_document',
'add_document',
'delete_document'
], user=request.user).values_list('object_uuid', flat=True)).exists():
raise PermissionDenied(
_('You do not have permission to view this project.')
)
return super(ProjectPermissionsView, self).dispatch(request, *args, **kwargs)

def list(self, request, *args, **kwargs):
permissions = self.queryset.filter(object_uuid=self.project.uuid)
serializer = self.serializer_class(permissions, many=True)
return Response(serializer.data)

def create(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data, many=True)
if serializer.is_valid():
serializer.save()
raise Response("Bad data", status=status.HTTP_400_BAD_REQUEST)





class DocumentPermissionsView(APIView):
pass

28 changes: 28 additions & 0 deletions django_kala/api/v1/serializers/permission_serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from rest_framework import serializers

from auth.models import Permissions

User = get_user_model()


class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'email', 'first_name', 'last_name')


class PermissionSerializer(serializers.ModelSerializer):
class Meta:
model = Permission
fields = ('id', 'name')


class PermissionsSerializer(serializers.ModelSerializer):
user = UserSerializer()
permission = PermissionSerializer()

class Meta:
model = Permissions
fields = ('user', 'permission', 'object_uuid')

0 comments on commit a80c6d8

Please sign in to comment.