mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-22 03:29:11 +01: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:
parent
c39b10aa7a
commit
8cc64a9678
5 changed files with 38 additions and 1 deletions
|
@ -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',
|
||||
|
|
|
@ -49,4 +49,11 @@ final class PhabricatorApplicationProject extends PhabricatorApplication {
|
|||
);
|
||||
}
|
||||
|
||||
protected function getCustomCapabilities() {
|
||||
return array(
|
||||
ProjectCapabilityCreateProjects::CAPABILITY => array(
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
|
||||
}
|
|
@ -24,11 +24,16 @@ abstract class PhabricatorProjectController extends PhabricatorController {
|
|||
public function buildApplicationCrumbs() {
|
||||
$crumbs = parent::buildApplicationCrumbs();
|
||||
|
||||
$can_create = $this->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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Reference in a new issue