Skip to content

Commit

Permalink
🚑 Fix POST response/applet/activity route (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
shnizzedy authored Nov 25, 2019
2 parents 6fb76cb + 397aa54 commit 29d9f33
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Changes
-------
Unreleased
==========
2019-11-25: v0.6.6
^^^^^^^^^^^^^^^^^^
* :ambulance: Fix `POST response/applet/activity` route

2019-11-25: v0.6.5
^^^^^^^^^^^^^^^^^^
* :pencil: Allow invitations for roles other than "user"
Expand Down
50 changes: 26 additions & 24 deletions girderformindlogger/api/v1/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,16 @@ def getLast7Days(
.errorResponse()
.errorResponse('Write access was denied on the parent folder.', 403)
)
def createResponseItem(self, applet, activity, metadata, subject_id, pending, params):
def createResponseItem(
self,
applet,
activity,
metadata,
subject_id,
pending,
params
):
from girderformindlogger.models.profile import Profile
try:
from girderformindlogger.utility.response import aggregateAndSave
# TODO: pending
Expand All @@ -348,26 +357,17 @@ def createResponseItem(self, applet, activity, metadata, subject_id, pending, pa
informant['_id']
)

# subject_id = [
# getUserCipher(
# appletAssignment=assignment,
# user=subject_id
# ) for assignment in appletAssignments
# ][0]
try:
subject_info = Folder().load(
id=subject_id,
user=informant,
level=AccessType.READ
)
except AccessException:
subject_info = {}

metadata['subject'] = subject_info.get('meta', {}) if isinstance(
subject_info,
dict
) else {}
metadata['subject']['@id'] = subject_id
subject_id = Profile().createProfile(
applet,
subject_id
).get('_id')

print(subject_id)

if isinstance(metadata.get('subject'), dict):
metadata['subject']['@id'] = subject_id
else:
metadata['subject'] = {'@id': subject_id}
now = datetime.now(tzlocal.get_localzone())
appletName=AppletModel().preferredName(applet)
UserResponsesFolder = ResponseFolderModel().load(
Expand All @@ -380,12 +380,13 @@ def createResponseItem(self, applet, activity, metadata, subject_id, pending, pa
name=appletName, reuseExisting=True, public=False)
AppletSubjectResponsesFolder = Folder().createFolder(
parent=UserAppletResponsesFolder, parentType='folder',
name=subject_id, reuseExisting=True, public=False)
name=str(subject_id), reuseExisting=True, public=False)

try:
newItem = self._model.createResponseItem(
folder=AppletSubjectResponsesFolder,
name=now.strftime("%Y-%m-%d-%H-%M-%S-%Z"), creator=informant,
name=now.strftime("%Y-%m-%d-%H-%M-%S-%Z"),
creator=informant,
description="{} response on {} at {}".format(
Folder().preferredName(activity),
now.strftime("%Y-%m-%d"),
Expand Down Expand Up @@ -419,6 +420,7 @@ def createResponseItem(self, applet, activity, metadata, subject_id, pending, pa
if metadata:
newItem = self._model.setMetadata(newItem, metadata)

print(metadata)
if not pending:
# create a Thread to calculate and save aggregates

Expand All @@ -428,7 +430,7 @@ def createResponseItem(self, applet, activity, metadata, subject_id, pending, pa
# agg.start()
aggregateAndSave(newItem, informant)
newItem['readOnly'] = True

print(newItem)
return(newItem)
except:
import sys, traceback
Expand Down
11 changes: 9 additions & 2 deletions girderformindlogger/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,19 @@ def smartImport(IRI, user=None, refreshCache=False, modelType=None):
from girderformindlogger.utility.jsonld_expander import reprolibCanonize

MODELS = MODELS()

model, modelType = MODELS['screen']().getFromUrl(
mt1 = "screen" if modelType is None else modelType
model, modelType = MODELS[mt1]().getFromUrl(
IRI,
user=user,
refreshCache=refreshCache
)
if mt1!=modelType:
MODELS[mt1]().remove(model)
model, modelType = MODELS[modelType]().getFromUrl(
IRI,
user=user,
refreshCache=refreshCache
)
return((
modelType,
model,
Expand Down
14 changes: 14 additions & 0 deletions girderformindlogger/models/applet.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ def formatThenUpdate(self, applet, user):
)
self.updateUserCacheAllRoles(user)

def getResponseData(self, appletId, reviewer, filter={}):
"""
Function to collect response data available to given reviewer.
:param appletId: ID of applet for which to get response data
:type appletId: ObjectId or str
:param reviewer: Reviewer making request
:type reviewer: dict
:param filter: reduction criteria (not yet implemented)
:type filter: dict
:reutrns: TBD
"""
pass

def updateRelationship(self, applet, relationship):
"""
:param applet: Applet to update
Expand Down

0 comments on commit 29d9f33

Please sign in to comment.