@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a "Thread Members" object policy and some unit tests

Summary:
Ref T8488. Ref T5681.

Now you can just use `id(new ConpherenceThreadMembersPolicyRule())->getObjectPolicyFullKey()` as a policy.

Added tests for TaskAuthor + ThreadMembers.

Test Plan:
- Ran tests.
- Set a thread policy to "Members of thread'.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5681, T8488

Differential Revision: https://secure.phabricator.com/D13258

+118 -1
+2
src/__phutil_library_map__.php
··· 256 256 'ConpherenceThreadIndexer' => 'applications/conpherence/search/ConpherenceThreadIndexer.php', 257 257 'ConpherenceThreadListView' => 'applications/conpherence/view/ConpherenceThreadListView.php', 258 258 'ConpherenceThreadMailReceiver' => 'applications/conpherence/mail/ConpherenceThreadMailReceiver.php', 259 + 'ConpherenceThreadMembersPolicyRule' => 'applications/conpherence/policyrule/ConpherenceThreadMembersPolicyRule.php', 259 260 'ConpherenceThreadQuery' => 'applications/conpherence/query/ConpherenceThreadQuery.php', 260 261 'ConpherenceThreadRemarkupRule' => 'applications/conpherence/remarkup/ConpherenceThreadRemarkupRule.php', 261 262 'ConpherenceThreadSearchEngine' => 'applications/conpherence/query/ConpherenceThreadSearchEngine.php', ··· 3542 3543 'ConpherenceThreadIndexer' => 'PhabricatorSearchDocumentIndexer', 3543 3544 'ConpherenceThreadListView' => 'AphrontView', 3544 3545 'ConpherenceThreadMailReceiver' => 'PhabricatorObjectMailReceiver', 3546 + 'ConpherenceThreadMembersPolicyRule' => 'PhabricatorPolicyRule', 3545 3547 'ConpherenceThreadQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 3546 3548 'ConpherenceThreadRemarkupRule' => 'PhabricatorObjectRemarkupRule', 3547 3549 'ConpherenceThreadSearchEngine' => 'PhabricatorApplicationSearchEngine',
+42
src/applications/conpherence/policyrule/ConpherenceThreadMembersPolicyRule.php
··· 1 + <?php 2 + 3 + final class ConpherenceThreadMembersPolicyRule 4 + extends PhabricatorPolicyRule { 5 + 6 + public function getObjectPolicyKey() { 7 + return 'conpherence.members'; 8 + } 9 + 10 + public function getObjectPolicyName() { 11 + return pht('Thread Members'); 12 + } 13 + 14 + public function getPolicyExplanation() { 15 + return pht('Members of this thread can take this action.'); 16 + } 17 + 18 + public function getRuleDescription() { 19 + return pht('thread members'); 20 + } 21 + 22 + public function canApplyToObject(PhabricatorPolicyInterface $object) { 23 + return ($object instanceof ConpherenceThread); 24 + } 25 + 26 + public function applyRule( 27 + PhabricatorUser $viewer, 28 + $value, 29 + PhabricatorPolicyInterface $object) { 30 + $viewer_phid = $viewer->getPHID(); 31 + if (!$viewer_phid) { 32 + return false; 33 + } 34 + 35 + return (bool)$object->getParticipantIfExists($viewer_phid); 36 + } 37 + 38 + public function getValueControlType() { 39 + return self::CONTROL_TYPE_NONE; 40 + } 41 + 42 + }
+59
src/applications/policy/__tests__/PhabricatorPolicyDataTestCase.php
··· 150 150 unset($time_b); 151 151 } 152 152 153 + public function testObjectPolicyRuleTaskAuthor() { 154 + $author = $this->generateNewTestUser(); 155 + $viewer = $this->generateNewTestUser(); 156 + 157 + $rule = new ManiphestTaskAuthorPolicyRule(); 158 + 159 + $task = ManiphestTask::initializeNewTask($author); 160 + $task->setViewPolicy($rule->getObjectPolicyFullKey()); 161 + $task->save(); 162 + 163 + $this->assertTrue( 164 + PhabricatorPolicyFilter::hasCapability( 165 + $author, 166 + $task, 167 + PhabricatorPolicyCapability::CAN_VIEW)); 168 + 169 + $this->assertFalse( 170 + PhabricatorPolicyFilter::hasCapability( 171 + $viewer, 172 + $task, 173 + PhabricatorPolicyCapability::CAN_VIEW)); 174 + } 175 + 176 + public function testObjectPolicyRuleThreadMembers() { 177 + $author = $this->generateNewTestUser(); 178 + $viewer = $this->generateNewTestUser(); 179 + 180 + $rule = new ConpherenceThreadMembersPolicyRule(); 181 + 182 + $thread = ConpherenceThread::initializeNewRoom($author); 183 + $thread->setViewPolicy($rule->getObjectPolicyFullKey()); 184 + $thread->save(); 185 + 186 + $this->assertFalse( 187 + PhabricatorPolicyFilter::hasCapability( 188 + $author, 189 + $thread, 190 + PhabricatorPolicyCapability::CAN_VIEW)); 191 + 192 + $this->assertFalse( 193 + PhabricatorPolicyFilter::hasCapability( 194 + $viewer, 195 + $thread, 196 + PhabricatorPolicyCapability::CAN_VIEW)); 197 + 198 + $participant = id(new ConpherenceParticipant()) 199 + ->setParticipantPHID($viewer->getPHID()) 200 + ->setConpherencePHID($thread->getPHID()); 201 + 202 + $thread->attachParticipants(array($viewer->getPHID() => $participant)); 203 + 204 + $this->assertTrue( 205 + PhabricatorPolicyFilter::hasCapability( 206 + $viewer, 207 + $thread, 208 + PhabricatorPolicyCapability::CAN_VIEW)); 209 + } 210 + 211 + 153 212 }
+1 -1
src/applications/policy/query/PhabricatorPolicyQuery.php
··· 316 316 continue; 317 317 } 318 318 319 - $full_key = self::OBJECT_POLICY_PREFIX.$key; 319 + $full_key = $rule->getObjectPolicyFullKey(); 320 320 if (isset($results[$full_key])) { 321 321 throw new Exception( 322 322 pht(
+14
src/applications/policy/rule/PhabricatorPolicyRule.php
··· 114 114 return null; 115 115 } 116 116 117 + public function getObjectPolicyFullKey() { 118 + $key = $this->getObjectPolicyKey(); 119 + 120 + if (!$key) { 121 + throw new Exception( 122 + pht( 123 + 'This policy rule (of class "%s") does not have an associated '. 124 + 'object policy key.', 125 + get_class($this))); 126 + } 127 + 128 + return PhabricatorPolicyQuery::OBJECT_POLICY_PREFIX.$key; 129 + } 130 + 117 131 public function getObjectPolicyName() { 118 132 throw new PhutilMethodNotImplementedException(); 119 133 }