From 8cc64a96789b3581fa49a5cec3c39f70d45f29e6 Mon Sep 17 00:00:00 2001 From: Asher Baker Date: Thu, 10 Oct 2013 04:29:07 -0700 Subject: [PATCH] Add a 'create' policy to Project Summary: UX on this could probably be better 'disabled' crumbs don't appear to have any visible difference, and the policy error has to load the /create page rather than being a modal - not sure on the way to fix these. Test Plan: Tried to create a project with and without access, saw suitable error. Reviewers: epriestley, #blessed_reviewers CC: Korvin, epriestley, aran Differential Revision: https://secure.phabricator.com/D7279 --- src/__phutil_library_map__.php | 2 ++ .../PhabricatorApplicationProject.php | 7 +++++++ .../ProjectCapabilityCreateProjects.php | 20 +++++++++++++++++++ .../PhabricatorProjectController.php | 7 ++++++- .../PhabricatorProjectCreateController.php | 3 +++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/applications/project/capability/ProjectCapabilityCreateProjects.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 5ca6db4847..513ab86945 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2018,6 +2018,7 @@ phutil_register_library_map(array( 'PonderVote' => 'applications/ponder/constants/PonderVote.php', 'PonderVoteEditor' => 'applications/ponder/editor/PonderVoteEditor.php', 'PonderVoteSaveController' => 'applications/ponder/controller/PonderVoteSaveController.php', + 'ProjectCapabilityCreateProjects' => 'applications/project/capability/ProjectCapabilityCreateProjects.php', 'ProjectRemarkupRule' => 'applications/project/remarkup/ProjectRemarkupRule.php', 'QueryFormattingTestCase' => 'infrastructure/storage/__tests__/QueryFormattingTestCase.php', 'ReleephAuthorFieldSpecification' => 'applications/releeph/field/specification/ReleephAuthorFieldSpecification.php', @@ -4309,6 +4310,7 @@ phutil_register_library_map(array( 'PonderVote' => 'PonderConstants', 'PonderVoteEditor' => 'PhabricatorEditor', 'PonderVoteSaveController' => 'PonderController', + 'ProjectCapabilityCreateProjects' => 'PhabricatorPolicyCapability', 'ProjectRemarkupRule' => 'PhabricatorRemarkupRuleObject', 'QueryFormattingTestCase' => 'PhabricatorTestCase', 'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification', diff --git a/src/applications/project/application/PhabricatorApplicationProject.php b/src/applications/project/application/PhabricatorApplicationProject.php index 9ef71d2a6b..22d8faa7f1 100644 --- a/src/applications/project/application/PhabricatorApplicationProject.php +++ b/src/applications/project/application/PhabricatorApplicationProject.php @@ -49,4 +49,11 @@ final class PhabricatorApplicationProject extends PhabricatorApplication { ); } + protected function getCustomCapabilities() { + return array( + ProjectCapabilityCreateProjects::CAPABILITY => array( + ), + ); + } + } diff --git a/src/applications/project/capability/ProjectCapabilityCreateProjects.php b/src/applications/project/capability/ProjectCapabilityCreateProjects.php new file mode 100644 index 0000000000..b46f40b749 --- /dev/null +++ b/src/applications/project/capability/ProjectCapabilityCreateProjects.php @@ -0,0 +1,20 @@ +hasApplicationCapability( + ProjectCapabilityCreateProjects::CAPABILITY); + $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('Create Project')) ->setHref($this->getApplicationURI('create/')) - ->setIcon('create')); + ->setIcon('create') + ->setWorkflow(!$can_create) + ->setDisabled(!$can_create)); return $crumbs; } diff --git a/src/applications/project/controller/PhabricatorProjectCreateController.php b/src/applications/project/controller/PhabricatorProjectCreateController.php index 137c1ae086..9c3b214101 100644 --- a/src/applications/project/controller/PhabricatorProjectCreateController.php +++ b/src/applications/project/controller/PhabricatorProjectCreateController.php @@ -9,6 +9,9 @@ final class PhabricatorProjectCreateController $request = $this->getRequest(); $user = $request->getUser(); + $this->requireApplicationCapability( + ProjectCapabilityCreateProjects::CAPABILITY); + $project = new PhabricatorProject(); $project->setAuthorPHID($user->getPHID()); $project->attachMemberPHIDs(array());