Skip to content

Commit

Permalink
Merge pull request #791 from guardian/aa-handle-empty-published-atom
Browse files Browse the repository at this point in the history
handle case where atom has not yet been published
  • Loading branch information
akash1810 authored Jun 18, 2018
2 parents e4d50f1 + b8a4962 commit 2cb1497
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions app/model/commands/PublishAtomCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ case class PublishAtomCommand(
val thriftPreviewAtom = getPreviewAtom(id)
val previewAtom = MediaAtom.fromThrift(thriftPreviewAtom)

val thriftPublishedAtom = getPublishedAtom(id)
val publishedAtom = MediaAtom.fromThrift(thriftPublishedAtom)
val publishedAtom = getPublishedAtom()

if(previewAtom.privacyStatus.contains(PrivacyStatus.Private)) {
log.error(s"Unable to publish atom ${previewAtom.id}, privacy status is set to private")
Expand Down Expand Up @@ -86,7 +85,15 @@ case class PublishAtomCommand(
}
}
}
}

private def getPublishedAtom(): Option[MediaAtom] = {
try {
val thriftPublishedAtom = getPublishedAtom(id)
Some(MediaAtom.fromThrift(thriftPublishedAtom))
} catch {
case _: Throwable => None
}
}

private def getAtomBlockAds(previewAtom: MediaAtom): Boolean = {
Expand All @@ -98,9 +105,9 @@ case class PublishAtomCommand(
}
}

private def getPrivacyStatus(previewAtom: MediaAtom, publishedAtom: MediaAtom): Future[PrivacyStatus] = {
previewAtom.channelId match {
case Some(channel) if youtube.channelsRequiringPermission.contains(channel) => {
private def getPrivacyStatus(previewAtom: MediaAtom, maybePublishedAtom: Option[MediaAtom]): Future[PrivacyStatus] = {
(previewAtom.channelId, maybePublishedAtom) match {
case (Some(channel), Some(publishedAtom)) if youtube.channelsRequiringPermission.contains(channel) => {
permissions.getStatusPermissions(user).map(permissions => {
val canChangeVideoStatus = permissions.setVideosOnAllChannelsPublic

Expand Down

0 comments on commit 2cb1497

Please sign in to comment.