Skip to content

Commit 934f082

Browse files
authored
Merge pull request #645 from pierotofy/contours
Contours fix in iframes
2 parents a4ece26 + 26e5baa commit 934f082

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

app/api/tasks.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,23 @@ class TaskViewSet(viewsets.ViewSet):
7777
"""
7878
queryset = models.Task.objects.all().defer('orthophoto_extent', 'dsm_extent', 'dtm_extent', 'console_output', )
7979

80-
# We don't use object level permissions on tasks, relying on
81-
# project's object permissions instead (but standard model permissions still apply)
82-
permission_classes = (permissions.DjangoModelPermissions, )
8380
parser_classes = (parsers.MultiPartParser, parsers.JSONParser, parsers.FormParser, )
8481
ordering_fields = '__all__'
8582

83+
def get_permissions(self):
84+
"""
85+
Instantiates and returns the list of permissions that this view requires.
86+
We don't use object level permissions on tasks, relying on
87+
project's object permissions instead (but standard model permissions still apply)
88+
and with the exception of 'retrieve' (task GET) for public tasks access
89+
"""
90+
if self.action == 'retrieve':
91+
permission_classes = [permissions.AllowAny]
92+
else:
93+
permission_classes = [permissions.DjangoModelPermissions, ]
94+
95+
return [permission() for permission in permission_classes]
96+
8697
def set_pending_action(self, pending_action, request, pk=None, project_pk=None, perms=('change_project', )):
8798
get_and_check_project(request, project_pk, perms)
8899
try:
@@ -128,7 +139,6 @@ def output(self, request, pk=None, project_pk=None):
128139
output = task.console_output or ""
129140
return Response('\n'.join(output.rstrip().split('\n')[line_num:]))
130141

131-
132142
def list(self, request, project_pk=None):
133143
get_and_check_project(request, project_pk)
134144
tasks = self.queryset.filter(project=project_pk)
@@ -137,12 +147,14 @@ def list(self, request, project_pk=None):
137147
return Response(serializer.data)
138148

139149
def retrieve(self, request, pk=None, project_pk=None):
140-
get_and_check_project(request, project_pk)
141150
try:
142151
task = self.queryset.get(pk=pk, project=project_pk)
143152
except (ObjectDoesNotExist, ValidationError):
144153
raise exceptions.NotFound()
145154

155+
if not task.public:
156+
get_and_check_project(request, task.project.id)
157+
146158
serializer = TaskSerializer(task)
147159
return Response(serializer.data)
148160

app/api/urls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from app.api.presets import PresetViewSet
44
from app.plugins import get_api_url_patterns
5-
from webodm import settings
65
from .projects import ProjectViewSet
76
from .tasks import TaskViewSet, TaskTiles, TaskTilesJson, TaskDownloads, TaskAssets, TaskAssetsImport
87
from .processingnodes import ProcessingNodeViewSet, ProcessingNodeOptionsView

app/tests/test_api_task.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ def accessResources(expectedStatus):
371371
res = other_client.get("/api/projects/{}/tasks/{}/{}/tiles/16/16020/42443.png".format(project.id, task.id, tile_type))
372372
self.assertTrue(res.status_code == expectedStatus)
373373

374+
res = other_client.get("/api/projects/{}/tasks/{}/".format(project.id, task.id))
375+
self.assertTrue(res.status_code == expectedStatus)
376+
374377
accessResources(status.HTTP_404_NOT_FOUND)
375378

376379
# Original owner enables sharing
@@ -382,16 +385,18 @@ def accessResources(expectedStatus):
382385
# Now other user can acccess resources
383386
accessResources(status.HTTP_200_OK)
384387

388+
# He cannot change a task
389+
res = other_client.patch("/api/projects/{}/tasks/{}/".format(project.id, task.id), {
390+
'name': "Changed! Uh oh"
391+
})
392+
self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND)
393+
385394
# User logs out
386395
other_client.logout()
387396

388397
# He can still access the resources as anonymous
389398
accessResources(status.HTTP_200_OK)
390399

391-
# Other user still does not have access to certain parts of the API
392-
res = other_client.get("/api/projects/{}/tasks/{}/".format(project.id, task.id))
393-
self.assertTrue(res.status_code == status.HTTP_403_FORBIDDEN)
394-
395400
# Restart a task
396401
testWatch.clear()
397402
res = client.post("/api/projects/{}/tasks/{}/restart/".format(project.id, task.id))

plugins/contours/public/ContoursPanel.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default class ContoursPanel extends React.Component {
5656
}
5757
})
5858
.fail(() => {
59-
this.setState({permanentError: `Cannot retrieve information for task ${id}. Are you are connected to the internet.`})
59+
this.setState({permanentError: `Cannot retrieve information for task ${id}. Are you are connected to the internet?`})
6060
})
6161
.always(() => {
6262
this.setState({loading: false});

0 commit comments

Comments
 (0)