Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of Tasks to be created in one API Request #3386

Merged
merged 2 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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