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

handle case where atom has not yet been published #791

Merged
merged 1 commit into from
Jun 18, 2018
Merged
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
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