mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
Add a Phriction hint when a draft exists, and fix some draft editing bugs
Summary: Depends on D19662. Ref T13077. See PHI840. - If you're looking at the published version of a document, but a draft version exists and you can edit it, add a hint/link. - Fix an issue where the "draft" transaction would complain when you created a document since the initial content is empty and no "draft" transaction is adding any content. Test Plan: Created new documents, viewed documents with current published versions and unpublished drafts. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13077 Differential Revision: https://secure.phabricator.com/D19663
This commit is contained in:
parent
550028a882
commit
b6ba75d991
5 changed files with 87 additions and 24 deletions
|
@ -186,6 +186,35 @@ final class PhrictionDocumentController
|
|||
);
|
||||
} 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();
|
||||
|
|
|
@ -98,7 +98,11 @@ final class PhrictionEditController
|
|||
$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 @@ final class PhrictionEditController
|
|||
}
|
||||
|
||||
$xactions = array();
|
||||
|
||||
$xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhrictionDocumentTitleTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($title);
|
||||
|
@ -275,17 +280,22 @@ final class PhrictionEditController
|
|||
->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());
|
||||
|
||||
$form->appendControl(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->addButton($draft_button)
|
||||
->addCancelButton($cancel_uri)
|
||||
->setValue($submit_button));
|
||||
if (!$is_new) {
|
||||
$draft_button = id(new PHUIButtonView())
|
||||
->setTag('input')
|
||||
->setName('draft')
|
||||
->setText(pht('Save as Draft'))
|
||||
->setColor(PHUIButtonView::GREEN);
|
||||
$submit->addButton($draft_button);
|
||||
}
|
||||
|
||||
$submit
|
||||
->addCancelButton($cancel_uri)
|
||||
->setValue($submit_button);
|
||||
|
||||
$form->appendControl($submit);
|
||||
}
|
||||
|
||||
$form_box = id(new PHUIObjectBoxView())
|
||||
|
|
|
@ -13,4 +13,20 @@ final class PhrictionDocumentContentTransaction
|
|||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,4 +11,25 @@ final class PhrictionDocumentDraftTransaction
|
|||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -79,17 +79,4 @@ abstract class PhrictionDocumentEditTransaction
|
|||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue