diff --git a/src/applications/phriction/controller/PhrictionDocumentController.php b/src/applications/phriction/controller/PhrictionDocumentController.php --- a/src/applications/phriction/controller/PhrictionDocumentController.php +++ b/src/applications/phriction/controller/PhrictionDocumentController.php @@ -186,6 +186,35 @@ ); } else { $content = $document->getContent(); + + if ($content->getVersion() < $document->getMaxVersion()) { + $can_edit = PhabricatorPolicyFilter::hasCapability( + $viewer, + $document, + PhabricatorPolicyCapability::CAN_EDIT); + if ($can_edit) { + $document_uri = new PhutilURI($document->getURI()); + $draft_uri = $document_uri->alter('v', $document->getMaxVersion()); + + $draft_link = phutil_tag( + 'a', + array( + 'href' => $draft_uri, + ), + pht('View Draft Version')); + + $draft_link = phutil_tag('strong', array(), $draft_link); + + $version_note = id(new PHUIInfoView()) + ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) + ->appendChild( + array( + pht('This document has unpublished draft changes.'), + ' ', + $draft_link, + )); + } + } } $page_title = $content->getTitle(); diff --git a/src/applications/phriction/controller/PhrictionEditController.php b/src/applications/phriction/controller/PhrictionEditController.php --- a/src/applications/phriction/controller/PhrictionEditController.php +++ b/src/applications/phriction/controller/PhrictionEditController.php @@ -98,7 +98,11 @@ $is_draft_mode = ($document->getContent()->getVersion() != $max_version); if ($request->isFormPost()) { - $save_as_draft = ($is_draft_mode || $request->getExists('draft')); + if ($is_new) { + $save_as_draft = false; + } else { + $save_as_draft = ($is_draft_mode || $request->getExists('draft')); + } $title = $request->getStr('title'); $content_text = $request->getStr('content'); @@ -117,6 +121,7 @@ } $xactions = array(); + $xactions[] = id(new PhrictionTransaction()) ->setTransactionType(PhrictionDocumentTitleTransaction::TRANSACTIONTYPE) ->setNewValue($title); @@ -275,17 +280,22 @@ ->addCancelButton($cancel_uri) ->setValue(pht('Save Draft'))); } else { - $draft_button = id(new PHUIButtonView()) - ->setTag('input') - ->setName('draft') - ->setText(pht('Save as Draft')) - ->setColor(PHUIButtonView::GREEN); + $submit = id(new AphrontFormSubmitControl()); + + if (!$is_new) { + $draft_button = id(new PHUIButtonView()) + ->setTag('input') + ->setName('draft') + ->setText(pht('Save as Draft')) + ->setColor(PHUIButtonView::GREEN); + $submit->addButton($draft_button); + } - $form->appendControl( - id(new AphrontFormSubmitControl()) - ->addButton($draft_button) - ->addCancelButton($cancel_uri) - ->setValue($submit_button)); + $submit + ->addCancelButton($cancel_uri) + ->setValue($submit_button); + + $form->appendControl($submit); } $form_box = id(new PHUIObjectBoxView()) diff --git a/src/applications/phriction/xaction/PhrictionDocumentContentTransaction.php b/src/applications/phriction/xaction/PhrictionDocumentContentTransaction.php --- a/src/applications/phriction/xaction/PhrictionDocumentContentTransaction.php +++ b/src/applications/phriction/xaction/PhrictionDocumentContentTransaction.php @@ -13,4 +13,20 @@ $this->getEditor()->setShouldPublishContent($object, true); } + public function validateTransactions($object, array $xactions) { + $errors = array(); + + // NOTE: This is slightly different from the draft validation. Here, + // we're validating that: you can't edit away a document; and you can't + // create an empty document. + + $content = $object->getContent()->getContent(); + if ($this->isEmptyTextTransaction($content, $xactions)) { + $errors[] = $this->newRequiredError( + pht('Documents must have content.')); + } + + return $errors; + } + } diff --git a/src/applications/phriction/xaction/PhrictionDocumentDraftTransaction.php b/src/applications/phriction/xaction/PhrictionDocumentDraftTransaction.php --- a/src/applications/phriction/xaction/PhrictionDocumentDraftTransaction.php +++ b/src/applications/phriction/xaction/PhrictionDocumentDraftTransaction.php @@ -11,4 +11,25 @@ $this->getEditor()->setShouldPublishContent($object, false); } + public function validateTransactions($object, array $xactions) { + $errors = array(); + + // NOTE: We're only validating that you can't edit a document down to + // nothing in a draft transaction. Alone, this doesn't prevent you from + // creating a document with no content. The content transaction has + // validation for that. + + if (!$xactions) { + return $errors; + } + + $content = $object->getContent()->getContent(); + if ($this->isEmptyTextTransaction($content, $xactions)) { + $errors[] = $this->newRequiredError( + pht('Documents must have content.')); + } + + return $errors; + } + } diff --git a/src/applications/phriction/xaction/PhrictionDocumentEditTransaction.php b/src/applications/phriction/xaction/PhrictionDocumentEditTransaction.php --- a/src/applications/phriction/xaction/PhrictionDocumentEditTransaction.php +++ b/src/applications/phriction/xaction/PhrictionDocumentEditTransaction.php @@ -79,17 +79,4 @@ return $changes; } - public function validateTransactions($object, array $xactions) { - $errors = array(); - - $content = $object->getContent()->getContent(); - if ($this->isEmptyTextTransaction($content, $xactions)) { - $errors[] = $this->newRequiredError( - pht('Documents must have content.')); - } - - return $errors; - } - - }