From 8a3b1b973041938911b49e482d54f60545ea2f50 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Fri, 7 Nov 2014 15:35:28 -0800 Subject: [PATCH] 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 --- .../20141107.phriction.policy.1.sql | 5 ++ .../20141107.phriction.policy.2.php | 47 +++++++++++++++++++ .../PhrictionDocumentController.php | 2 + .../editor/PhrictionTransactionEditor.php | 2 - .../phriction/storage/PhrictionDocument.php | 26 +++++----- 5 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 resources/sql/autopatches/20141107.phriction.policy.1.sql create mode 100644 resources/sql/autopatches/20141107.phriction.policy.2.php diff --git a/resources/sql/autopatches/20141107.phriction.policy.1.sql b/resources/sql/autopatches/20141107.phriction.policy.1.sql new file mode 100644 index 0000000000..ae466db0db --- /dev/null +++ b/resources/sql/autopatches/20141107.phriction.policy.1.sql @@ -0,0 +1,5 @@ +ALTER TABLE {$NAMESPACE}_phriction.phriction_document + ADD viewPolicy VARBINARY(64) NOT NULL; + +ALTER TABLE {$NAMESPACE}_phriction.phriction_document + ADD editPolicy VARBINARY(64) NOT NULL; diff --git a/resources/sql/autopatches/20141107.phriction.policy.2.php b/resources/sql/autopatches/20141107.phriction.policy.2.php new file mode 100644 index 0000000000..b55b7ebe0b --- /dev/null +++ b/resources/sql/autopatches/20141107.phriction.policy.2.php @@ -0,0 +1,47 @@ +establishConnection('w'); + +echo "Populating Phriction policies.\n"; + +$default_view_policy = PhabricatorPolicies::getMostOpenPolicy(); +$default_edit_policy = PhabricatorPolicies::POLICY_USER; + +foreach (new LiskMigrationIterator($table) as $doc) { + $id = $doc->getID(); + + if ($doc->getViewPolicy() && $doc->getEditPolicy()) { + echo "Skipping doc $id; already has policy set.\n"; + continue; + } + + // project documents get the project policy + if (PhrictionDocument::isProjectSlug($doc->getSlug())) { + + $project_slug = + PhrictionDocument::getProjectSlugIdentifier($doc->getSlug()); + $project_slugs = array($project_slug); + $project = id(new PhabricatorProjectQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withPhrictionSlugs($project_slugs) + ->executeOne(); + + $project_name = $project->getName(); + echo "Migrating doc $id to project policy $project_name...\n"; + $doc->setViewPolicy($project->getViewPolicy()); + $doc->setEditPolicy($project->getEditPolicy()); + $doc->save(); + + // non-project documents get the most open policy possible + } else { + + echo "Migrating doc $id to default install policy...\n"; + $doc->setViewPolicy($default_view_policy); + $doc->setEditPolicy($default_edit_policy); + $doc->save(); + + } +} + +echo "Done.\n"; diff --git a/src/applications/phriction/controller/PhrictionDocumentController.php b/src/applications/phriction/controller/PhrictionDocumentController.php index 2ace1a281c..f9dec06d03 100644 --- a/src/applications/phriction/controller/PhrictionDocumentController.php +++ b/src/applications/phriction/controller/PhrictionDocumentController.php @@ -199,6 +199,8 @@ final class PhrictionDocumentController } $header = id(new PHUIHeaderView()) + ->setUser($user) + ->setPolicyObject($document) ->setHeader($page_title); $prop_list = null; diff --git a/src/applications/phriction/editor/PhrictionTransactionEditor.php b/src/applications/phriction/editor/PhrictionTransactionEditor.php index 4564e817dc..bc838c8f03 100644 --- a/src/applications/phriction/editor/PhrictionTransactionEditor.php +++ b/src/applications/phriction/editor/PhrictionTransactionEditor.php @@ -83,10 +83,8 @@ final class PhrictionTransactionEditor $types[] = PhrictionTransaction::TYPE_MOVE_TO; $types[] = PhrictionTransaction::TYPE_MOVE_AWAY; - /* TODO $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; - */ return $types; } diff --git a/src/applications/phriction/storage/PhrictionDocument.php b/src/applications/phriction/storage/PhrictionDocument.php index c609dd5250..3a4a80bfe4 100644 --- a/src/applications/phriction/storage/PhrictionDocument.php +++ b/src/applications/phriction/storage/PhrictionDocument.php @@ -13,6 +13,8 @@ final class PhrictionDocument extends PhrictionDAO protected $contentID; protected $status; protected $mailKey; + protected $viewPolicy; + protected $editPolicy; private $contentObject = self::ATTACHABLE; private $ancestors = array(); @@ -66,6 +68,10 @@ final class PhrictionDocument extends PhrictionDAO $content->setTitle($default_title); $document->attachContent($content); + $default_view_policy = PhabricatorPolicies::getMostOpenPolicy(); + $document->setViewPolicy($default_view_policy); + $document->setEditPolicy(PhabricatorPolicies::POLICY_USER); + return $document; } @@ -172,31 +178,29 @@ final class PhrictionDocument extends PhrictionDAO } public function getPolicy($capability) { - if ($this->hasProject()) { - return $this->getProject()->getPolicy($capability); + switch ($capability) { + case PhabricatorPolicyCapability::CAN_VIEW: + return $this->getViewPolicy(); + case PhabricatorPolicyCapability::CAN_EDIT: + return $this->getEditPolicy(); } - - return PhabricatorPolicies::POLICY_USER; } public function hasAutomaticCapability($capability, PhabricatorUser $user) { - if ($this->hasProject()) { - return $this->getProject()->hasAutomaticCapability($capability, $user); - } return false; } public function describeAutomaticCapability($capability) { - if ($this->hasProject()) { - return pht( - "This is a project wiki page, and inherits the project's policies."); - } switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: return pht( 'To view a wiki document, you must also be able to view all '. 'of its parents.'); + case PhabricatorPolicyCapability::CAN_EDIT: + return pht( + 'To edit a wiki document, you must also be able to view all '. + 'of its parents.'); } return null; -- 2.51.2