diff --git a/src/applications/policy/editor/PhabricatorPolicyEditEngineExtension.php b/src/applications/policy/editor/PhabricatorPolicyEditEngineExtension.php index ce534195a5..1e97f59e24 100644 --- a/src/applications/policy/editor/PhabricatorPolicyEditEngineExtension.php +++ b/src/applications/policy/editor/PhabricatorPolicyEditEngineExtension.php @@ -1,123 +1,125 @@ getViewer(); $editor = $object->getApplicationTransactionEditor(); $types = $editor->getTransactionTypesForObject($object); $types = array_fuse($types); $policies = id(new PhabricatorPolicyQuery()) ->setViewer($viewer) ->setObject($object) ->execute(); $map = array( PhabricatorTransactions::TYPE_VIEW_POLICY => array( 'key' => 'policy.view', 'aliases' => array('view'), 'capability' => PhabricatorPolicyCapability::CAN_VIEW, 'label' => pht('View Policy'), 'description' => pht('Controls who can view the object.'), 'edit' => 'view', ), PhabricatorTransactions::TYPE_EDIT_POLICY => array( 'key' => 'policy.edit', 'aliases' => array('edit'), 'capability' => PhabricatorPolicyCapability::CAN_EDIT, 'label' => pht('Edit Policy'), 'description' => pht('Controls who can edit the object.'), 'edit' => 'edit', ), PhabricatorTransactions::TYPE_JOIN_POLICY => array( 'key' => 'policy.join', 'aliases' => array('join'), 'capability' => PhabricatorPolicyCapability::CAN_JOIN, 'label' => pht('Join Policy'), 'description' => pht('Controls who can join the object.'), 'edit' => 'join', ), ); $fields = array(); foreach ($map as $type => $spec) { if (empty($types[$type])) { continue; } $capability = $spec['capability']; $key = $spec['key']; $aliases = $spec['aliases']; $label = $spec['label']; $description = $spec['description']; $edit = $spec['edit']; $policy_field = id(new PhabricatorPolicyEditField()) ->setKey($key) ->setLabel($label) ->setAliases($aliases) ->setIsCopyable(true) ->setCapability($capability) ->setPolicies($policies) ->setTransactionType($type) ->setEditTypeKey($edit) ->setConduitDescription($description) ->setConduitTypeDescription(pht('New policy PHID or constant.')) ->setValue($object->getPolicy($capability)); $fields[] = $policy_field; if ($object instanceof PhabricatorSpacesInterface) { if ($capability == PhabricatorPolicyCapability::CAN_VIEW) { $type_space = PhabricatorTransactions::TYPE_SPACE; if (isset($types[$type_space])) { $space_field = id(new PhabricatorSpaceEditField()) ->setKey('spacePHID') ->setLabel(pht('Space')) ->setEditTypeKey('space') ->setIsCopyable(true) + ->setIsLockable(false) ->setIsReorderable(false) ->setAliases(array('space', 'policy.space')) ->setTransactionType($type_space) ->setDescription(pht('Select a space for the object.')) ->setConduitDescription( pht('Shift the object between spaces.')) ->setConduitTypeDescription(pht('New space PHID.')) ->setValue($object->getSpacePHID()); $fields[] = $space_field; + $space_field->setPolicyField($policy_field); $policy_field->setSpaceField($space_field); } } } } return $fields; } } diff --git a/src/applications/transactions/editfield/PhabricatorSpaceEditField.php b/src/applications/transactions/editfield/PhabricatorSpaceEditField.php index 6ad1e27831..ee15f0b19e 100644 --- a/src/applications/transactions/editfield/PhabricatorSpaceEditField.php +++ b/src/applications/transactions/editfield/PhabricatorSpaceEditField.php @@ -1,20 +1,40 @@ policyField = $policy_field; + return $this; + } + + public function getPolicyField() { + return $this->policyField; + } + protected function newControl() { // NOTE: This field doesn't do anything on its own, it just serves as a // companion to the associated View Policy field. return null; } protected function newHTTPParameterType() { return new AphrontPHIDHTTPParameterType(); } protected function newConduitParameterType() { return new ConduitPHIDParameterType(); } + + public function shouldReadValueFromRequest() { + return $this->getPolicyField()->shouldReadValueFromRequest(); + } + + public function shouldReadValueFromSubmit() { + return $this->getPolicyField()->shouldReadValueFromSubmit(); + } + }