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
|
|
|
|
2015-07-27 18:41:53 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2012-01-16 22:26:44 +01:00
|
|
|
|
2013-09-30 18:38:13 +02:00
|
|
|
$file = id(new PhabricatorFileQuery())
|
2015-07-27 18:41:53 +02:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
2013-09-30 18:38:13 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
2012-01-16 22:26:44 +01:00
|
|
|
if (!$file) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2015-07-27 18:41:53 +02:00
|
|
|
if (($viewer->getPHID() != $file->getAuthorPHID()) &&
|
|
|
|
(!$viewer->getIsAdmin())) {
|
2012-01-16 22:26:44 +01:00
|
|
|
return new Aphront403Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$file->delete();
|
|
|
|
return id(new AphrontRedirectResponse())->setURI('/file/');
|
|
|
|
}
|
|
|
|
|
2016-04-06 00:55:04 +02:00
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Really delete file?'))
|
|
|
|
->appendChild(hsprintf(
|
2015-05-22 09:27:56 +02:00
|
|
|
'<p>%s</p>',
|
|
|
|
pht(
|
2016-04-06 00:55:04 +02:00
|
|
|
'Permanently delete "%s"? This action can not be undone.',
|
|
|
|
$file->getName())))
|
|
|
|
->addSubmitButton(pht('Delete'))
|
|
|
|
->addCancelButton($file->getInfoURI());
|
2012-01-16 22:26:44 +01:00
|
|
|
}
|
|
|
|
}
|