mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 13:00:56 +01:00
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
This commit is contained in:
parent
1a8d87699c
commit
32b1ffdf89
6 changed files with 72 additions and 3 deletions
|
@ -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',
|
||||
|
|
|
@ -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.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class ProjectDefaultEditCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'project.default.edit';
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Edit Policy');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class ProjectDefaultJoinCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'project.default.join';
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Join Policy');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
final class ProjectDefaultViewCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'project.default.view';
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default View Policy');
|
||||
}
|
||||
|
||||
public function shouldAllowPublicPolicySetting() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -36,14 +36,26 @@ final class PhabricatorProject extends PhabricatorProjectDAO
|
|||
const TABLE_DATASOURCE_TOKEN = 'project_datasourcetoken';
|
||||
|
||||
public static function initializeNewProject(PhabricatorUser $actor) {
|
||||
$app = id(new PhabricatorApplicationQuery())
|
||||
->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());
|
||||
|
|
Loading…
Reference in a new issue