Page MenuHomePhabricator

D15268.id36840.diff
No OneTemporary

D15268.id36840.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -7305,6 +7305,7 @@
'PhabricatorApplicationTransactionInterface',
'PhabricatorPolicyInterface',
'PhabricatorDestructibleInterface',
+ 'PhabricatorExtendedPolicyInterface',
),
'PhabricatorProjectColumnDetailController' => 'PhabricatorProjectBoardController',
'PhabricatorProjectColumnEditController' => 'PhabricatorProjectBoardController',
diff --git a/src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php b/src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php
--- a/src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php
+++ b/src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php
@@ -1013,6 +1013,51 @@
$this->assertColumns($expect, $user, $board, $task);
}
+ public function testColumnExtendedPolicies() {
+ $user = $this->createUser();
+ $user->save();
+
+ $board = $this->createProject($user);
+ $column = $this->addColumn($user, $board, 0);
+
+ // At first, the user should be able to view and edit the column.
+ $column = $this->refreshColumn($user, $column);
+ $this->assertTrue((bool)$column);
+
+ $can_edit = PhabricatorPolicyFilter::hasCapability(
+ $user,
+ $column,
+ PhabricatorPolicyCapability::CAN_EDIT);
+ $this->assertTrue($can_edit);
+
+ // Now, set the project edit policy to "Members of Project". This should
+ // disable editing.
+ $members_policy = id(new PhabricatorProjectMembersPolicyRule())
+ ->getObjectPolicyFullKey();
+ $board->setEditPolicy($members_policy)->save();
+
+ $column = $this->refreshColumn($user, $column);
+ $this->assertTrue((bool)$column);
+
+ $can_edit = PhabricatorPolicyFilter::hasCapability(
+ $user,
+ $column,
+ PhabricatorPolicyCapability::CAN_EDIT);
+ $this->assertFalse($can_edit);
+
+ // Now, join the project. This should make the column editable again.
+ $this->joinProject($board, $user);
+
+ $column = $this->refreshColumn($user, $column);
+ $this->assertTrue((bool)$column);
+
+ $can_edit = PhabricatorPolicyFilter::hasCapability(
+ $user,
+ $column,
+ PhabricatorPolicyCapability::CAN_EDIT);
+ $this->assertTrue($can_edit);
+ }
+
private function moveToColumn(
PhabricatorUser $viewer,
PhabricatorProject $board,
@@ -1251,6 +1296,22 @@
}
}
+ private function refreshColumn(
+ PhabricatorUser $viewer,
+ PhabricatorProjectColumn $column) {
+
+ $results = id(new PhabricatorProjectColumnQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($column->getID()))
+ ->execute();
+
+ if ($results) {
+ return head($results);
+ } else {
+ return null;
+ }
+ }
+
private function createProject(
PhabricatorUser $user,
PhabricatorProject $parent = null,
diff --git a/src/applications/project/controller/PhabricatorProjectColumnDetailController.php b/src/applications/project/controller/PhabricatorProjectColumnDetailController.php
--- a/src/applications/project/controller/PhabricatorProjectColumnDetailController.php
+++ b/src/applications/project/controller/PhabricatorProjectColumnDetailController.php
@@ -73,8 +73,7 @@
$header = id(new PHUIHeaderView())
->setUser($viewer)
- ->setHeader($column->getDisplayName())
- ->setPolicyObject($column);
+ ->setHeader($column->getDisplayName());
if ($column->isHidden()) {
$header->setStatus('fa-ban', 'dark', pht('Hidden'));
diff --git a/src/applications/project/storage/PhabricatorProjectColumn.php b/src/applications/project/storage/PhabricatorProjectColumn.php
--- a/src/applications/project/storage/PhabricatorProjectColumn.php
+++ b/src/applications/project/storage/PhabricatorProjectColumn.php
@@ -5,7 +5,8 @@
implements
PhabricatorApplicationTransactionInterface,
PhabricatorPolicyInterface,
- PhabricatorDestructibleInterface {
+ PhabricatorDestructibleInterface,
+ PhabricatorExtendedPolicyInterface {
const STATUS_ACTIVE = 0;
const STATUS_HIDDEN = 1;
@@ -219,7 +220,14 @@
}
public function getPolicy($capability) {
- return $this->getProject()->getPolicy($capability);
+ // NOTE: Column policies are enforced as an extended policy which makes
+ // them the same as the project's policies.
+ switch ($capability) {
+ case PhabricatorPolicyCapability::CAN_VIEW:
+ return PhabricatorPolicies::getMostOpenPolicy();
+ case PhabricatorPolicyCapability::CAN_EDIT:
+ return PhabricatorPolicies::POLICY_USER;
+ }
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
@@ -233,6 +241,16 @@
}
+/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
+
+
+ public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
+ return array(
+ array($this->getProject(), $capability),
+ );
+ }
+
+
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(

File Metadata

Mime Type
text/plain
Expires
Sun, May 12, 12:39 PM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6286996
Default Alt Text
D15268.id36840.diff (5 KB)

Event Timeline