1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 17:30:59 +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:
Chad Little 2014-11-21 11:22:17 -08:00
parent 1a8d87699c
commit 32b1ffdf89
6 changed files with 72 additions and 3 deletions

View file

@ -2848,6 +2848,9 @@ phutil_register_library_map(array(
'ProjectConduitAPIMethod' => 'applications/project/conduit/ProjectConduitAPIMethod.php', 'ProjectConduitAPIMethod' => 'applications/project/conduit/ProjectConduitAPIMethod.php',
'ProjectCreateConduitAPIMethod' => 'applications/project/conduit/ProjectCreateConduitAPIMethod.php', 'ProjectCreateConduitAPIMethod' => 'applications/project/conduit/ProjectCreateConduitAPIMethod.php',
'ProjectCreateProjectsCapability' => 'applications/project/capability/ProjectCreateProjectsCapability.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', 'ProjectQueryConduitAPIMethod' => 'applications/project/conduit/ProjectQueryConduitAPIMethod.php',
'ProjectRemarkupRule' => 'applications/project/remarkup/ProjectRemarkupRule.php', 'ProjectRemarkupRule' => 'applications/project/remarkup/ProjectRemarkupRule.php',
'ProjectRemarkupRuleTestCase' => 'applications/project/remarkup/__tests__/ProjectRemarkupRuleTestCase.php', 'ProjectRemarkupRuleTestCase' => 'applications/project/remarkup/__tests__/ProjectRemarkupRuleTestCase.php',
@ -6090,6 +6093,9 @@ phutil_register_library_map(array(
'ProjectConduitAPIMethod' => 'ConduitAPIMethod', 'ProjectConduitAPIMethod' => 'ConduitAPIMethod',
'ProjectCreateConduitAPIMethod' => 'ProjectConduitAPIMethod', 'ProjectCreateConduitAPIMethod' => 'ProjectConduitAPIMethod',
'ProjectCreateProjectsCapability' => 'PhabricatorPolicyCapability', 'ProjectCreateProjectsCapability' => 'PhabricatorPolicyCapability',
'ProjectDefaultEditCapability' => 'PhabricatorPolicyCapability',
'ProjectDefaultJoinCapability' => 'PhabricatorPolicyCapability',
'ProjectDefaultViewCapability' => 'PhabricatorPolicyCapability',
'ProjectQueryConduitAPIMethod' => 'ProjectConduitAPIMethod', 'ProjectQueryConduitAPIMethod' => 'ProjectConduitAPIMethod',
'ProjectRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'ProjectRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'ProjectRemarkupRuleTestCase' => 'PhabricatorTestCase', 'ProjectRemarkupRuleTestCase' => 'PhabricatorTestCase',

View file

@ -98,6 +98,18 @@ final class PhabricatorProjectApplication extends PhabricatorApplication {
ProjectCanLockProjectsCapability::CAPABILITY => array( ProjectCanLockProjectsCapability::CAPABILITY => array(
'default' => PhabricatorPolicies::POLICY_ADMIN, '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.'),
),
); );
} }

View file

@ -0,0 +1,12 @@
<?php
final class ProjectDefaultEditCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'project.default.edit';
public function getCapabilityName() {
return pht('Default Edit Policy');
}
}

View file

@ -0,0 +1,12 @@
<?php
final class ProjectDefaultJoinCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'project.default.join';
public function getCapabilityName() {
return pht('Default Join Policy');
}
}

View file

@ -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;
}
}

View file

@ -36,14 +36,26 @@ final class PhabricatorProject extends PhabricatorProjectDAO
const TABLE_DATASOURCE_TOKEN = 'project_datasourcetoken'; const TABLE_DATASOURCE_TOKEN = 'project_datasourcetoken';
public static function initializeNewProject(PhabricatorUser $actor) { 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()) return id(new PhabricatorProject())
->setName('') ->setName('')
->setAuthorPHID($actor->getPHID()) ->setAuthorPHID($actor->getPHID())
->setIcon(self::DEFAULT_ICON) ->setIcon(self::DEFAULT_ICON)
->setColor(self::DEFAULT_COLOR) ->setColor(self::DEFAULT_COLOR)
->setViewPolicy(PhabricatorPolicies::POLICY_USER) ->setViewPolicy($view_policy)
->setEditPolicy(PhabricatorPolicies::POLICY_USER) ->setEditPolicy($edit_policy)
->setJoinPolicy(PhabricatorPolicies::POLICY_USER) ->setJoinPolicy($join_policy)
->setIsMembershipLocked(0) ->setIsMembershipLocked(0)
->attachMemberPHIDs(array()) ->attachMemberPHIDs(array())
->attachSlugs(array()); ->attachSlugs(array());