@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.

Phriction - add viewPolicy and editPolicy back-end data

Summary: Ref T4029. this diff makes the pertinent database changes AND adds the migration script. This is important to get the data backend straightened away before we fully ship T4029. Next diff will expose the edit controls for these policies and whatever else work is needed to get that part done right.

Test Plan: made sure the lone project page on my wiki had a project with restrictive view policy. Post migration verified correct policy applied to this lone project page AND most open policy applied to the others

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T4029

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

+69 -13
+5
resources/sql/autopatches/20141107.phriction.policy.1.sql
··· 1 + ALTER TABLE {$NAMESPACE}_phriction.phriction_document 2 + ADD viewPolicy VARBINARY(64) NOT NULL; 3 + 4 + ALTER TABLE {$NAMESPACE}_phriction.phriction_document 5 + ADD editPolicy VARBINARY(64) NOT NULL;
+47
resources/sql/autopatches/20141107.phriction.policy.2.php
··· 1 + <?php 2 + 3 + $table = new PhrictionDocument(); 4 + $conn_w = $table->establishConnection('w'); 5 + 6 + echo "Populating Phriction policies.\n"; 7 + 8 + $default_view_policy = PhabricatorPolicies::getMostOpenPolicy(); 9 + $default_edit_policy = PhabricatorPolicies::POLICY_USER; 10 + 11 + foreach (new LiskMigrationIterator($table) as $doc) { 12 + $id = $doc->getID(); 13 + 14 + if ($doc->getViewPolicy() && $doc->getEditPolicy()) { 15 + echo "Skipping doc $id; already has policy set.\n"; 16 + continue; 17 + } 18 + 19 + // project documents get the project policy 20 + if (PhrictionDocument::isProjectSlug($doc->getSlug())) { 21 + 22 + $project_slug = 23 + PhrictionDocument::getProjectSlugIdentifier($doc->getSlug()); 24 + $project_slugs = array($project_slug); 25 + $project = id(new PhabricatorProjectQuery()) 26 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 27 + ->withPhrictionSlugs($project_slugs) 28 + ->executeOne(); 29 + 30 + $project_name = $project->getName(); 31 + echo "Migrating doc $id to project policy $project_name...\n"; 32 + $doc->setViewPolicy($project->getViewPolicy()); 33 + $doc->setEditPolicy($project->getEditPolicy()); 34 + $doc->save(); 35 + 36 + // non-project documents get the most open policy possible 37 + } else { 38 + 39 + echo "Migrating doc $id to default install policy...\n"; 40 + $doc->setViewPolicy($default_view_policy); 41 + $doc->setEditPolicy($default_edit_policy); 42 + $doc->save(); 43 + 44 + } 45 + } 46 + 47 + echo "Done.\n";
+2
src/applications/phriction/controller/PhrictionDocumentController.php
··· 199 199 } 200 200 201 201 $header = id(new PHUIHeaderView()) 202 + ->setUser($user) 203 + ->setPolicyObject($document) 202 204 ->setHeader($page_title); 203 205 204 206 $prop_list = null;
-2
src/applications/phriction/editor/PhrictionTransactionEditor.php
··· 83 83 $types[] = PhrictionTransaction::TYPE_MOVE_TO; 84 84 $types[] = PhrictionTransaction::TYPE_MOVE_AWAY; 85 85 86 - /* TODO 87 86 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 88 87 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 89 - */ 90 88 91 89 return $types; 92 90 }
+15 -11
src/applications/phriction/storage/PhrictionDocument.php
··· 13 13 protected $contentID; 14 14 protected $status; 15 15 protected $mailKey; 16 + protected $viewPolicy; 17 + protected $editPolicy; 16 18 17 19 private $contentObject = self::ATTACHABLE; 18 20 private $ancestors = array(); ··· 65 67 $default_title = PhabricatorSlug::getDefaultTitle($slug); 66 68 $content->setTitle($default_title); 67 69 $document->attachContent($content); 70 + 71 + $default_view_policy = PhabricatorPolicies::getMostOpenPolicy(); 72 + $document->setViewPolicy($default_view_policy); 73 + $document->setEditPolicy(PhabricatorPolicies::POLICY_USER); 68 74 69 75 return $document; 70 76 } ··· 172 178 } 173 179 174 180 public function getPolicy($capability) { 175 - if ($this->hasProject()) { 176 - return $this->getProject()->getPolicy($capability); 181 + switch ($capability) { 182 + case PhabricatorPolicyCapability::CAN_VIEW: 183 + return $this->getViewPolicy(); 184 + case PhabricatorPolicyCapability::CAN_EDIT: 185 + return $this->getEditPolicy(); 177 186 } 178 - 179 - return PhabricatorPolicies::POLICY_USER; 180 187 } 181 188 182 189 public function hasAutomaticCapability($capability, PhabricatorUser $user) { 183 - if ($this->hasProject()) { 184 - return $this->getProject()->hasAutomaticCapability($capability, $user); 185 - } 186 190 return false; 187 191 } 188 192 189 193 public function describeAutomaticCapability($capability) { 190 - if ($this->hasProject()) { 191 - return pht( 192 - "This is a project wiki page, and inherits the project's policies."); 193 - } 194 194 195 195 switch ($capability) { 196 196 case PhabricatorPolicyCapability::CAN_VIEW: 197 197 return pht( 198 198 'To view a wiki document, you must also be able to view all '. 199 + 'of its parents.'); 200 + case PhabricatorPolicyCapability::CAN_EDIT: 201 + return pht( 202 + 'To edit a wiki document, you must also be able to view all '. 199 203 'of its parents.'); 200 204 } 201 205