| 
									
										
										
										
											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/'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $dialog = new AphrontDialogView(); | 
					
						
							| 
									
										
										
										
											2015-07-27 09:41:53 -07:00
										 |  |  |     $dialog->setUser($viewer); | 
					
						
							| 
									
										
										
										
											2015-05-22 17:27:56 +10:00
										 |  |  |     $dialog->setTitle(pht('Really delete file?')); | 
					
						
							| 
									
										
										
										
											2013-02-08 12:07:44 -08:00
										 |  |  |     $dialog->appendChild(hsprintf( | 
					
						
							| 
									
										
										
										
											2015-05-22 17:27:56 +10:00
										 |  |  |       '<p>%s</p>', | 
					
						
							|  |  |  |       pht( | 
					
						
							|  |  |  |         "Permanently delete '%s'? This action can not be undone.", | 
					
						
							|  |  |  |         $file->getName()))); | 
					
						
							|  |  |  |     $dialog->addSubmitButton(pht('Delete')); | 
					
						
							| 
									
										
										
										
											2012-01-16 13:26:44 -08:00
										 |  |  |     $dialog->addCancelButton($file->getInfoURI()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return id(new AphrontDialogResponse())->setDialog($dialog); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |