Allow pastes to be edited

Summary: Fixes T4814.

Test Plan: Edited pastes from the web UI.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4814

Differential Revision: https://secure.phabricator.com/D8970
This commit is contained in:
epriestley
2014-05-04 11:11:46 -07:00
parent c2f58496ad
commit bd7420c4bb
8 changed files with 115 additions and 64 deletions

View File

@@ -42,6 +42,7 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
}
$paste->setAuthorPHID($user->getPHID());
$paste->attachRawContent('');
} else {
$is_create = false;
@@ -53,6 +54,7 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($this->id))
->needRawContent(true)
->executeOne();
if (!$paste) {
return new Aphront404Response();
@@ -69,22 +71,20 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
} else {
$v_title = $paste->getTitle();
$v_language = $paste->getLanguage();
$v_text = '';
$v_text = $paste->getRawContent();
}
$v_policy = $paste->getViewPolicy();
if ($request->isFormPost()) {
$xactions = array();
if ($is_create) {
$v_text = $request->getStr('text');
if (!strlen($v_text)) {
$e_text = pht('Required');
$errors[] = pht('The paste may not be blank.');
} else {
$e_text = null;
}
}
$v_text = $request->getStr('text');
if (!strlen($v_text)) {
$e_text = pht('Required');
$errors[] = pht('The paste may not be blank.');
} else {
$e_text = null;
}
$v_title = $request->getStr('title');
$v_language = $request->getStr('language');
@@ -94,14 +94,14 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
// so it's impossible for them to choose an invalid policy.
if (!$errors) {
if ($is_create) {
if ($is_create || ($v_text !== $paste->getRawContent())) {
$file = PhabricatorPasteEditor::initializeFileForPaste(
$user,
$v_title,
$v_text);
$xactions[] = id(new PhabricatorPasteTransaction())
->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE)
->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT)
->setNewValue($file->getPHID());
}
@@ -161,31 +161,15 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
->setPolicies($policies)
->setName('can_view'));
if ($is_create) {
$form
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel(pht('Text'))
->setError($e_text)
->setValue($v_text)
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
->setCustomClass('PhabricatorMonospaced')
->setName('text'));
} else {
$fork_link = phutil_tag(
'a',
array(
'href' => $this->getApplicationURI('?parent='.$paste->getID())
),
pht('Fork'));
$form
->appendChild(
id(new AphrontFormMarkupControl())
$form
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel(pht('Text'))
->setValue(pht(
'Paste text can not be edited. %s to create a new paste.',
$fork_link)));
}
->setError($e_text)
->setValue($v_text)
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
->setCustomClass('PhabricatorMonospaced')
->setName('text'));
$submit = new AphrontFormSubmitControl();