mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-08 04:48:28 +01:00
58b889c5b0
Summary: Ref T12956. Currently, when you visit `/maniphest/` (or any other ApplicationSearch application) we execute the first query in the list by default. In T12956, I plan to make changes so that personal queries are always first, then global/builtin queries. Without changing the "default query" rule, this will make it harder to have, for example, some custom queries in Differential but still run a global query like "Active" by default. To make this work, you'd have to save a personal copy of the "Active" query, then put it at the top. This feels a bit cumbersome and this rule is kind of implicit and a little weird anyway. To make this work a little better as we make changes here, add an explicit pinning action, like the one we have in Project ProfileMenus. You can now explicitly choose a query to make default. Test Plan: - Browsed without pinning anything, saw normal behavior. - Pinned queries, viewed `/maniphest/`, saw a non-initial query selected by default. - Pinned a query, deleted it, nothing exploded. {F5098484} Reviewers: chad Reviewed By: chad Maniphest Tasks: T12956 Differential Revision: https://secure.phabricator.com/D18422
92 lines
2 KiB
PHP
92 lines
2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorNamedQueryConfig
|
|
extends PhabricatorSearchDAO
|
|
implements PhabricatorPolicyInterface {
|
|
|
|
protected $engineClassName;
|
|
protected $scopePHID;
|
|
protected $properties = array();
|
|
|
|
const SCOPE_GLOBAL = 'scope.global';
|
|
|
|
const PROPERTY_PINNED = 'pinned';
|
|
|
|
protected function getConfiguration() {
|
|
return array(
|
|
self::CONFIG_SERIALIZATION => array(
|
|
'properties' => self::SERIALIZATION_JSON,
|
|
),
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
|
'engineClassName' => 'text128',
|
|
),
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
'key_scope' => array(
|
|
'columns' => array('engineClassName', 'scopePHID'),
|
|
'unique' => true,
|
|
),
|
|
),
|
|
) + parent::getConfiguration();
|
|
}
|
|
|
|
public static function initializeNewQueryConfig() {
|
|
return new self();
|
|
}
|
|
|
|
public function isGlobal() {
|
|
return ($this->getScopePHID() == self::SCOPE_GLOBAL);
|
|
}
|
|
|
|
public function getConfigProperty($key, $default = null) {
|
|
return idx($this->properties, $key, $default);
|
|
}
|
|
|
|
public function setConfigProperty($key, $value) {
|
|
$this->properties[$key] = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function getStrengthSortVector() {
|
|
// Apply personal preferences before global preferences.
|
|
if (!$this->isGlobal()) {
|
|
$phase = 0;
|
|
} else {
|
|
$phase = 1;
|
|
}
|
|
|
|
return id(new PhutilSortVector())
|
|
->addInt($phase)
|
|
->addInt($this->getID());
|
|
}
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
public function getCapabilities() {
|
|
return array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
);
|
|
}
|
|
|
|
public function getPolicy($capability) {
|
|
return PhabricatorPolicies::POLICY_NOONE;
|
|
}
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
if ($this->isGlobal()) {
|
|
return true;
|
|
}
|
|
|
|
if ($viewer->getPHID() == $this->getScopePHID()) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function describeAutomaticCapability($capability) {
|
|
return null;
|
|
}
|
|
|
|
}
|