mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-21 03:08:40 +01:00
Summary: Ref T9132. Ref T9908. Fixes T5622. This allows you to copy some fields (projects, subscribers, custom fields, some per-application) from another object when creating a new object by passing the `?template=xyz` parameter. Extend "copy" support to work with all custom fields. Test Plan: - Created new pastes, packages, tasks using `?template=...` - Viewed new template docs page. Reviewers: chad Reviewed By: chad Maniphest Tasks: T5622, T9132, T9908 Differential Revision: https://secure.phabricator.com/D14699
120 lines
3.6 KiB
PHP
120 lines
3.6 KiB
PHP
<?php
|
|
|
|
final class PhabricatorPolicyEditEngineExtension
|
|
extends PhabricatorEditEngineExtension {
|
|
|
|
const EXTENSIONKEY = 'policy.policy';
|
|
|
|
public function getExtensionPriority() {
|
|
return 250;
|
|
}
|
|
|
|
public function isExtensionEnabled() {
|
|
return true;
|
|
}
|
|
|
|
public function getExtensionName() {
|
|
return pht('Policies');
|
|
}
|
|
|
|
public function supportsObject(
|
|
PhabricatorEditEngine $engine,
|
|
PhabricatorApplicationTransactionInterface $object) {
|
|
return ($object instanceof PhabricatorPolicyInterface);
|
|
}
|
|
|
|
public function buildCustomEditFields(
|
|
PhabricatorEditEngine $engine,
|
|
PhabricatorApplicationTransactionInterface $object) {
|
|
|
|
$viewer = $engine->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)
|
|
->setDescription($description)
|
|
->setAliases($aliases)
|
|
->setIsCopyable(true)
|
|
->setCapability($capability)
|
|
->setPolicies($policies)
|
|
->setTransactionType($type)
|
|
->setEditTypeKey($edit)
|
|
->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')
|
|
->setDescription(
|
|
pht('Shifts the object in the Spaces application.'))
|
|
->setIsCopyable(true)
|
|
->setIsReorderable(false)
|
|
->setAliases(array('space', 'policy.space'))
|
|
->setTransactionType($type_space)
|
|
->setValue($object->getSpacePHID());
|
|
$fields[] = $space_field;
|
|
|
|
$policy_field->setSpaceField($space_field);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
}
|