1
0
Fork 0
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:
epriestley 2014-08-02 14:45:50 -07:00
parent b5750412c7
commit 4c04d4d019
7 changed files with 128 additions and 5 deletions

View file

@ -1538,6 +1538,7 @@ phutil_register_library_map(array(
'PhabricatorFileDataController' => 'applications/files/controller/PhabricatorFileDataController.php',
'PhabricatorFileDeleteController' => 'applications/files/controller/PhabricatorFileDeleteController.php',
'PhabricatorFileDropUploadController' => 'applications/files/controller/PhabricatorFileDropUploadController.php',
'PhabricatorFileEditController' => 'applications/files/controller/PhabricatorFileEditController.php',
'PhabricatorFileEditor' => 'applications/files/editor/PhabricatorFileEditor.php',
'PhabricatorFileFilePHIDType' => 'applications/files/phid/PhabricatorFileFilePHIDType.php',
'PhabricatorFileImageMacro' => 'applications/macro/storage/PhabricatorFileImageMacro.php',
@ -4354,6 +4355,7 @@ phutil_register_library_map(array(
'PhabricatorFileDataController' => 'PhabricatorFileController',
'PhabricatorFileDeleteController' => 'PhabricatorFileController',
'PhabricatorFileDropUploadController' => 'PhabricatorFileController',
'PhabricatorFileEditController' => 'PhabricatorFileController',
'PhabricatorFileEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorFileFilePHIDType' => 'PhabricatorPHIDType',
'PhabricatorFileImageMacro' => array(

View file

@ -50,6 +50,7 @@ final class PhabricatorFilesApplication extends PhabricatorApplication {
'compose/' => 'PhabricatorFileComposeController',
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorFileCommentController',
'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorFileDeleteController',
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorFileEditController',
'info/(?P<phid>[^/]+)/' => 'PhabricatorFileInfoController',
'data/(?P<key>[^/]+)/(?P<phid>[^/]+)/.*'
=> 'PhabricatorFileDataController',

View file

@ -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,
));
}
}

View file

@ -115,12 +115,17 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
private function buildActionView(PhabricatorFile $file) {
$request = $this->getRequest();
$user = $request->getUser();
$viewer = $request->getUser();
$id = $file->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$file,
PhabricatorPolicyCapability::CAN_EDIT);
$view = id(new PhabricatorActionListView())
->setUser($user)
->setUser($viewer)
->setObjectURI($this->getRequest()->getRequestURI())
->setObject($file);
@ -133,7 +138,7 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
} else {
$view->addAction(
id(new PhabricatorActionView())
->setUser($user)
->setUser($viewer)
->setRenderAsForm(true)
->setDownload(true)
->setName(pht('Download File'))
@ -141,12 +146,21 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
->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(
id(new PhabricatorActionView())
->setName(pht('Delete File'))
->setIcon('fa-times')
->setHref($this->getApplicationURI("/delete/{$id}/"))
->setWorkflow(true));
->setWorkflow(true)
->setDisabled(!$can_edit));
return $view;
}

View file

@ -18,7 +18,7 @@ final class PhabricatorFileShortcutController
return new Aphront404Response();
}
return id(new AphrontRedirectResponse())->setURI($file->getBestURI());
return id(new AphrontRedirectResponse())->setURI($file->getInfoURI());
}
}

View file

@ -7,6 +7,7 @@ final class PhabricatorFileEditor
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
return $types;
}
@ -26,6 +27,12 @@ final class PhabricatorFileEditor
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorTransactions::TYPE_VIEW_POLICY:
$object->setViewPolicy($xaction->getNewValue());
break;
}
}
protected function applyCustomExternalTransaction(

View file

@ -56,6 +56,10 @@ final class PhabricatorFile extends PhabricatorFileDAO
return parent::save();
}
public function getMonogram() {
return 'F'.$this->getID();
}
public static function readUploadedFileData($spec) {
if (!$spec) {
throw new Exception('No file was uploaded!');