1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

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
This commit is contained in:
Asher Baker 2013-10-10 04:29:07 -07:00 committed by epriestley
parent c39b10aa7a
commit 8cc64a9678
5 changed files with 38 additions and 1 deletions

View file

@ -2018,6 +2018,7 @@ phutil_register_library_map(array(
'PonderVote' => 'applications/ponder/constants/PonderVote.php', 'PonderVote' => 'applications/ponder/constants/PonderVote.php',
'PonderVoteEditor' => 'applications/ponder/editor/PonderVoteEditor.php', 'PonderVoteEditor' => 'applications/ponder/editor/PonderVoteEditor.php',
'PonderVoteSaveController' => 'applications/ponder/controller/PonderVoteSaveController.php', 'PonderVoteSaveController' => 'applications/ponder/controller/PonderVoteSaveController.php',
'ProjectCapabilityCreateProjects' => 'applications/project/capability/ProjectCapabilityCreateProjects.php',
'ProjectRemarkupRule' => 'applications/project/remarkup/ProjectRemarkupRule.php', 'ProjectRemarkupRule' => 'applications/project/remarkup/ProjectRemarkupRule.php',
'QueryFormattingTestCase' => 'infrastructure/storage/__tests__/QueryFormattingTestCase.php', 'QueryFormattingTestCase' => 'infrastructure/storage/__tests__/QueryFormattingTestCase.php',
'ReleephAuthorFieldSpecification' => 'applications/releeph/field/specification/ReleephAuthorFieldSpecification.php', 'ReleephAuthorFieldSpecification' => 'applications/releeph/field/specification/ReleephAuthorFieldSpecification.php',
@ -4309,6 +4310,7 @@ phutil_register_library_map(array(
'PonderVote' => 'PonderConstants', 'PonderVote' => 'PonderConstants',
'PonderVoteEditor' => 'PhabricatorEditor', 'PonderVoteEditor' => 'PhabricatorEditor',
'PonderVoteSaveController' => 'PonderController', 'PonderVoteSaveController' => 'PonderController',
'ProjectCapabilityCreateProjects' => 'PhabricatorPolicyCapability',
'ProjectRemarkupRule' => 'PhabricatorRemarkupRuleObject', 'ProjectRemarkupRule' => 'PhabricatorRemarkupRuleObject',
'QueryFormattingTestCase' => 'PhabricatorTestCase', 'QueryFormattingTestCase' => 'PhabricatorTestCase',
'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification', 'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification',

View file

@ -49,4 +49,11 @@ final class PhabricatorApplicationProject extends PhabricatorApplication {
); );
} }
protected function getCustomCapabilities() {
return array(
ProjectCapabilityCreateProjects::CAPABILITY => array(
),
);
}
} }

View file

@ -0,0 +1,20 @@
<?php
final class ProjectCapabilityCreateProjects
extends PhabricatorPolicyCapability {
const CAPABILITY = 'project.create';
public function getCapabilityKey() {
return self::CAPABILITY;
}
public function getCapabilityName() {
return pht('Can Create Projects');
}
public function describeCapabilityRejection() {
return pht('You do not have permission to create new projects.');
}
}

View file

@ -24,11 +24,16 @@ abstract class PhabricatorProjectController extends PhabricatorController {
public function buildApplicationCrumbs() { public function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs(); $crumbs = parent::buildApplicationCrumbs();
$can_create = $this->hasApplicationCapability(
ProjectCapabilityCreateProjects::CAPABILITY);
$crumbs->addAction( $crumbs->addAction(
id(new PHUIListItemView()) id(new PHUIListItemView())
->setName(pht('Create Project')) ->setName(pht('Create Project'))
->setHref($this->getApplicationURI('create/')) ->setHref($this->getApplicationURI('create/'))
->setIcon('create')); ->setIcon('create')
->setWorkflow(!$can_create)
->setDisabled(!$can_create));
return $crumbs; return $crumbs;
} }

View file

@ -9,6 +9,9 @@ final class PhabricatorProjectCreateController
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
$this->requireApplicationCapability(
ProjectCapabilityCreateProjects::CAPABILITY);
$project = new PhabricatorProject(); $project = new PhabricatorProject();
$project->setAuthorPHID($user->getPHID()); $project->setAuthorPHID($user->getPHID());
$project->attachMemberPHIDs(array()); $project->attachMemberPHIDs(array());