1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

Give Pholio mocks a configurable edit policy

Summary:
Ref T4566. Currently, mocks have a conservative (author only), immutable default edit policy.

Instead:

  - Let the edit policy be changed.
  - Default the edit policy to "all users", similar to other applications.
  - Add an application-level setting for it.
  - Migrate existing edit policies to be consistent with the old policy (just the author).

This stops short of adding a separate "owner" and letting that be changed, since Pholio doesn't really have any review/approve type features (at least, so far). We can look at doing this if we get more feedback about it, or if we make owners more meaningful (e.g., add more "review-like" process to mocks).

Test Plan:
  - Ran migration scripts.
  - Confirmed existing mocks retained their effective policies (author only).
  - Created a new mock, saw edit policy.
  - Changed edit policy.
  - Changed global edit policy default.
  - Tried to edit a mock I couldn't edit.

Reviewers: chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T4566

Differential Revision: https://secure.phabricator.com/D9550
This commit is contained in:
epriestley 2014-06-15 10:28:16 -07:00
parent 77efdb6f35
commit 868ff166b1
8 changed files with 43 additions and 6 deletions

View file

@ -81,7 +81,7 @@ return array(
'rsrc/css/application/phame/phame.css' => '19ecc703',
'rsrc/css/application/pholio/pholio-edit.css' => '90616955',
'rsrc/css/application/pholio/pholio-inline-comments.css' => '3d5a5590',
'rsrc/css/application/pholio/pholio.css' => '5bd4c882',
'rsrc/css/application/pholio/pholio.css' => 'e94312dd',
'rsrc/css/application/phortune/phortune-credit-card-form.css' => 'b25b4beb',
'rsrc/css/application/phrequent/phrequent.css' => 'ffc185ad',
'rsrc/css/application/phriction/phriction-document-css.css' => '7d7f0071',
@ -748,7 +748,7 @@ return array(
'phabricator-uiexample-reactor-sendproperties' => '551add57',
'phabricator-zindex-css' => 'efb673ac',
'phame-css' => '19ecc703',
'pholio-css' => '5bd4c882',
'pholio-css' => 'e94312dd',
'pholio-edit-css' => '90616955',
'pholio-inline-comments-css' => '3d5a5590',
'phortune-credit-card-form' => '2290aeef',

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_pholio.pholio_mock
ADD editPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin;

View file

@ -0,0 +1,2 @@
UPDATE {$NAMESPACE}_pholio.pholio_mock
SET editPolicy = authorPHID WHERE editPolicy = '';

View file

@ -2405,6 +2405,7 @@ phutil_register_library_map(array(
'PhluxVariableQuery' => 'applications/phlux/query/PhluxVariableQuery.php',
'PhluxViewController' => 'applications/phlux/controller/PhluxViewController.php',
'PholioActionMenuEventListener' => 'applications/pholio/event/PholioActionMenuEventListener.php',
'PholioCapabilityDefaultEdit' => 'applications/pholio/capability/PholioCapabilityDefaultEdit.php',
'PholioCapabilityDefaultView' => 'applications/pholio/capability/PholioCapabilityDefaultView.php',
'PholioConstants' => 'applications/pholio/constants/PholioConstants.php',
'PholioController' => 'applications/pholio/controller/PholioController.php',
@ -5303,6 +5304,7 @@ phutil_register_library_map(array(
'PhluxVariableQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhluxViewController' => 'PhluxController',
'PholioActionMenuEventListener' => 'PhabricatorEventListener',
'PholioCapabilityDefaultEdit' => 'PhabricatorPolicyCapability',
'PholioCapabilityDefaultView' => 'PhabricatorPolicyCapability',
'PholioController' => 'PhabricatorController',
'PholioDAO' => 'PhabricatorLiskDAO',

View file

@ -72,8 +72,8 @@ final class PhabricatorApplicationPholio extends PhabricatorApplication {
protected function getCustomCapabilities() {
return array(
PholioCapabilityDefaultView::CAPABILITY => array(
),
PholioCapabilityDefaultView::CAPABILITY => array(),
PholioCapabilityDefaultEdit::CAPABILITY => array(),
);
}

View file

@ -0,0 +1,16 @@
<?php
final class PholioCapabilityDefaultEdit
extends PhabricatorPolicyCapability {
const CAPABILITY = 'pholio.default.edit';
public function getCapabilityKey() {
return self::CAPABILITY;
}
public function getCapabilityName() {
return pht('Default Edit Policy');
}
}

View file

@ -65,6 +65,7 @@ final class PholioMockEditController extends PholioController {
$v_desc = $mock->getDescription();
$v_status = $mock->getStatus();
$v_view = $mock->getViewPolicy();
$v_edit = $mock->getEditPolicy();
$v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$mock->getPHID());
@ -75,12 +76,14 @@ final class PholioMockEditController extends PholioController {
$type_desc = PholioTransactionType::TYPE_DESCRIPTION;
$type_status = PholioTransactionType::TYPE_STATUS;
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
$type_cc = PhabricatorTransactions::TYPE_SUBSCRIBERS;
$v_name = $request->getStr('name');
$v_desc = $request->getStr('description');
$v_status = $request->getStr('status');
$v_view = $request->getStr('can_view');
$v_edit = $request->getStr('can_edit');
$v_cc = $request->getArr('cc');
$v_projects = $request->getArr('projects');
@ -89,6 +92,7 @@ final class PholioMockEditController extends PholioController {
$mock_xactions[$type_desc] = $v_desc;
$mock_xactions[$type_status] = $v_status;
$mock_xactions[$type_view] = $v_view;
$mock_xactions[$type_edit] = $v_edit;
$mock_xactions[$type_cc] = array('=' => $v_cc);
if (!strlen($request->getStr('name'))) {
@ -242,6 +246,7 @@ final class PholioMockEditController extends PholioController {
// NOTE: Make this show up correctly on the rendered form.
$mock->setViewPolicy($v_view);
$mock->setEditPolicy($v_edit);
$handles = id(new PhabricatorHandleQuery())
->setViewer($user)
@ -359,6 +364,13 @@ final class PholioMockEditController extends PholioController {
->setPolicyObject($mock)
->setPolicies($policies)
->setName('can_view'))
->appendChild(
id(new AphrontFormPolicyControl())
->setUser($user)
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
->setPolicyObject($mock)
->setPolicies($policies)
->setName('can_edit'))
->appendChild(
id(new AphrontFormMarkupControl())
->setValue($list_control))

View file

@ -14,6 +14,7 @@ final class PholioMock extends PholioDAO
protected $authorPHID;
protected $viewPolicy;
protected $editPolicy;
protected $name;
protected $originalName;
@ -34,11 +35,13 @@ final class PholioMock extends PholioDAO
->executeOne();
$view_policy = $app->getPolicy(PholioCapabilityDefaultView::CAPABILITY);
$edit_policy = $app->getPolicy(PholioCapabilityDefaultEdit::CAPABILITY);
return id(new PholioMock())
->setAuthorPHID($actor->getPHID())
->attachImages(array())
->setViewPolicy($view_policy);
->setViewPolicy($view_policy)
->setEditPolicy($edit_policy);
}
public function getMonogram() {
@ -178,7 +181,7 @@ final class PholioMock extends PholioDAO
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return PhabricatorPolicies::POLICY_NOONE;
return $this->getEditPolicy();
}
}