Skip to content

Commit

Permalink
Merge pull request #373 from girder/new-project-contents-fix
Browse files Browse the repository at this point in the history
Update get_contents
  • Loading branch information
JakeWags authored Apr 16, 2024
2 parents c69bc2f + 587e81f commit 949be92
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
25 changes: 20 additions & 5 deletions shapeworks_cloud/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ class Dataset(TimeStampedModel, models.Model):
publications = models.TextField(blank=True, default='')

def get_contents(self):
ret = []
ret = [] # type: ignore

def truncate_filename(filename):
return filename.split('/')[-1]

def truncate_anatomy(anatomy_type):
return anatomy_type.replace('anatomy_', '')

group_list = [
Segmentation.objects.filter(subject__dataset=self),
Mesh.objects.filter(subject__dataset=self),
Expand All @@ -34,12 +37,24 @@ def truncate_filename(filename):

for shape_group in group_list:
for shape in shape_group:
ret.append(
{
if hasattr(shape, 'anatomy_type'):
anatomy = truncate_anatomy(shape.anatomy_type)
label = 'shape_'
else:
anatomy = shape.modality # type: ignore
label = 'image_'
if shape.subject.name in [s['name'] for s in ret]: # type: ignore
subject = next(
(s for s in ret if s['name'] == shape.subject.name), None # type: ignore
)
subject[label + anatomy] = truncate_filename(shape.file.name) # type: ignore
else:
subject = {
'name': shape.subject.name, # type: ignore
'shape_1': truncate_filename(shape.file.name), # type: ignore
label + anatomy: truncate_filename(shape.file.name), # type: ignore
}
)
ret.append(subject)

return ret


Expand Down
42 changes: 42 additions & 0 deletions shapeworks_cloud/core/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ def get_serializer_class(self):
else:
return serializers.ProjectSerializer

def edit_allowed(self, request, **kwargs):
project = self.get_object()
user = self.request.user
if project.readonly and not user.is_staff:
return False
return True

def create(self, request, **kwargs):
data = request.data
if 'creator' not in data:
Expand Down Expand Up @@ -283,6 +290,11 @@ def clone(self, request, **kwargs):
methods=['POST'],
)
def set_thumbnail(self, request, **kwargs):
if not self.edit_allowed(request, **kwargs):
return Response(
'Project is read only.',
status=status.HTTP_403_FORBIDDEN,
)
project = self.get_object()
form_data = request.data
encoded_thumbnail = form_data.get('encoding')
Expand Down Expand Up @@ -312,6 +324,11 @@ def download(self, request, **kwargs):
methods=['POST'],
)
def set_landmarks(self, request, **kwargs):
if not self.edit_allowed(request, **kwargs):
return Response(
'Project is read only.',
status=status.HTTP_403_FORBIDDEN,
)
project = self.get_object()
form_data = request.data
landmarks_info = form_data.get('info')
Expand Down Expand Up @@ -372,6 +389,11 @@ def set_landmarks(self, request, **kwargs):
methods=['POST'],
)
def set_constraints(self, request, **kwargs):
if not self.edit_allowed(request, **kwargs):
return Response(
'Project is read only.',
status=status.HTTP_403_FORBIDDEN,
)
project = self.get_object()
form_data = request.data
constraints_locations = form_data.get('locations')
Expand Down Expand Up @@ -411,6 +433,11 @@ def set_constraints(self, request, **kwargs):
methods=['POST'],
)
def groom(self, request, **kwargs):
if not self.edit_allowed(request, **kwargs):
return Response(
'Project is read only.',
status=status.HTTP_403_FORBIDDEN,
)
project = self.get_object()
form_data = request.data
form_data = {k: str(v) for k, v in form_data.items()}
Expand All @@ -437,6 +464,11 @@ def groom(self, request, **kwargs):
methods=['POST'],
)
def optimize(self, request, **kwargs):
if not self.edit_allowed(request, **kwargs):
return Response(
'Project is read only.',
status=status.HTTP_403_FORBIDDEN,
)
project = self.get_object()
form_data = request.data
form_data = {k: str(v) for k, v in form_data.items()}
Expand Down Expand Up @@ -475,6 +507,11 @@ def optimize(self, request, **kwargs):
methods=['POST'],
)
def analyze(self, request, **kwargs):
if not self.edit_allowed(request, **kwargs):
return Response(
'Project is read only.',
status=status.HTTP_403_FORBIDDEN,
)
project = self.get_object()

params = request.data
Expand Down Expand Up @@ -518,6 +555,11 @@ def analyze(self, request, **kwargs):
methods=['POST'],
)
def deepssm_run(self, request, **kwargs):
if not self.edit_allowed(request, **kwargs):
return Response(
'Project is read only.',
status=status.HTTP_403_FORBIDDEN,
)
project = self.get_object()
form_data = request.data
form_data = {k: str(v) for k, v in form_data.items()}
Expand Down
5 changes: 3 additions & 2 deletions web/shapeworks/src/components/Analysis/PCA.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ import { groupBy } from '../../helper';
pcaInfo,
animate,
menu,
showConfirmation
showConfirmation,
selectedProject,
};
},
};
Expand Down Expand Up @@ -230,7 +231,7 @@ import { groupBy } from '../../helper';
bottom
right
>
<template v-slot:activator="{ on, attrs }">
<template v-slot:activator="{ on, attrs }" v-if="selectedProject && !selectedProject.readonly">
<v-btn
dark
icon
Expand Down
3 changes: 2 additions & 1 deletion web/shapeworks/src/components/DeepSSM/DeepSSMTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export default {
});
return {
selectedProject,
openExpansionPanel,
controlsTabs,
prepData,
Expand Down Expand Up @@ -257,7 +258,7 @@ export default {
<div class="pa-3" v-else>
<div class="loading-dialog"><v-dialog v-model="deepSSMLoadingData" width="10%">Fetching results... <v-progress-circular indeterminate align-center></v-progress-circular></v-dialog></div>
<v-expansion-panels v-model="openExpansionPanel">
<v-expansion-panel>
<v-expansion-panel v-if="selectedProject && !selectedProject.readonly">
<v-expansion-panel-header>Controls</v-expansion-panel-header>
<v-expansion-panel-content>
<v-tabs v-model="controlsTabs">
Expand Down
9 changes: 8 additions & 1 deletion web/shapeworks/src/views/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,14 @@ export default {
</v-tab-item>
<v-tab href="#info">Info</v-tab>
<v-tab-item value="info">
<info-tab />
<span
v-if="selectedProject && selectedProject.readonly"
class="red--text pa-3"
>
This project is read only.
No operations may be performed.
</span>
<info-tab v-else />
</v-tab-item>
<v-tab href="#groom">Groom</v-tab>
<v-tab-item value="groom">
Expand Down

0 comments on commit 949be92

Please sign in to comment.