diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0a48289455..26272151e3 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -469,6 +469,7 @@ phutil_register_library_map(array( 'PhabricatorFileAltViewController' => 'applications/files/controller/altview', 'PhabricatorFileController' => 'applications/files/controller/base', 'PhabricatorFileDAO' => 'applications/files/storage/base', + 'PhabricatorFileDeleteController' => 'applications/files/controller/delete', 'PhabricatorFileDropUploadController' => 'applications/files/controller/dropupload', 'PhabricatorFileImageMacro' => 'applications/files/storage/imagemacro', 'PhabricatorFileListController' => 'applications/files/controller/list', @@ -1150,6 +1151,7 @@ phutil_register_library_map(array( 'PhabricatorFileAltViewController' => 'PhabricatorFileController', 'PhabricatorFileController' => 'PhabricatorController', 'PhabricatorFileDAO' => 'PhabricatorLiskDAO', + 'PhabricatorFileDeleteController' => 'PhabricatorFileController', 'PhabricatorFileDropUploadController' => 'PhabricatorFileController', 'PhabricatorFileImageMacro' => 'PhabricatorFileDAO', 'PhabricatorFileListController' => 'PhabricatorFileController', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index bda20448dd..89c648ddd3 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -54,6 +54,7 @@ class AphrontDefaultApplicationConfiguration 'filter/(?P\w+)/$' => 'PhabricatorFileListController', 'upload/$' => 'PhabricatorFileUploadController', 'dropupload/$' => 'PhabricatorFileDropUploadController', + 'delete/(?P\d+)/$' => 'PhabricatorFileDeleteController', '(?Pinfo)/(?P[^/]+)/' => 'PhabricatorFileViewController', '(?Pview)/(?P[^/]+)/' => 'PhabricatorFileViewController', '(?Pdownload)/(?P[^/]+)/' => 'PhabricatorFileViewController', diff --git a/src/applications/files/controller/delete/PhabricatorFileDeleteController.php b/src/applications/files/controller/delete/PhabricatorFileDeleteController.php new file mode 100644 index 0000000000..11ac72147e --- /dev/null +++ b/src/applications/files/controller/delete/PhabricatorFileDeleteController.php @@ -0,0 +1,60 @@ +id = $data['id']; + } + + public function processRequest() { + + $request = $this->getRequest(); + $user = $request->getUser(); + + $file = id(new PhabricatorFile())->loadOneWhere( + 'id = %d', + $this->id); + 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); + $dialog->setTitle('Really delete file?'); + $dialog->appendChild( + "

Permanently delete '".phutil_escape_html($file->getName())."'? This ". + "action can not be undone."); + $dialog->addSubmitButton('Delete'); + $dialog->addCancelButton($file->getInfoURI()); + + return id(new AphrontDialogResponse())->setDialog($dialog); + } +} diff --git a/src/applications/files/controller/delete/__init__.php b/src/applications/files/controller/delete/__init__.php new file mode 100644 index 0000000000..6593be5f6a --- /dev/null +++ b/src/applications/files/controller/delete/__init__.php @@ -0,0 +1,21 @@ +isViewableInBrowser()) { $form->setAction($file->getViewURI()); - $button_name = 'View File'; + $submit->setValue('View File'); } else { $form->setAction('/file/download/'.$file->getPHID().'/'); - $button_name = 'Download File'; + $submit->setValue('Download File'); + } + + if (($user->getPHID() == $file->getAuthorPHID()) || + ($user->getIsAdmin())) { + $submit->addCancelButton( + '/file/delete/'.$file->getID().'/', + 'Delete File'); } $file_id = 'F'.$file->getID(); @@ -171,8 +180,7 @@ class PhabricatorFileViewController extends PhabricatorFileController { ->setName('storageHandle') ->setValue($file->getStorageHandle())) ->appendChild( - id(new AphrontFormSubmitControl()) - ->setValue($button_name)); + id($submit)); $panel = new AphrontPanelView(); $panel->setHeader('File Info - '.$file->getName());