From 32b1ffdf894c3d0bae2c9022900bbb53ec12455b Mon Sep 17 00:00:00 2001 From: Chad Little Date: Fri, 21 Nov 2014 11:22:17 -0800 Subject: [PATCH] Add default View, Edit, and Join Policies to Projects Summary: Fixes T6567, lets admins set a default policy for new Projects. Test Plan: Changed the default Policy, created a new Project. Project had correct defaults. Reviewers: btrahan, epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T6567 Differential Revision: https://secure.phabricator.com/D10890 --- src/__phutil_library_map__.php | 6 ++++++ .../PhabricatorProjectApplication.php | 12 ++++++++++++ .../ProjectDefaultEditCapability.php | 12 ++++++++++++ .../ProjectDefaultJoinCapability.php | 12 ++++++++++++ .../ProjectDefaultViewCapability.php | 15 +++++++++++++++ .../project/storage/PhabricatorProject.php | 18 +++++++++++++++--- 6 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/applications/project/capability/ProjectDefaultEditCapability.php create mode 100644 src/applications/project/capability/ProjectDefaultJoinCapability.php create mode 100644 src/applications/project/capability/ProjectDefaultViewCapability.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e793f9c0fb..addaf502a9 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2848,6 +2848,9 @@ phutil_register_library_map(array( 'ProjectConduitAPIMethod' => 'applications/project/conduit/ProjectConduitAPIMethod.php', 'ProjectCreateConduitAPIMethod' => 'applications/project/conduit/ProjectCreateConduitAPIMethod.php', 'ProjectCreateProjectsCapability' => 'applications/project/capability/ProjectCreateProjectsCapability.php', + 'ProjectDefaultEditCapability' => 'applications/project/capability/ProjectDefaultEditCapability.php', + 'ProjectDefaultJoinCapability' => 'applications/project/capability/ProjectDefaultJoinCapability.php', + 'ProjectDefaultViewCapability' => 'applications/project/capability/ProjectDefaultViewCapability.php', 'ProjectQueryConduitAPIMethod' => 'applications/project/conduit/ProjectQueryConduitAPIMethod.php', 'ProjectRemarkupRule' => 'applications/project/remarkup/ProjectRemarkupRule.php', 'ProjectRemarkupRuleTestCase' => 'applications/project/remarkup/__tests__/ProjectRemarkupRuleTestCase.php', @@ -6090,6 +6093,9 @@ phutil_register_library_map(array( 'ProjectConduitAPIMethod' => 'ConduitAPIMethod', 'ProjectCreateConduitAPIMethod' => 'ProjectConduitAPIMethod', 'ProjectCreateProjectsCapability' => 'PhabricatorPolicyCapability', + 'ProjectDefaultEditCapability' => 'PhabricatorPolicyCapability', + 'ProjectDefaultJoinCapability' => 'PhabricatorPolicyCapability', + 'ProjectDefaultViewCapability' => 'PhabricatorPolicyCapability', 'ProjectQueryConduitAPIMethod' => 'ProjectConduitAPIMethod', 'ProjectRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'ProjectRemarkupRuleTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/project/application/PhabricatorProjectApplication.php b/src/applications/project/application/PhabricatorProjectApplication.php index 0ea1a2f495..4d84b2af4e 100644 --- a/src/applications/project/application/PhabricatorProjectApplication.php +++ b/src/applications/project/application/PhabricatorProjectApplication.php @@ -98,6 +98,18 @@ final class PhabricatorProjectApplication extends PhabricatorApplication { ProjectCanLockProjectsCapability::CAPABILITY => array( 'default' => PhabricatorPolicies::POLICY_ADMIN, ), + ProjectDefaultViewCapability::CAPABILITY => array( + 'caption' => pht( + 'Default view policy for newly created projects.'), + ), + ProjectDefaultEditCapability::CAPABILITY => array( + 'caption' => pht( + 'Default edit policy for newly created projects.'), + ), + ProjectDefaultJoinCapability::CAPABILITY => array( + 'caption' => pht( + 'Default join policy for newly created projects.'), + ), ); } diff --git a/src/applications/project/capability/ProjectDefaultEditCapability.php b/src/applications/project/capability/ProjectDefaultEditCapability.php new file mode 100644 index 0000000000..ef631b1798 --- /dev/null +++ b/src/applications/project/capability/ProjectDefaultEditCapability.php @@ -0,0 +1,12 @@ +setViewer(PhabricatorUser::getOmnipotentUser()) + ->withClasses(array('PhabricatorProjectApplication')) + ->executeOne(); + + $view_policy = $app->getPolicy( + ProjectDefaultViewCapability::CAPABILITY); + $edit_policy = $app->getPolicy( + ProjectDefaultEditCapability::CAPABILITY); + $join_policy = $app->getPolicy( + ProjectDefaultJoinCapability::CAPABILITY); + return id(new PhabricatorProject()) ->setName('') ->setAuthorPHID($actor->getPHID()) ->setIcon(self::DEFAULT_ICON) ->setColor(self::DEFAULT_COLOR) - ->setViewPolicy(PhabricatorPolicies::POLICY_USER) - ->setEditPolicy(PhabricatorPolicies::POLICY_USER) - ->setJoinPolicy(PhabricatorPolicies::POLICY_USER) + ->setViewPolicy($view_policy) + ->setEditPolicy($edit_policy) + ->setJoinPolicy($join_policy) ->setIsMembershipLocked(0) ->attachMemberPHIDs(array()) ->attachSlugs(array());