Skip to content

Commit

Permalink
limit number of tasks to be created in one api request (#3386)
Browse files Browse the repository at this point in the history
  • Loading branch information
fm3 authored Oct 25, 2018
1 parent 1144a22 commit 8dc903f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/controllers/TaskController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,20 @@ class TaskController @Inject() (annotationService: AnnotationService,


def create = sil.SecuredAction.async(validateJson[List[TaskParameters]]) { implicit request =>
createTasks(request.body.map { params =>
val tracing = annotationService.createTracingBase(params.dataSet, params.boundingBox, params.editPosition, params.editRotation)
(params, tracing)
})
for {
_ <- bool2Fox(request.body.length <= 1000) ?~> "task.create.limitExceeded"
result <- createTasks(request.body.map { params =>
val tracing = annotationService.createTracingBase(params.dataSet, params.boundingBox, params.editPosition, params.editRotation)
(params, tracing)
})
} yield result
}

def createFromFiles = sil.SecuredAction.async { implicit request =>
for {
body <- request.body.asMultipartFormData ?~> "binary.payload.invalid"
inputFiles = body.files.filter(file => file.filename.toLowerCase.endsWith(".nml") || file.filename.toLowerCase.endsWith(".zip"))
_ <- bool2Fox(inputFiles.length <= 1000) ?~> "task.create.limitExceeded"
_ <- bool2Fox(inputFiles.nonEmpty) ?~> "nml.file.notFound"
jsonString <- body.dataParts.get("formJSON").flatMap(_.headOption) ?~> "format.json.missing"
params <- JsonHelper.parseJsonToFox[NmlTaskParameters](jsonString) ?~> "task.create.failed"
Expand Down Expand Up @@ -263,7 +267,6 @@ class TaskController @Inject() (annotationService: AnnotationService,
}

def listTasks = sil.SecuredAction.async(parse.json) { implicit request =>

for {
userIdOpt <- Fox.runOptional((request.body \ "user").asOpt[String])(ObjectId.parse)
projectNameOpt = (request.body \ "project").asOpt[String]
Expand Down
1 change: 1 addition & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ annotation.makeHybrid.alreadyHybrid=Could not convert annotation to hybrid annot

task.create.success=Task successfully created
task.create.failed=Failed to create Task
task.create.limitExceeded=Cannot create more than 1000 tasks in one request.
task.finished=Task is finished
task.assigned=You got a new task
task.tooManyOpenOnes=You already have too many open tasks
Expand Down

0 comments on commit 8dc903f

Please sign in to comment.