|
8 | 8 |
|
9 | 9 | from django.contrib.auth.models import AnonymousUser |
10 | 10 | from django.contrib.auth.models import User |
| 11 | +from django.http import Http404 |
11 | 12 | from django.utils import timezone |
12 | 13 | from guardian.shortcuts import assign_perm |
13 | 14 | from guardian.shortcuts import get_objects_for_user |
@@ -324,14 +325,17 @@ def pre_save(self, obj): |
324 | 325 |
|
325 | 326 | def get_queryset(self, **kwargs): |
326 | 327 | app = get_object_or_404(models.App, id=self.kwargs['id']) |
| 328 | + try: |
| 329 | + self.check_object_permissions(self.request, app) |
| 330 | + except PermissionDenied: |
| 331 | + raise Http404("No {} matches the given query.".format( |
| 332 | + self.model._meta.object_name)) |
327 | 333 | return self.model.objects.filter(app=app) |
328 | 334 |
|
329 | 335 | def get_object(self, *args, **kwargs): |
330 | 336 | obj = self.get_queryset().latest('created') |
331 | | - user = self.request.user |
332 | | - if user == obj.app.owner or user in get_users_with_perms(obj.app): |
333 | | - return obj |
334 | | - raise PermissionDenied() |
| 337 | + self.check_object_permissions(self.request, obj) |
| 338 | + return obj |
335 | 339 |
|
336 | 340 |
|
337 | 341 | class AppBuildViewSet(BaseAppViewSet): |
@@ -368,10 +372,12 @@ class AppConfigViewSet(BaseAppViewSet): |
368 | 372 | def get_object(self, *args, **kwargs): |
369 | 373 | """Return the Config associated with the App's latest Release.""" |
370 | 374 | app = get_object_or_404(models.App, id=self.kwargs['id']) |
371 | | - user = self.request.user |
372 | | - if user == app.owner or user in get_users_with_perms(app): |
| 375 | + try: |
| 376 | + self.check_object_permissions(self.request, app) |
373 | 377 | return app.release_set.latest().config |
374 | | - raise PermissionDenied() |
| 378 | + except (PermissionDenied, models.Release.DoesNotExist): |
| 379 | + raise Http404("No {} matches the given query.".format( |
| 380 | + self.model._meta.object_name)) |
375 | 381 |
|
376 | 382 | def post_save(self, config, created=False): |
377 | 383 | if created: |
@@ -409,7 +415,12 @@ class AppLimitViewSet(BaseAppViewSet): |
409 | 415 | def get_object(self, *args, **kwargs): |
410 | 416 | """Return the Limit associated with the App's latest Release.""" |
411 | 417 | app = get_object_or_404(models.App, id=self.kwargs['id']) |
412 | | - return app.release_set.latest().config.limit |
| 418 | + try: |
| 419 | + self.check_object_permissions(self.request, app) |
| 420 | + return app.release_set.latest().config.limit |
| 421 | + except (PermissionDenied, models.Release.DoesNotExist): |
| 422 | + raise Http404("No {} matches the given query.".format( |
| 423 | + self.model._meta.object_name)) |
413 | 424 |
|
414 | 425 | def post_save(self, limit, created=False): |
415 | 426 | if created: |
@@ -481,15 +492,14 @@ def rollback(self, request, *args, **kwargs): |
481 | 492 | return Response(response, status=status.HTTP_201_CREATED) |
482 | 493 |
|
483 | 494 |
|
484 | | -class AppContainerViewSet(OwnerViewSet): |
| 495 | +class AppContainerViewSet(BaseAppViewSet): |
485 | 496 | """RESTful views for :class:`~api.models.Container`.""" |
486 | 497 |
|
487 | 498 | model = models.Container |
488 | 499 | serializer_class = serializers.ContainerSerializer |
489 | 500 |
|
490 | 501 | def get_queryset(self, **kwargs): |
491 | | - app = get_object_or_404(models.App, id=self.kwargs['id']) |
492 | | - qs = self.model.objects.filter(app=app) |
| 502 | + qs = super(AppContainerViewSet, self).get_queryset(**kwargs) |
493 | 503 | container_type = self.kwargs.get('type') |
494 | 504 | if container_type: |
495 | 505 | qs = qs.filter(type=container_type) |
|
0 commit comments