mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Allow users to set view policies on files explicitly
Summary: Ref T4589. Allow users to adjust visibility settings on files explicitly. This makes it easier to understand and manage upcoming changes in T4589. Test Plan: Changed the view policy for a file several times. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4589 Differential Revision: https://secure.phabricator.com/D10129
This commit is contained in:
parent
b5750412c7
commit
4c04d4d019
7 changed files with 128 additions and 5 deletions
|
@ -1538,6 +1538,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorFileDataController' => 'applications/files/controller/PhabricatorFileDataController.php',
|
'PhabricatorFileDataController' => 'applications/files/controller/PhabricatorFileDataController.php',
|
||||||
'PhabricatorFileDeleteController' => 'applications/files/controller/PhabricatorFileDeleteController.php',
|
'PhabricatorFileDeleteController' => 'applications/files/controller/PhabricatorFileDeleteController.php',
|
||||||
'PhabricatorFileDropUploadController' => 'applications/files/controller/PhabricatorFileDropUploadController.php',
|
'PhabricatorFileDropUploadController' => 'applications/files/controller/PhabricatorFileDropUploadController.php',
|
||||||
|
'PhabricatorFileEditController' => 'applications/files/controller/PhabricatorFileEditController.php',
|
||||||
'PhabricatorFileEditor' => 'applications/files/editor/PhabricatorFileEditor.php',
|
'PhabricatorFileEditor' => 'applications/files/editor/PhabricatorFileEditor.php',
|
||||||
'PhabricatorFileFilePHIDType' => 'applications/files/phid/PhabricatorFileFilePHIDType.php',
|
'PhabricatorFileFilePHIDType' => 'applications/files/phid/PhabricatorFileFilePHIDType.php',
|
||||||
'PhabricatorFileImageMacro' => 'applications/macro/storage/PhabricatorFileImageMacro.php',
|
'PhabricatorFileImageMacro' => 'applications/macro/storage/PhabricatorFileImageMacro.php',
|
||||||
|
@ -4354,6 +4355,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorFileDataController' => 'PhabricatorFileController',
|
'PhabricatorFileDataController' => 'PhabricatorFileController',
|
||||||
'PhabricatorFileDeleteController' => 'PhabricatorFileController',
|
'PhabricatorFileDeleteController' => 'PhabricatorFileController',
|
||||||
'PhabricatorFileDropUploadController' => 'PhabricatorFileController',
|
'PhabricatorFileDropUploadController' => 'PhabricatorFileController',
|
||||||
|
'PhabricatorFileEditController' => 'PhabricatorFileController',
|
||||||
'PhabricatorFileEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PhabricatorFileEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'PhabricatorFileFilePHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorFileFilePHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhabricatorFileImageMacro' => array(
|
'PhabricatorFileImageMacro' => array(
|
||||||
|
|
|
@ -50,6 +50,7 @@ final class PhabricatorFilesApplication extends PhabricatorApplication {
|
||||||
'compose/' => 'PhabricatorFileComposeController',
|
'compose/' => 'PhabricatorFileComposeController',
|
||||||
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorFileCommentController',
|
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorFileCommentController',
|
||||||
'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorFileDeleteController',
|
'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorFileDeleteController',
|
||||||
|
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorFileEditController',
|
||||||
'info/(?P<phid>[^/]+)/' => 'PhabricatorFileInfoController',
|
'info/(?P<phid>[^/]+)/' => 'PhabricatorFileInfoController',
|
||||||
'data/(?P<key>[^/]+)/(?P<phid>[^/]+)/.*'
|
'data/(?P<key>[^/]+)/(?P<phid>[^/]+)/.*'
|
||||||
=> 'PhabricatorFileDataController',
|
=> 'PhabricatorFileDataController',
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorFileEditController extends PhabricatorFileController {
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
public function willProcessRequest(array $data) {
|
||||||
|
$this->id = $data['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function processRequest() {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
|
$file = id(new PhabricatorFileQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withIDs(array($this->id))
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->executeOne();
|
||||||
|
if (!$file) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = pht('Edit %s', $file->getName());
|
||||||
|
$view_uri = '/'.$file->getMonogram();
|
||||||
|
|
||||||
|
$validation_exception = null;
|
||||||
|
if ($request->isFormPost()) {
|
||||||
|
$can_view = $request->getStr('canView');
|
||||||
|
|
||||||
|
$xactions = array();
|
||||||
|
|
||||||
|
$xactions[] = id(new PhabricatorFileTransaction())
|
||||||
|
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
||||||
|
->setNewValue($can_view);
|
||||||
|
|
||||||
|
$editor = id(new PhabricatorFileEditor())
|
||||||
|
->setActor($viewer)
|
||||||
|
->setContentSourceFromRequest($request)
|
||||||
|
->setContinueOnNoEffect(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$editor->applyTransactions($file, $xactions);
|
||||||
|
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
||||||
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||||
|
$validation_exception = $ex;
|
||||||
|
|
||||||
|
$file->setViewPolicy($can_view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$policies = id(new PhabricatorPolicyQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->setObject($file)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
$form = id(new AphrontFormView())
|
||||||
|
->setUser($viewer)
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormPolicyControl())
|
||||||
|
->setUser($viewer)
|
||||||
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
||||||
|
->setPolicyObject($file)
|
||||||
|
->setPolicies($policies)
|
||||||
|
->setName('canView'))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormSubmitControl())
|
||||||
|
->addCancelButton($view_uri)
|
||||||
|
->setValue(pht('Save Changes')));
|
||||||
|
|
||||||
|
$crumbs = $this->buildApplicationCrumbs()
|
||||||
|
->addTextCrumb($file->getMonogram(), $view_uri)
|
||||||
|
->addTextCrumb(pht('Edit'));
|
||||||
|
|
||||||
|
$object_box = id(new PHUIObjectBoxView())
|
||||||
|
->setHeaderText($title)
|
||||||
|
->setValidationException($validation_exception)
|
||||||
|
->appendChild($form);
|
||||||
|
|
||||||
|
return $this->buildApplicationPage(
|
||||||
|
array(
|
||||||
|
$crumbs,
|
||||||
|
$object_box,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'title' => $title,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -115,12 +115,17 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
|
||||||
|
|
||||||
private function buildActionView(PhabricatorFile $file) {
|
private function buildActionView(PhabricatorFile $file) {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
$id = $file->getID();
|
$id = $file->getID();
|
||||||
|
|
||||||
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||||
|
$viewer,
|
||||||
|
$file,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT);
|
||||||
|
|
||||||
$view = id(new PhabricatorActionListView())
|
$view = id(new PhabricatorActionListView())
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->setObjectURI($this->getRequest()->getRequestURI())
|
->setObjectURI($this->getRequest()->getRequestURI())
|
||||||
->setObject($file);
|
->setObject($file);
|
||||||
|
|
||||||
|
@ -133,7 +138,7 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
|
||||||
} else {
|
} else {
|
||||||
$view->addAction(
|
$view->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->setRenderAsForm(true)
|
->setRenderAsForm(true)
|
||||||
->setDownload(true)
|
->setDownload(true)
|
||||||
->setName(pht('Download File'))
|
->setName(pht('Download File'))
|
||||||
|
@ -141,12 +146,21 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
|
||||||
->setHref($file->getViewURI()));
|
->setHref($file->getViewURI()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$view->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setName(pht('Edit File'))
|
||||||
|
->setIcon('fa-pencil')
|
||||||
|
->setHref($this->getApplicationURI("/edit/{$id}/"))
|
||||||
|
->setWorkflow(!$can_edit)
|
||||||
|
->setDisabled(!$can_edit));
|
||||||
|
|
||||||
$view->addAction(
|
$view->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setName(pht('Delete File'))
|
->setName(pht('Delete File'))
|
||||||
->setIcon('fa-times')
|
->setIcon('fa-times')
|
||||||
->setHref($this->getApplicationURI("/delete/{$id}/"))
|
->setHref($this->getApplicationURI("/delete/{$id}/"))
|
||||||
->setWorkflow(true));
|
->setWorkflow(true)
|
||||||
|
->setDisabled(!$can_edit));
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ final class PhabricatorFileShortcutController
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
return id(new AphrontRedirectResponse())->setURI($file->getBestURI());
|
return id(new AphrontRedirectResponse())->setURI($file->getInfoURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ final class PhabricatorFileEditor
|
||||||
$types = parent::getTransactionTypes();
|
$types = parent::getTransactionTypes();
|
||||||
|
|
||||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
||||||
|
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +27,12 @@ final class PhabricatorFileEditor
|
||||||
protected function applyCustomInternalTransaction(
|
protected function applyCustomInternalTransaction(
|
||||||
PhabricatorLiskDAO $object,
|
PhabricatorLiskDAO $object,
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
|
||||||
|
switch ($xaction->getTransactionType()) {
|
||||||
|
case PhabricatorTransactions::TYPE_VIEW_POLICY:
|
||||||
|
$object->setViewPolicy($xaction->getNewValue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function applyCustomExternalTransaction(
|
protected function applyCustomExternalTransaction(
|
||||||
|
|
|
@ -56,6 +56,10 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
return parent::save();
|
return parent::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMonogram() {
|
||||||
|
return 'F'.$this->getID();
|
||||||
|
}
|
||||||
|
|
||||||
public static function readUploadedFileData($spec) {
|
public static function readUploadedFileData($spec) {
|
||||||
if (!$spec) {
|
if (!$spec) {
|
||||||
throw new Exception('No file was uploaded!');
|
throw new Exception('No file was uploaded!');
|
||||||
|
|
Loading…
Reference in a new issue