in app/controllers/FaciaToolController.scala [166:245]
def treatEdits(collectionId: String) = AccessAPIAuthAction.async {
implicit request =>
val collectionPriorities =
collectionPermissions.getFrontsPermissionsPriorityByCollectionId(
collectionId
)
withModifyGroupPermissionForCollections(collectionPriorities, Set()) {
request.body.asJson
.flatMap(_.asOpt[UpdateMessage])
.map {
case update: Update =>
val identity = request.user
updateActions
.updateTreats(collectionId, update.update, identity)
.map(_.map { updatedCollectionJson =>
s3FrontsApi.putCollectionJson(
collectionId,
Json.prettyPrint(Json.toJson(updatedCollectionJson))
)
structuredLogger.putLog(LogUpdate(update, identity.email))
faciaPress
.press(PressCommand.forOneId(collectionId).withPressLive())
Ok(Json.toJson(Map(collectionId -> updatedCollectionJson)))
.as("application/json")
}.getOrElse(NotFound))
case remove: Remove =>
val identity = request.user
updateActions
.removeTreats(collectionId, remove.remove, identity)
.map(_.map { updatedCollectionJson =>
s3FrontsApi.putCollectionJson(
collectionId,
Json.prettyPrint(Json.toJson(updatedCollectionJson))
)
structuredLogger.putLog(LogUpdate(remove, identity.email))
faciaPress
.press(PressCommand.forOneId(collectionId).withPressLive())
Ok(Json.toJson(Map(collectionId -> updatedCollectionJson)))
.as("application/json")
}.getOrElse(NotFound))
case updateAndRemove: UpdateAndRemove =>
val identity = request.user
val futureUpdatedCollections =
Future
.sequence(
List(
updateActions
.updateTreats(
updateAndRemove.update.id,
updateAndRemove.update,
identity
)
.map(_.map(updateAndRemove.update.id -> _)),
updateActions
.removeTreats(
updateAndRemove.remove.id,
updateAndRemove.remove,
identity
)
.map(_.map(updateAndRemove.remove.id -> _))
)
)
.map(_.flatten.toMap)
futureUpdatedCollections.map { updatedCollections =>
val collectionIds = updatedCollections.keySet
structuredLogger.putLog(
LogUpdate(updateAndRemove, identity.email)
)
faciaPress.press(PressCommand(collectionIds).withPressLive())
Ok(Json.toJson(updatedCollections)).as("application/json")
}
case _ => Future.successful(NotAcceptable)
}
.getOrElse(Future.successful(NotAcceptable))
}
}