Summary: Update Files application Test Plan: Upload a file, edit a file, view details, transforms, delete file Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D13735
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorFileDeleteController extends PhabricatorFileController {
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
$viewer = $request->getViewer();
|
|
$id = $request->getURIData('id');
|
|
|
|
$file = id(new PhabricatorFileQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($id))
|
|
->requireCapabilities(
|
|
array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
))
|
|
->executeOne();
|
|
if (!$file) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
if (($viewer->getPHID() != $file->getAuthorPHID()) &&
|
|
(!$viewer->getIsAdmin())) {
|
|
return new Aphront403Response();
|
|
}
|
|
|
|
if ($request->isFormPost()) {
|
|
$file->delete();
|
|
return id(new AphrontRedirectResponse())->setURI('/file/');
|
|
}
|
|
|
|
$dialog = new AphrontDialogView();
|
|
$dialog->setUser($viewer);
|
|
$dialog->setTitle(pht('Really delete file?'));
|
|
$dialog->appendChild(hsprintf(
|
|
'<p>%s</p>',
|
|
pht(
|
|
"Permanently delete '%s'? This action can not be undone.",
|
|
$file->getName())));
|
|
$dialog->addSubmitButton(pht('Delete'));
|
|
$dialog->addCancelButton($file->getInfoURI());
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
}
|
|
}
|