2016-01-12 10:27:39 -08:00
|
|
|
<?php
|
|
|
|
|
2016-12-11 09:38:06 -08:00
|
|
|
final class PhabricatorProfileMenuItemConfiguration
|
2016-01-12 10:27:39 -08:00
|
|
|
extends PhabricatorSearchDAO
|
|
|
|
implements
|
|
|
|
PhabricatorPolicyInterface,
|
2016-01-12 15:06:43 -08:00
|
|
|
PhabricatorExtendedPolicyInterface,
|
|
|
|
PhabricatorApplicationTransactionInterface {
|
2016-01-12 10:27:39 -08:00
|
|
|
|
|
|
|
protected $profilePHID;
|
2016-12-11 09:38:06 -08:00
|
|
|
protected $menuItemKey;
|
2016-01-12 10:27:39 -08:00
|
|
|
protected $builtinKey;
|
2016-12-11 09:38:06 -08:00
|
|
|
protected $menuItemOrder;
|
2016-01-12 15:06:43 -08:00
|
|
|
protected $visibility;
|
2017-01-06 20:12:57 -08:00
|
|
|
protected $customPHID;
|
2016-12-11 09:38:06 -08:00
|
|
|
protected $menuItemProperties = array();
|
2016-01-12 10:27:39 -08:00
|
|
|
|
|
|
|
private $profileObject = self::ATTACHABLE;
|
2016-12-11 10:08:26 -08:00
|
|
|
private $menuItem = self::ATTACHABLE;
|
2016-01-12 10:27:39 -08:00
|
|
|
|
2016-01-22 05:33:21 -08:00
|
|
|
const VISIBILITY_DEFAULT = 'default';
|
2016-01-12 15:06:43 -08:00
|
|
|
const VISIBILITY_VISIBLE = 'visible';
|
|
|
|
const VISIBILITY_DISABLED = 'disabled';
|
|
|
|
|
2016-12-11 09:38:06 -08:00
|
|
|
public function getTableName() {
|
|
|
|
// For now, this class uses an older table name.
|
|
|
|
return 'search_profilepanelconfiguration';
|
|
|
|
}
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
public static function initializeNewBuiltin() {
|
|
|
|
return id(new self())
|
|
|
|
->setVisibility(self::VISIBILITY_VISIBLE);
|
|
|
|
}
|
|
|
|
|
2016-12-11 10:08:26 -08:00
|
|
|
public static function initializeNewItem(
|
2016-01-14 05:59:25 -08:00
|
|
|
$profile_object,
|
2017-01-10 11:20:26 -08:00
|
|
|
PhabricatorProfileMenuItem $item,
|
|
|
|
$custom_phid) {
|
2016-01-12 10:27:39 -08:00
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
return self::initializeNewBuiltin()
|
2016-01-12 10:27:39 -08:00
|
|
|
->setProfilePHID($profile_object->getPHID())
|
2016-12-11 10:08:26 -08:00
|
|
|
->setMenuItemKey($item->getMenuItemKey())
|
|
|
|
->attachMenuItem($item)
|
2017-01-10 11:20:26 -08:00
|
|
|
->attachProfileObject($profile_object)
|
|
|
|
->setCustomPHID($custom_phid);
|
2016-01-12 10:27:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
|
|
|
self::CONFIG_SERIALIZATION => array(
|
2016-12-11 09:38:06 -08:00
|
|
|
'menuItemProperties' => self::SERIALIZATION_JSON,
|
2016-01-12 10:27:39 -08:00
|
|
|
),
|
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
2016-12-11 09:38:06 -08:00
|
|
|
'menuItemKey' => 'text64',
|
2016-01-12 15:06:43 -08:00
|
|
|
'builtinKey' => 'text64?',
|
2016-12-11 09:38:06 -08:00
|
|
|
'menuItemOrder' => 'uint32?',
|
2017-01-06 20:12:57 -08:00
|
|
|
'customPHID' => 'phid?',
|
2016-01-12 15:06:43 -08:00
|
|
|
'visibility' => 'text32',
|
2016-01-12 10:27:39 -08:00
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_profile' => array(
|
2016-12-11 09:38:06 -08:00
|
|
|
'columns' => array('profilePHID', 'menuItemOrder'),
|
2016-01-12 10:27:39 -08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
public function generatePHID() {
|
|
|
|
return PhabricatorPHID::generateNewPHID(
|
2016-12-11 09:38:06 -08:00
|
|
|
PhabricatorProfileMenuItemPHIDType::TYPECONST);
|
2016-01-12 15:06:43 -08:00
|
|
|
}
|
|
|
|
|
2016-12-11 10:08:26 -08:00
|
|
|
public function attachMenuItem(PhabricatorProfileMenuItem $item) {
|
|
|
|
$this->menuItem = $item;
|
2016-01-12 10:27:39 -08:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-12-11 10:08:26 -08:00
|
|
|
public function getMenuItem() {
|
|
|
|
return $this->assertAttached($this->menuItem);
|
2016-01-12 10:27:39 -08:00
|
|
|
}
|
|
|
|
|
2016-01-14 05:59:25 -08:00
|
|
|
public function attachProfileObject($profile_object) {
|
2016-01-12 10:27:39 -08:00
|
|
|
$this->profileObject = $profile_object;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProfileObject() {
|
|
|
|
return $this->assertAttached($this->profileObject);
|
|
|
|
}
|
|
|
|
|
2016-12-11 09:38:06 -08:00
|
|
|
public function setMenuItemProperty($key, $value) {
|
|
|
|
$this->menuItemProperties[$key] = $value;
|
2016-01-12 10:27:39 -08:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-12-11 09:38:06 -08:00
|
|
|
public function getMenuItemProperty($key, $default = null) {
|
|
|
|
return idx($this->menuItemProperties, $key, $default);
|
2016-01-12 10:27:39 -08:00
|
|
|
}
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
public function buildNavigationMenuItems() {
|
2016-12-11 10:08:26 -08:00
|
|
|
return $this->getMenuItem()->buildNavigationMenuItems($this);
|
2016-01-12 15:06:43 -08:00
|
|
|
}
|
|
|
|
|
2016-12-11 10:08:26 -08:00
|
|
|
public function getMenuItemTypeName() {
|
|
|
|
return $this->getMenuItem()->getMenuItemTypeName();
|
2016-01-12 15:06:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getDisplayName() {
|
2016-12-11 10:08:26 -08:00
|
|
|
return $this->getMenuItem()->getDisplayName($this);
|
2016-01-12 15:06:43 -08:00
|
|
|
}
|
|
|
|
|
2016-01-22 05:33:21 -08:00
|
|
|
public function canMakeDefault() {
|
2016-12-11 10:08:26 -08:00
|
|
|
return $this->getMenuItem()->canMakeDefault($this);
|
2016-01-22 05:33:21 -08:00
|
|
|
}
|
|
|
|
|
2016-12-11 09:38:06 -08:00
|
|
|
public function canHideMenuItem() {
|
2016-12-11 10:08:26 -08:00
|
|
|
return $this->getMenuItem()->canHideMenuItem($this);
|
2016-01-25 03:21:36 -08:00
|
|
|
}
|
|
|
|
|
2016-02-06 12:48:01 -08:00
|
|
|
public function shouldEnableForObject($object) {
|
2016-12-11 10:08:26 -08:00
|
|
|
return $this->getMenuItem()->shouldEnableForObject($object);
|
2016-02-06 12:48:01 -08:00
|
|
|
}
|
|
|
|
|
2016-12-15 14:22:42 -08:00
|
|
|
public function willBuildNavigationItems(array $items) {
|
|
|
|
return $this->getMenuItem()->willBuildNavigationItems($items);
|
|
|
|
}
|
|
|
|
|
2017-01-20 11:03:09 -08:00
|
|
|
public function validateTransactions(array $map) {
|
|
|
|
$item = $this->getMenuItem();
|
|
|
|
|
|
|
|
$fields = $item->buildEditEngineFields($this);
|
|
|
|
$errors = array();
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
$field_key = $field->getKey();
|
|
|
|
|
|
|
|
$xactions = idx($map, $field_key, array());
|
|
|
|
$value = $this->getMenuItemProperty($field_key);
|
|
|
|
|
|
|
|
$field_errors = $item->validateTransactions(
|
|
|
|
$this,
|
|
|
|
$field_key,
|
|
|
|
$value,
|
|
|
|
$xactions);
|
|
|
|
foreach ($field_errors as $error) {
|
|
|
|
$errors[] = $error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
2017-01-17 12:46:05 -08:00
|
|
|
public function getSortVector() {
|
|
|
|
// Sort custom items above global items.
|
|
|
|
if ($this->getCustomPHID()) {
|
|
|
|
$is_global = 0;
|
|
|
|
} else {
|
|
|
|
$is_global = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort items with an explicit order above items without an explicit order,
|
|
|
|
// so any newly created builtins go to the bottom.
|
2016-12-11 09:38:06 -08:00
|
|
|
$order = $this->getMenuItemOrder();
|
2017-01-17 12:46:05 -08:00
|
|
|
if ($order !== null) {
|
|
|
|
$has_order = 0;
|
2016-01-13 09:40:27 -08:00
|
|
|
} else {
|
2017-01-17 12:46:05 -08:00
|
|
|
$has_order = 1;
|
2016-01-13 09:40:27 -08:00
|
|
|
}
|
|
|
|
|
2017-01-17 12:46:05 -08:00
|
|
|
return id(new PhutilSortVector())
|
|
|
|
->addInt($is_global)
|
|
|
|
->addInt($has_order)
|
|
|
|
->addInt((int)$order)
|
|
|
|
->addInt((int)$this->getID());
|
2016-01-13 09:40:27 -08:00
|
|
|
}
|
|
|
|
|
2016-01-13 10:40:31 -08:00
|
|
|
public function isDisabled() {
|
2016-12-11 09:38:06 -08:00
|
|
|
if (!$this->canHideMenuItem()) {
|
2016-01-25 03:21:36 -08:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-13 10:40:31 -08:00
|
|
|
return ($this->getVisibility() === self::VISIBILITY_DISABLED);
|
|
|
|
}
|
|
|
|
|
2016-01-22 05:33:21 -08:00
|
|
|
public function isDefault() {
|
|
|
|
return ($this->getVisibility() === self::VISIBILITY_DEFAULT);
|
|
|
|
}
|
|
|
|
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 12:14:02 -08:00
|
|
|
public function getItemIdentifier() {
|
|
|
|
$id = $this->getID();
|
|
|
|
|
|
|
|
if ($id) {
|
|
|
|
return (int)$id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getBuiltinKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newPageContent() {
|
|
|
|
return $this->getMenuItem()->newPageContent($this);
|
|
|
|
}
|
2016-01-12 10:27:39 -08:00
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
return PhabricatorPolicies::getMostOpenPolicy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return $this->getProfileObject()->hasAutomaticCapability(
|
|
|
|
$capability,
|
|
|
|
$viewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
|
2017-01-19 11:06:42 -08:00
|
|
|
// If this is an item with a custom PHID (like a personal menu item),
|
|
|
|
// we only require that the user can edit the corresponding custom
|
|
|
|
// object (usually their own user profile), not the object that the
|
|
|
|
// menu appears on (which may be an Application like Favorites or Home).
|
|
|
|
if ($capability == PhabricatorPolicyCapability::CAN_EDIT) {
|
|
|
|
if ($this->getCustomPHID()) {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
$this->getCustomPHID(),
|
|
|
|
$capability,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-12 10:27:39 -08:00
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
$this->getProfileObject(),
|
|
|
|
$capability,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
|
|
|
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getApplicationTransactionEditor() {
|
2016-12-11 09:38:06 -08:00
|
|
|
return new PhabricatorProfileMenuEditor();
|
2016-01-12 15:06:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionObject() {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionTemplate() {
|
2016-12-11 09:38:06 -08:00
|
|
|
return new PhabricatorProfileMenuItemConfigurationTransaction();
|
2016-01-12 15:06:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function willRenderTimeline(
|
|
|
|
PhabricatorApplicationTransactionView $timeline,
|
|
|
|
AphrontRequest $request) {
|
|
|
|
|
|
|
|
return $timeline;
|
|
|
|
}
|
|
|
|
|
2016-01-12 10:27:39 -08:00
|
|
|
}
|