2013-05-10 13:43:59 -07:00
|
|
|
<?php
|
|
|
|
|
2013-05-27 13:40:43 -07:00
|
|
|
final class PhabricatorNamedQuery extends PhabricatorSearchDAO
|
|
|
|
implements PhabricatorPolicyInterface {
|
2013-05-10 13:43:59 -07:00
|
|
|
|
2013-06-05 05:28:25 -07:00
|
|
|
protected $queryKey;
|
|
|
|
protected $queryName;
|
|
|
|
protected $userPHID;
|
|
|
|
protected $engineClassName;
|
|
|
|
|
|
|
|
protected $isBuiltin = 0;
|
|
|
|
protected $isDisabled = 0;
|
|
|
|
protected $sequence = 0;
|
2013-05-27 13:40:43 -07:00
|
|
|
|
2017-08-14 12:19:06 -07:00
|
|
|
const SCOPE_GLOBAL = 'scope.global';
|
|
|
|
|
2015-01-14 06:47:05 +11:00
|
|
|
protected function getConfiguration() {
|
2014-10-01 07:53:35 -07:00
|
|
|
return array(
|
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
|
|
|
'engineClassName' => 'text128',
|
|
|
|
'queryName' => 'text255',
|
2014-10-01 10:11:19 -07:00
|
|
|
'queryKey' => 'text12',
|
2014-10-01 07:53:35 -07:00
|
|
|
'isBuiltin' => 'bool',
|
|
|
|
'isDisabled' => 'bool',
|
|
|
|
'sequence' => 'uint32',
|
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_userquery' => array(
|
|
|
|
'columns' => array('userPHID', 'engineClassName', 'queryKey'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
2017-08-14 12:19:06 -07:00
|
|
|
public function isGlobal() {
|
|
|
|
if ($this->getIsBuiltin()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->getUserPHID() === self::SCOPE_GLOBAL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNamedQuerySortVector() {
|
|
|
|
if (!$this->isGlobal()) {
|
|
|
|
$phase = 0;
|
|
|
|
} else {
|
|
|
|
$phase = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return id(new PhutilSortVector())
|
|
|
|
->addInt($phase)
|
|
|
|
->addInt($this->sequence)
|
|
|
|
->addInt($this->getID());
|
2013-06-05 16:22:27 -07:00
|
|
|
}
|
|
|
|
|
2013-05-27 13:40:43 -07:00
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
2017-08-14 12:19:06 -07:00
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
2013-05-27 13:40:43 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
return PhabricatorPolicies::POLICY_NOONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
2017-08-14 12:19:06 -07:00
|
|
|
if ($viewer->getPHID() == $this->getUserPHID()) {
|
2013-05-27 13:40:43 -07:00
|
|
|
return true;
|
|
|
|
}
|
2017-08-14 12:19:06 -07:00
|
|
|
|
|
|
|
if ($this->isGlobal()) {
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return true;
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return $viewer->getIsAdmin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-27 13:40:43 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-27 08:43:41 -07:00
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return pht(
|
|
|
|
'The queries you have saved are private. Only you can view or edit '.
|
|
|
|
'them.');
|
|
|
|
}
|
|
|
|
|
2013-05-10 13:43:59 -07:00
|
|
|
}
|