1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-08 04:48:28 +01:00
phorge-phorge/src/applications/search/storage/PhabricatorNamedQuery.php
epriestley 47da632a22 Separate saved queries in applications into "personal" and "global" queries
Summary:
Ref T12956. UI changes:

  - Administrators get a new `[X] Save as global query` option when saving a query.
  - "Edit Queries..." is split into "Personal" and "Global" sections. For administrators, each section can be edited. For non-admins, only the top section can be edited, but any query can be pinned.

A couple notes:

  - This doesn't support "pin for everyone by default". New users just get the first query from the bottom set. That seems reasonable for now.
  - Reordering is currently a little buggy (it works if you've reordered before, but not if you're reordering for the first time), but I need to migrate before I can fix / test that properly. So that'll get cleaned up in the next change or two.

Test Plan:
  - As an admin and non-admin, viewed, edited, disabled, saved-as-personal and saved-as-global various queries.

{F5098581}

{F5098582}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12956

Differential Revision: https://secure.phabricator.com/D18426
2017-08-24 15:24:34 -07:00

98 lines
2.2 KiB
PHP

<?php
final class PhabricatorNamedQuery extends PhabricatorSearchDAO
implements PhabricatorPolicyInterface {
protected $queryKey;
protected $queryName;
protected $userPHID;
protected $engineClassName;
protected $isBuiltin = 0;
protected $isDisabled = 0;
protected $sequence = 0;
const SCOPE_GLOBAL = 'scope.global';
protected function getConfiguration() {
return array(
self::CONFIG_COLUMN_SCHEMA => array(
'engineClassName' => 'text128',
'queryName' => 'text255',
'queryKey' => 'text12',
'isBuiltin' => 'bool',
'isDisabled' => 'bool',
'sequence' => 'uint32',
),
self::CONFIG_KEY_SCHEMA => array(
'key_userquery' => array(
'columns' => array('userPHID', 'engineClassName', 'queryKey'),
'unique' => true,
),
),
) + parent::getConfiguration();
}
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());
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
return PhabricatorPolicies::POLICY_NOONE;
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
if ($viewer->getPHID() == $this->getUserPHID()) {
return true;
}
if ($this->isGlobal()) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return true;
case PhabricatorPolicyCapability::CAN_EDIT:
return $viewer->getIsAdmin();
}
}
return false;
}
public function describeAutomaticCapability($capability) {
return pht(
'The queries you have saved are private. Only you can view or edit '.
'them.');
}
}