in app/controllers/Restore.scala [34:55]
def userFromPandaUser(user: PandaUser) = User(user.firstName, user.lastName, user.email)
def restore(sourceId: String, contentId: String, timestamp: String, destinationId: String) = AuthAction.async { request =>
if (!permissions.hasPermission(Permissions.RestoreContent, request.user.email)) {
Future.successful(Forbidden(s"You do not have the ${Permissions.RestoreContent.name} permission which is required to restore content"))
} else if (sourceId != destinationId && !permissions.hasPermission(Permissions.RestoreContentToAlternateStack, request.user.email)) {
Future.successful(Forbidden(s"You do not have the ${Permissions.RestoreContentToAlternateStack.name} permission which is required to restore content from one stack to another"))
} else {
val user = userFromPandaUser(request.user)
val sourceStack = config.stackFromId(sourceId)
val targetStack = config.stackFromId(destinationId)
val snapshotId = SnapshotId(contentId, timestamp)
val result = snapshotApi.getSnapshot(sourceStack.snapshotBucket, snapshotId).flatMap[Result] {
case None => Attempt.Right(NotFound)
case Some(snapshot) => flexibleApi.restore(targetStack, user, contentId, snapshot).map(Ok(_))
}
result.fold(
errors => InternalServerError(s"Error whilst restoring: $errors"),
identity
)
}
}