1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

When predicting object policies for project milestones, adjust objects so they behave like milestones

Summary:
Ref T13462. Currently, when testing milestone edit policies during creation, the project object does not behave like a milestone:

  - it doesn't have a milestone number yet, so it doesn't try to access the parent project; and
  - the parent project isn't attached yet.

Instead: attach the parent project sooner (which "should" be harmless, although it's possible this has weird side effects); and give the adjusted policy object a dummy milestone number if it doesn't have one yet. This forces it to act like a milestone when emitting policies.

Test Plan:
  - Set "Projects" application default edit policy to "No One".
  - Created a milestone I had permission to create.
    - Before: failed with a policy error, because the project behaved like a non-milestone and returned "No One" as the effective edit policy.
    - After: worked properly, correctly evaluting the parent project edit policy as the effective edit policy.
  - Tried to create a milestone I did not have permission to create (no edit permission on parent project).
    - Got an appropriate edit policy error.

Maniphest Tasks: T13462

Differential Revision: https://secure.phabricator.com/D20919
This commit is contained in:
epriestley 2019-11-18 22:21:15 -08:00
parent de66a8ece1
commit 959504a488
3 changed files with 11 additions and 3 deletions

View file

@ -1537,8 +1537,7 @@ final class PhabricatorProjectCoreTestCase extends PhabricatorTestCase {
PhabricatorProject $parent = null,
$is_milestone = false) {
$project = PhabricatorProject::initializeNewProject($user);
$project = PhabricatorProject::initializeNewProject($user, $parent);
$name = pht('Test Project %d', mt_rand());

View file

@ -336,6 +336,15 @@ final class PhabricatorProjectTransactionEditor
$type_edge = PhabricatorTransactions::TYPE_EDGE;
$edgetype_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
// See T13462. If we're creating a milestone, set a dummy milestone
// number so the project behaves like a milestone and uses milestone
// policy rules. Otherwise, we'll end up checking the default policies
// (which are not relevant to milestones) instead of the parent project
// policies (which are the correct policies).
if ($this->getIsMilestone() && !$copy->isMilestone()) {
$copy->setMilestoneNumber(1);
}
$member_xaction = null;
foreach ($xactions as $xaction) {
if ($xaction->getTransactionType() !== $type_edge) {

View file

@ -107,7 +107,7 @@ final class PhabricatorProject extends PhabricatorProjectDAO
->setHasMilestones(0)
->setHasSubprojects(0)
->setSubtype(PhabricatorEditEngineSubtype::SUBTYPE_DEFAULT)
->attachParentProject(null);
->attachParentProject($parent);
}
public function getCapabilities() {