@@ -67,7 +67,7 @@ class AnnotationController @Inject()(
67
67
def info ( // Type of the annotation, one of Task, Explorational, CompoundTask, CompoundProject, CompoundTaskType
68
68
typ : String ,
69
69
// For Task and Explorational annotations, id is an annotation id. For CompoundTask, id is a task id. For CompoundProject, id is a project id. For CompoundTaskType, id is a task type id
70
- id : String ,
70
+ id : ObjectId ,
71
71
// Timestamp in milliseconds (time at which the request is sent)
72
72
timestamp : Option [Long ]): Action [AnyContent ] = sil.UserAwareAction .async { implicit request =>
73
73
log() {
@@ -99,7 +99,7 @@ class AnnotationController @Inject()(
99
99
}
100
100
}
101
101
102
- def infoWithoutType (id : String ,
102
+ def infoWithoutType (id : ObjectId ,
103
103
// Timestamp in milliseconds (time at which the request is sent)
104
104
timestamp : Option [Long ]): Action [AnyContent ] = sil.UserAwareAction .async { implicit request =>
105
105
log() {
@@ -111,7 +111,7 @@ class AnnotationController @Inject()(
111
111
}
112
112
}
113
113
114
- def merge (typ : String , id : String , mergedTyp : String , mergedId : String ): Action [AnyContent ] =
114
+ def merge (typ : String , id : ObjectId , mergedTyp : String , mergedId : ObjectId ): Action [AnyContent ] =
115
115
sil.SecuredAction .async { implicit request =>
116
116
for {
117
117
annotationA <- provider.provideAnnotation(typ, id, request.identity) ?~> " annotation.notFound" ~> NOT_FOUND
@@ -124,15 +124,15 @@ class AnnotationController @Inject()(
124
124
} yield JsonOk (js, Messages (" annotation.merge.success" ))
125
125
}
126
126
127
- def mergeWithoutType (id : String , mergedTyp : String , mergedId : String ): Action [AnyContent ] =
127
+ def mergeWithoutType (id : ObjectId , mergedTyp : String , mergedId : ObjectId ): Action [AnyContent ] =
128
128
sil.SecuredAction .async { implicit request =>
129
129
for {
130
130
annotation <- provider.provideAnnotation(id, request.identity) ?~> " annotation.notFound" ~> NOT_FOUND
131
131
result <- merge(annotation.typ.toString, id, mergedTyp, mergedId)(request)
132
132
} yield result
133
133
}
134
134
135
- def reset (typ : String , id : String ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
135
+ def reset (typ : String , id : ObjectId ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
136
136
for {
137
137
annotation <- provider.provideAnnotation(typ, id, request.identity) ?~> " annotation.notFound" ~> NOT_FOUND
138
138
_ <- Fox .assertTrue(userService.isTeamManagerOrAdminOf(request.identity, annotation._team))
@@ -142,7 +142,7 @@ class AnnotationController @Inject()(
142
142
} yield JsonOk (json, Messages (" annotation.reset.success" ))
143
143
}
144
144
145
- def reopen (typ : String , id : String ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
145
+ def reopen (typ : String , id : ObjectId ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
146
146
def isReopenAllowed (user : User , annotation : Annotation ) =
147
147
for {
148
148
isAdminOrTeamManager <- userService.isTeamManagerOrAdminOf(user, annotation._team)
@@ -162,8 +162,8 @@ class AnnotationController @Inject()(
162
162
} yield JsonOk (json, Messages (" annotation.reopened" ))
163
163
}
164
164
165
- def editLockedState (typ : String , id : String , isLockedByOwner : Boolean ): Action [AnyContent ] = sil. SecuredAction .async {
166
- implicit request =>
165
+ def editLockedState (typ : String , id : ObjectId , isLockedByOwner : Boolean ): Action [AnyContent ] =
166
+ sil. SecuredAction .async { implicit request =>
167
167
for {
168
168
annotation <- provider.provideAnnotation(typ, id, request.identity)
169
169
_ <- bool2Fox(annotation._user == request.identity._id) ?~> " annotation.isLockedByOwner.notAllowed"
@@ -174,13 +174,12 @@ class AnnotationController @Inject()(
174
174
updatedAnnotation <- provider.provideAnnotation(typ, id, request.identity) ~> NOT_FOUND
175
175
json <- annotationService.publicWrites(updatedAnnotation, Some (request.identity)) ?~> " annotation.write.failed"
176
176
} yield JsonOk (json, Messages (" annotation.isLockedByOwner.success" ))
177
- }
177
+ }
178
178
179
- def createExplorational (datasetId : String ): Action [List [AnnotationLayerParameters ]] =
179
+ def createExplorational (datasetId : ObjectId ): Action [List [AnnotationLayerParameters ]] =
180
180
sil.SecuredAction .async(validateJson[List [AnnotationLayerParameters ]]) { implicit request =>
181
181
for {
182
- datasetIdValidated <- ObjectId .fromString(datasetId)
183
- dataset <- datasetDAO.findOne(datasetIdValidated) ?~> Messages (" dataset.notFound" , datasetIdValidated) ~> NOT_FOUND
182
+ dataset <- datasetDAO.findOne(datasetId) ?~> Messages (" dataset.notFound" , datasetId) ~> NOT_FOUND
184
183
annotation <- annotationService.createExplorationalFor(
185
184
request.identity,
186
185
dataset._id,
@@ -192,12 +191,11 @@ class AnnotationController @Inject()(
192
191
} yield JsonOk (json)
193
192
}
194
193
195
- def getSandbox (datasetId : String , typ : String , sharingToken : Option [String ]): Action [AnyContent ] =
194
+ def getSandbox (datasetId : ObjectId , typ : String , sharingToken : Option [String ]): Action [AnyContent ] =
196
195
sil.UserAwareAction .async { implicit request =>
197
196
val ctx = URLSharing .fallbackTokenAccessContext(sharingToken) // users with dataset sharing token may also get a sandbox annotation
198
197
for {
199
- datasetIdValidated <- ObjectId .fromString(datasetId)
200
- dataset <- datasetDAO.findOne(datasetIdValidated)(ctx) ?~> Messages (" dataset.notFound" , datasetIdValidated) ~> NOT_FOUND
198
+ dataset <- datasetDAO.findOne(datasetId)(ctx) ?~> Messages (" dataset.notFound" , datasetId) ~> NOT_FOUND
201
199
tracingType <- TracingType .fromString(typ).toFox
202
200
_ <- bool2Fox(tracingType == TracingType .skeleton) ?~> " annotation.sandbox.skeletonOnly"
203
201
annotation = Annotation (
@@ -216,7 +214,7 @@ class AnnotationController @Inject()(
216
214
} yield JsonOk (json)
217
215
}
218
216
219
- private def finishAnnotation (typ : String , id : String , issuingUser : User , timestamp : Instant )(
217
+ private def finishAnnotation (typ : String , id : ObjectId , issuingUser : User , timestamp : Instant )(
220
218
implicit ctx : DBAccessContext ): Fox [(Annotation , String )] =
221
219
for {
222
220
annotation <- provider.provideAnnotation(typ, id, issuingUser) ~> NOT_FOUND
@@ -226,7 +224,7 @@ class AnnotationController @Inject()(
226
224
_ <- timeSpanService.logUserInteractionIfTheyArePotentialContributor(timestamp, issuingUser, annotation) // log time on tracing end
227
225
} yield (updated, message)
228
226
229
- def finish (typ : String , id : String , timestamp : Long ): Action [AnyContent ] = sil.SecuredAction .async {
227
+ def finish (typ : String , id : ObjectId , timestamp : Long ): Action [AnyContent ] = sil.SecuredAction .async {
230
228
implicit request =>
231
229
log() {
232
230
for {
@@ -242,7 +240,10 @@ class AnnotationController @Inject()(
242
240
log() {
243
241
withJsonAs[JsArray ](request.body \ " annotations" ) { annotationIds =>
244
242
val results = Fox .serialSequence(annotationIds.value.toList) { jsValue =>
245
- jsValue.asOpt[String ].toFox.flatMap(id => finishAnnotation(typ, id, request.identity, Instant (timestamp)))
243
+ jsValue
244
+ .asOpt[String ]
245
+ .toFox
246
+ .flatMap(id => finishAnnotation(typ, ObjectId (id), request.identity, Instant (timestamp)))
246
247
}
247
248
248
249
results.map { _ =>
@@ -252,7 +253,7 @@ class AnnotationController @Inject()(
252
253
}
253
254
}
254
255
255
- def editAnnotation (typ : String , id : String ): Action [JsValue ] = sil.SecuredAction .async(parse.json) {
256
+ def editAnnotation (typ : String , id : ObjectId ): Action [JsValue ] = sil.SecuredAction .async(parse.json) {
256
257
implicit request =>
257
258
for {
258
259
annotation <- provider.provideAnnotation(typ, id, request.identity) ~> NOT_FOUND
@@ -276,7 +277,7 @@ class AnnotationController @Inject()(
276
277
} yield JsonOk (Messages (" annotation.edit.success" ))
277
278
}
278
279
279
- def editAnnotationLayer (typ : String , id : String , tracingId : String ): Action [JsValue ] =
280
+ def editAnnotationLayer (typ : String , id : ObjectId , tracingId : String ): Action [JsValue ] =
280
281
sil.SecuredAction .async(parse.json) { implicit request =>
281
282
for {
282
283
annotation <- provider.provideAnnotation(typ, id, request.identity) ~> NOT_FOUND
@@ -287,19 +288,18 @@ class AnnotationController @Inject()(
287
288
} yield JsonOk (Messages (" annotation.edit.success" ))
288
289
}
289
290
290
- def annotationsForTask (taskId : String ): Action [AnyContent ] =
291
+ def annotationsForTask (taskId : ObjectId ): Action [AnyContent ] =
291
292
sil.SecuredAction .async { implicit request =>
292
293
for {
293
- taskIdValidated <- ObjectId .fromString(taskId)
294
- task <- taskDAO.findOne(taskIdValidated) ?~> " task.notFound" ~> NOT_FOUND
294
+ task <- taskDAO.findOne(taskId) ?~> " task.notFound" ~> NOT_FOUND
295
295
project <- projectDAO.findOne(task._project)
296
296
_ <- Fox .assertTrue(userService.isTeamManagerOrAdminOf(request.identity, project._team))
297
297
annotations <- annotationService.annotationsFor(task._id) ?~> " task.annotation.failed"
298
298
jsons <- Fox .serialSequence(annotations)(a => annotationService.publicWrites(a, Some (request.identity)))
299
299
} yield Ok (JsArray (jsons.flatten))
300
300
}
301
301
302
- def cancel (typ : String , id : String ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
302
+ def cancel (typ : String , id : ObjectId ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
303
303
def tryToCancel (annotation : Annotation ) =
304
304
annotation match {
305
305
case t if t.typ == AnnotationType .Task =>
@@ -319,14 +319,14 @@ class AnnotationController @Inject()(
319
319
} yield result
320
320
}
321
321
322
- def cancelWithoutType (id : String ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
322
+ def cancelWithoutType (id : ObjectId ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
323
323
for {
324
324
annotation <- provider.provideAnnotation(id, request.identity) ~> NOT_FOUND
325
325
result <- cancel(annotation.typ.toString, id)(request)
326
326
} yield result
327
327
}
328
328
329
- def transfer (typ : String , id : String ): Action [JsValue ] = sil.SecuredAction .async(parse.json) { implicit request =>
329
+ def transfer (typ : String , id : ObjectId ): Action [JsValue ] = sil.SecuredAction .async(parse.json) { implicit request =>
330
330
for {
331
331
restrictions <- provider.restrictionsFor(typ, id) ?~> " restrictions.notFound" ~> NOT_FOUND
332
332
_ <- restrictions.allowFinish(request.identity) ?~> " notAllowed" ~> FORBIDDEN
@@ -337,7 +337,7 @@ class AnnotationController @Inject()(
337
337
} yield JsonOk (json)
338
338
}
339
339
340
- def duplicate (typ : String , id : String ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
340
+ def duplicate (typ : String , id : ObjectId ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
341
341
for {
342
342
annotation <- provider.provideAnnotation(typ, id, request.identity) ~> NOT_FOUND
343
343
newAnnotation <- duplicateAnnotation(annotation, request.identity) ?~> " annotation.duplicate.failed"
@@ -376,7 +376,7 @@ class AnnotationController @Inject()(
376
376
377
377
}
378
378
379
- def getSharedTeams (typ : String , id : String ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
379
+ def getSharedTeams (typ : String , id : ObjectId ): Action [AnyContent ] = sil.SecuredAction .async { implicit request =>
380
380
for {
381
381
annotation <- provider.provideAnnotation(typ, id, request.identity)
382
382
_ <- bool2Fox(annotation._user == request.identity._id) ?~> " notAllowed" ~> FORBIDDEN
@@ -385,7 +385,7 @@ class AnnotationController @Inject()(
385
385
} yield Ok (Json .toJson(json))
386
386
}
387
387
388
- def updateSharedTeams (typ : String , id : String ): Action [JsValue ] = sil.SecuredAction .async(parse.json) {
388
+ def updateSharedTeams (typ : String , id : ObjectId ): Action [JsValue ] = sil.SecuredAction .async(parse.json) {
389
389
implicit request =>
390
390
withJsonBodyAs[List [String ]] { teams =>
391
391
for {
@@ -399,7 +399,7 @@ class AnnotationController @Inject()(
399
399
}
400
400
}
401
401
402
- def updateOthersMayEdit (typ : String , id : String , othersMayEdit : Boolean ): Action [AnyContent ] =
402
+ def updateOthersMayEdit (typ : String , id : ObjectId , othersMayEdit : Boolean ): Action [AnyContent ] =
403
403
sil.SecuredAction .async { implicit request =>
404
404
for {
405
405
annotation <- provider.provideAnnotation(typ, id, request.identity)
@@ -438,14 +438,13 @@ class AnnotationController @Inject()(
438
438
_ <- annotationDAO.insertOne(clonedAnnotation)
439
439
} yield clonedAnnotation
440
440
441
- def tryAcquiringAnnotationMutex (id : String ): Action [AnyContent ] =
441
+ def tryAcquiringAnnotationMutex (id : ObjectId ): Action [AnyContent ] =
442
442
sil.SecuredAction .async { implicit request =>
443
443
logTime(slackNotificationService.noticeSlowRequest, durationThreshold = 1 second) {
444
444
for {
445
- idValidated <- ObjectId .fromString(id)
446
445
annotation <- provider.provideAnnotation(id, request.identity) ~> NOT_FOUND
447
446
_ <- bool2Fox(annotation.othersMayEdit) ?~> " notAllowed" ~> FORBIDDEN
448
- restrictions <- provider.restrictionsFor(AnnotationIdentifier (annotation.typ, idValidated )) ?~> " restrictions.notFound" ~> NOT_FOUND
447
+ restrictions <- provider.restrictionsFor(AnnotationIdentifier (annotation.typ, id )) ?~> " restrictions.notFound" ~> NOT_FOUND
449
448
_ <- restrictions.allowUpdate(request.identity) ?~> " notAllowed" ~> FORBIDDEN
450
449
mutexResult <- annotationMutexService.tryAcquiringAnnotationMutex(annotation._id, request.identity._id) ?~> " annotation.mutex.failed"
451
450
resultJson <- annotationMutexService.publicWrites(mutexResult)
0 commit comments