mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Phriction - move delete business logic from controlller to editor
Summary: Ref T4029. More cleanup and code consolidation for the long terms benefits. Test Plan: found a document and opened up two browser tabs. Loaded delete dialog on both. Completed delete in one tab and noted document was properly deleted. Tried to complete delete in tab 2 and got an error message. Reviewers: chad, epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T4029 Differential Revision: https://secure.phabricator.com/D10809
This commit is contained in:
parent
aa0ca6fe4c
commit
622eaac9ed
2 changed files with 33 additions and 17 deletions
|
@ -26,20 +26,10 @@ final class PhrictionDeleteController extends PhrictionController {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$e_text = null;
|
|
||||||
$disallowed_states = array(
|
|
||||||
PhrictionDocumentStatus::STATUS_DELETED => true, // Silly
|
|
||||||
PhrictionDocumentStatus::STATUS_MOVED => true, // Makes no sense
|
|
||||||
PhrictionDocumentStatus::STATUS_STUB => true, // How could they?
|
|
||||||
);
|
|
||||||
if (isset($disallowed_states[$document->getStatus()])) {
|
|
||||||
$e_text = pht(
|
|
||||||
'An already moved or deleted document can not be deleted.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$document_uri = PhrictionDocument::getSlugURI($document->getSlug());
|
$document_uri = PhrictionDocument::getSlugURI($document->getSlug());
|
||||||
|
|
||||||
if (!$e_text && $request->isFormPost()) {
|
$e_text = null;
|
||||||
|
if ($request->isFormPost()) {
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
$xactions[] = id(new PhrictionTransaction())
|
$xactions[] = id(new PhrictionTransaction())
|
||||||
->setTransactionType(PhrictionTransaction::TYPE_DELETE)
|
->setTransactionType(PhrictionTransaction::TYPE_DELETE)
|
||||||
|
@ -48,16 +38,19 @@ final class PhrictionDeleteController extends PhrictionController {
|
||||||
$editor = id(new PhrictionTransactionEditor())
|
$editor = id(new PhrictionTransactionEditor())
|
||||||
->setActor($user)
|
->setActor($user)
|
||||||
->setContentSourceFromRequest($request)
|
->setContentSourceFromRequest($request)
|
||||||
->setContinueOnNoEffect(true)
|
->setContinueOnNoEffect(true);
|
||||||
->applyTransactions($document, $xactions);
|
try {
|
||||||
|
$editor->applyTransactions($document, $xactions);
|
||||||
return id(new AphrontRedirectResponse())->setURI($document_uri);
|
return id(new AphrontRedirectResponse())->setURI($document_uri);
|
||||||
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||||
|
$e_text = phutil_implode_html("\n", $ex->getErrorMessages());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($e_text) {
|
if ($e_text) {
|
||||||
$dialog = id(new AphrontDialogView())
|
$dialog = id(new AphrontDialogView())
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
->setTitle(pht('Can not delete document!'))
|
->setTitle(pht('Can Not Delete Document!'))
|
||||||
->appendChild($e_text)
|
->appendChild($e_text)
|
||||||
->addCancelButton($document_uri);
|
->addCancelButton($document_uri);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -476,6 +476,29 @@ final class PhrictionTransactionEditor
|
||||||
$errors[] = $error;
|
$errors[] = $error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case PhrictionTransaction::TYPE_DELETE:
|
||||||
|
switch ($object->getStatus()) {
|
||||||
|
case PhrictionDocumentStatus::STATUS_DELETED:
|
||||||
|
$e_text = pht('An already deleted document can not be deleted.');
|
||||||
|
break;
|
||||||
|
case PhrictionDocumentStatus::STATUS_MOVED:
|
||||||
|
$e_text = pht('A moved document can not be deleted.');
|
||||||
|
break;
|
||||||
|
case PhrictionDocumentStatus::STATUS_STUB:
|
||||||
|
$e_text = pht('A stub document can not be deleted.');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
$error = new PhabricatorApplicationTransactionValidationError(
|
||||||
|
$type,
|
||||||
|
pht('Can not delete document.'),
|
||||||
|
$e_text,
|
||||||
|
$xaction);
|
||||||
|
$errors[] = $error;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue