2012-01-16 22:26:44 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorFileDeleteController extends PhabricatorFileController {
|
2012-01-16 22:26:44 +01:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2013-09-30 18:38:13 +02:00
|
|
|
$file = id(new PhabricatorFileQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
2012-01-16 22:26:44 +01:00
|
|
|
if (!$file) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($user->getPHID() != $file->getAuthorPHID()) &&
|
|
|
|
(!$user->getIsAdmin())) {
|
|
|
|
return new Aphront403Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$file->delete();
|
|
|
|
return id(new AphrontRedirectResponse())->setURI('/file/');
|
|
|
|
}
|
|
|
|
|
|
|
|
$dialog = new AphrontDialogView();
|
|
|
|
$dialog->setUser($user);
|
2015-05-22 09:27:56 +02:00
|
|
|
$dialog->setTitle(pht('Really delete file?'));
|
2013-02-08 21:07:44 +01:00
|
|
|
$dialog->appendChild(hsprintf(
|
2015-05-22 09:27:56 +02:00
|
|
|
'<p>%s</p>',
|
|
|
|
pht(
|
|
|
|
"Permanently delete '%s'? This action can not be undone.",
|
|
|
|
$file->getName())));
|
|
|
|
$dialog->addSubmitButton(pht('Delete'));
|
2012-01-16 22:26:44 +01:00
|
|
|
$dialog->addCancelButton($file->getInfoURI());
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
}
|