Skip to content

Commit

Permalink
Fix downloaded zip names (#4330)
Browse files Browse the repository at this point in the history
* set file name parameter in play sendFile method

* update changelog
  • Loading branch information
youri-k authored Nov 28, 2019
1 parent b54d8ca commit 180cffa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
### Fixed
- Fixed broken sorting in the dataset table of the dashboard. [#4318](https://github.com/scalableminds/webknossos/pull/4318)
- Fixed annotation access to match the text in the modal. [#4314](https://github.com/scalableminds/webknossos/pull/4314)
- Fixed the name of downloaded annotation zips. [#4330](https://github.com/scalableminds/webknossos/pull/4330)


## [19.11.0](https://github.com/scalableminds/webknossos/releases/tag/19.11.0) - 2019-10-28
Expand Down
20 changes: 10 additions & 10 deletions app/controllers/AnnotationIOController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import akka.util.ByteString
import com.mohiva.play.silhouette.api.Silhouette
import com.scalableminds.util.accesscontext.{DBAccessContext, GlobalAccessContext}
import com.scalableminds.util.io.{NamedEnumeratorStream, ZipIO}
import com.scalableminds.util.tools.{Fox, FoxImplicits}
import com.scalableminds.util.tools.{Fox, FoxImplicits, TextUtils}
import com.scalableminds.webknossos.datastore.models.datasource.{AbstractSegmentationLayer, SegmentationLayer}
import com.scalableminds.webknossos.tracingstore.SkeletonTracing.{SkeletonTracing, SkeletonTracingOpt, SkeletonTracings}
import com.scalableminds.webknossos.tracingstore.VolumeTracing.VolumeTracing
Expand Down Expand Up @@ -301,18 +301,18 @@ class AnnotationIOController @Inject()(nmlWriter: NmlWriter,
project <- projectDAO.findOne(projectIdValidated) ?~> Messages("project.notFound", projectId) ~> NOT_FOUND
_ <- Fox.assertTrue(userService.isTeamManagerOrAdminOf(user, project._team)) ?~> "notAllowed" ~> FORBIDDEN
annotations <- annotationDAO.findAllFinishedForProject(projectIdValidated)
zip <- annotationService.zipAnnotations(annotations, project.name + "_nmls.zip", skipVolumeData)
zip <- annotationService.zipAnnotations(annotations, project.name, skipVolumeData)
} yield {
val file = new File(zip.path.toString)
Ok.sendFile(file, inline = false)
Ok.sendFile(file, inline = false, fileName = _ => TextUtils.normalize(project.name + "_nmls.zip"))
}

private def downloadTask(taskId: String, user: User, skipVolumeData: Boolean)(implicit ctx: DBAccessContext,
m: MessagesProvider) = {
def createTaskZip(task: Task): Fox[TemporaryFile] = annotationService.annotationsFor(task._id).flatMap {
annotations =>
val finished = annotations.filter(_.state == Finished)
annotationService.zipAnnotations(finished, task._id.toString + "_nmls.zip", skipVolumeData)
annotationService.zipAnnotations(finished, task._id.toString, skipVolumeData)
}

for {
Expand All @@ -322,7 +322,7 @@ class AnnotationIOController @Inject()(nmlWriter: NmlWriter,
zip <- createTaskZip(task)
} yield {
val file = new File(zip.path.toString)
Ok.sendFile(file, inline = false)
Ok.sendFile(file, inline = false, fileName = _ => TextUtils.normalize(task._id.toString + "_nmls.zip"))
}
}

Expand All @@ -336,17 +336,17 @@ class AnnotationIOController @Inject()(nmlWriter: NmlWriter,
.map(_.flatten)
.toFox
finishedAnnotations = annotations.filter(_.state == Finished)
zip <- annotationService.zipAnnotations(finishedAnnotations, taskType.summary + "_nmls.zip", skipVolumeData)
zip <- annotationService.zipAnnotations(finishedAnnotations, taskType.summary, skipVolumeData)
} yield zip

for {
taskTypeIdValidated <- ObjectId.parse(taskTypeId) ?~> "taskType.id.invalid"
tasktype <- taskTypeDAO.findOne(taskTypeIdValidated) ?~> "taskType.notFound" ~> NOT_FOUND
_ <- Fox.assertTrue(userService.isTeamManagerOrAdminOf(user, tasktype._team)) ?~> "notAllowed" ~> FORBIDDEN
zip <- createTaskTypeZip(tasktype)
taskType <- taskTypeDAO.findOne(taskTypeIdValidated) ?~> "taskType.notFound" ~> NOT_FOUND
_ <- Fox.assertTrue(userService.isTeamManagerOrAdminOf(user, taskType._team)) ?~> "notAllowed" ~> FORBIDDEN
zip <- createTaskTypeZip(taskType)
} yield {
val file = new File(zip.path.toString)
Ok.sendFile(file, inline = false)
Ok.sendFile(file, inline = false, fileName = _ => TextUtils.normalize(taskType.summary + "_nmls.zip"))
}
}
}

0 comments on commit 180cffa

Please sign in to comment.