Skip to content

Commit

Permalink
Additional patch for CE
Browse files Browse the repository at this point in the history
Merge branch 'developer' of http://git.vst.lan/cloud/polemarch
  • Loading branch information
onegreyonewhite committed Dec 14, 2017
2 parents 14779d3 + 8b1ed81 commit 789a28e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 5 additions & 2 deletions polemarch/api/v1/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pylint: disable=unused-argument,protected-access,too-many-ancestors
from collections import OrderedDict
from django.core.exceptions import PermissionDenied
from django.db import transaction
from django.http import HttpResponse
from rest_framework import exceptions as excepts, views as rest_views
Expand Down Expand Up @@ -206,7 +207,6 @@ def types(self, request):


class BulkViewSet(rest_views.APIView):
permission_classes = (StaffPermission,)
serializer_classes = serializers

_op_types = {
Expand All @@ -232,7 +232,10 @@ def get_serializer(self, *args, **kwargs):
def get_object(self, item, pk):
serializer_class = self.get_serializer_class(item)
model = serializer_class.Meta.model
return model.objects.get(pk=pk)
obj = model.objects.get(pk=pk)
if not obj.editable_by(self.request.user):
raise PermissionDenied("You don't have permission to this object.")
return obj

def perform_create(self, item, data):
serializer = self.get_serializer(data=data, item=item)
Expand Down
9 changes: 4 additions & 5 deletions polemarch/main/models/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ class AbstractVarsQuerySet(ACLQuerySet):

@transaction.atomic
def create(self, **kwargs):
variables = kwargs.pop("vars", None)
variables = kwargs.pop("vars", {})
obj = super(AbstractVarsQuerySet, self).create(**kwargs)
if variables is not None:
if isinstance(variables, (string_types, text_type)):
variables = json.loads(variables)
obj.vars = variables
if isinstance(variables, (string_types, text_type)):
variables = json.loads(variables)
obj.vars = variables
return obj

def var_filter(self, **kwargs):
Expand Down

0 comments on commit 789a28e

Please sign in to comment.