Skip to content

Commit 6b0138c

Browse files
AnhNhanepriestley
authored andcommitted
prevents users from deleting already deleted/moved phriction documents
Summary: Deps D5198 since it uses a constant from D5198 accidentalbigdiff I sure doubled the size of this file ^^ Could be that I added unserious business. Test Plan: Created a page. Had it open in two browser windows. Deleted in one. This is the second attempt: {F34458} Reviewers: epriestley, btrahan Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D5202
1 parent 0a2a5c7 commit 6b0138c

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

src/applications/phriction/controller/PhrictionDeleteController.php

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,56 @@ public function processRequest() {
2121
return new Aphront404Response();
2222
}
2323

24+
$error_view = null;
25+
$disallowed_states = array(
26+
PhrictionDocumentStatus::STATUS_DELETED, // Stupid
27+
PhrictionDocumentStatus::STATUS_MOVED, // Makes no sense
28+
);
29+
if (in_array($document->getStatus(), $disallowed_states)) {
30+
$is_serious =
31+
PhabricatorEnv::getEnvConfig('phabricator.serious-business');
32+
33+
if ($is_serious) {
34+
$e_text = pht('An already moved or deleted document can not be '.
35+
'deleted');
36+
} else {
37+
$e_text = pht('I\'m not sure if you got the notice, but you can\'t '.
38+
'delete an already deleted or moved document.');
39+
}
40+
41+
$error_view = new AphrontErrorView();
42+
$error_view->setSeverity(AphrontErrorView::SEVERITY_ERROR);
43+
$error_view->setTitle(pht('Can not delete page'));
44+
$error_view->appendChild($e_text);
45+
46+
$error_view = $error_view->render();
47+
}
48+
2449
$document_uri = PhrictionDocument::getSlugURI($document->getSlug());
2550

26-
if ($request->isFormPost()) {
51+
if (!$error_view && $request->isFormPost()) {
2752
$editor = id(PhrictionDocumentEditor::newForSlug($document->getSlug()))
2853
->setActor($user)
2954
->delete();
3055
return id(new AphrontRedirectResponse())->setURI($document_uri);
3156
}
3257

33-
$dialog = id(new AphrontDialogView())
34-
->setUser($user)
35-
->setTitle(pht('Delete document?'))
36-
->appendChild(
37-
pht('Really delete this document? You can recover it later by '.
38-
'reverting to a previous version.'))
39-
->addSubmitButton(pht('Delete'))
40-
->addCancelButton($document_uri);
58+
if ($error_view) {
59+
$dialog = id(new AphrontDialogView())
60+
->setUser($user)
61+
->setTitle(pht('Error!'))
62+
->appendChild($error_view)
63+
->addCancelButton($document_uri);
64+
} else {
65+
$dialog = id(new AphrontDialogView())
66+
->setUser($user)
67+
->setTitle(pht('Delete document?'))
68+
->appendChild(
69+
pht('Really delete this document? You can recover it later by '.
70+
'reverting to a previous version.'))
71+
->addSubmitButton(pht('Delete'))
72+
->addCancelButton($document_uri);
73+
}
4174

4275
return id(new AphrontDialogResponse())->setDialog($dialog);
4376
}

0 commit comments

Comments
 (0)