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