2013-07-01 21:36:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorConduitMethodQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $isDeprecated;
|
|
|
|
private $isStable;
|
|
|
|
private $isUnstable;
|
|
|
|
private $applicationNames;
|
|
|
|
private $nameContains;
|
|
|
|
private $methods;
|
2016-04-08 22:08:56 +02:00
|
|
|
private $isInternal;
|
2013-07-01 21:36:34 +02:00
|
|
|
|
|
|
|
public function withMethods(array $methods) {
|
|
|
|
$this->methods = $methods;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withNameContains($name_contains) {
|
|
|
|
$this->nameContains = $name_contains;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withIsStable($is_stable) {
|
|
|
|
$this->isStable = $is_stable;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withIsUnstable($is_unstable) {
|
|
|
|
$this->isUnstable = $is_unstable;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withIsDeprecated($is_deprecated) {
|
|
|
|
$this->isDeprecated = $is_deprecated;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-04-08 22:08:56 +02:00
|
|
|
public function withIsInternal($is_internal) {
|
|
|
|
$this->isInternal = $is_internal;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:56:07 +01:00
|
|
|
protected function loadPage() {
|
2013-07-01 21:36:34 +02:00
|
|
|
$methods = $this->getAllMethods();
|
|
|
|
$methods = $this->filterMethods($methods);
|
|
|
|
return $methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getAllMethods() {
|
2015-08-13 23:49:00 +02:00
|
|
|
return id(new PhutilClassMapQuery())
|
|
|
|
->setAncestorClass('ConduitAPIMethod')
|
|
|
|
->setSortMethod('getSortOrder')
|
|
|
|
->execute();
|
2013-07-01 21:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function filterMethods(array $methods) {
|
|
|
|
foreach ($methods as $key => $method) {
|
|
|
|
$application = $method->getApplication();
|
|
|
|
if (!$application) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!$application->isInstalled()) {
|
|
|
|
unset($methods[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$status = array(
|
2014-07-23 02:03:09 +02:00
|
|
|
ConduitAPIMethod::METHOD_STATUS_STABLE => $this->isStable,
|
2013-07-01 21:36:34 +02:00
|
|
|
ConduitAPIMethod::METHOD_STATUS_DEPRECATED => $this->isDeprecated,
|
2014-07-23 02:03:09 +02:00
|
|
|
ConduitAPIMethod::METHOD_STATUS_UNSTABLE => $this->isUnstable,
|
2013-07-01 21:36:34 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// Only apply status filters if any of them are set.
|
|
|
|
if (array_filter($status)) {
|
|
|
|
foreach ($methods as $key => $method) {
|
|
|
|
$keep = idx($status, $method->getMethodStatus());
|
|
|
|
if (!$keep) {
|
|
|
|
unset($methods[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->nameContains) {
|
|
|
|
$needle = phutil_utf8_strtolower($this->nameContains);
|
|
|
|
foreach ($methods as $key => $method) {
|
|
|
|
$haystack = $method->getAPIMethodName();
|
|
|
|
$haystack = phutil_utf8_strtolower($haystack);
|
|
|
|
if (strpos($haystack, $needle) === false) {
|
|
|
|
unset($methods[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->methods) {
|
|
|
|
$map = array_fuse($this->methods);
|
|
|
|
foreach ($methods as $key => $method) {
|
|
|
|
$needle = $method->getAPIMethodName();
|
|
|
|
if (empty($map[$needle])) {
|
|
|
|
unset($methods[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 22:08:56 +02:00
|
|
|
if ($this->isInternal !== null) {
|
|
|
|
foreach ($methods as $key => $method) {
|
|
|
|
if ($method->isInternalAPI() !== $this->isInternal) {
|
|
|
|
unset($methods[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-01 21:36:34 +02:00
|
|
|
return $methods;
|
|
|
|
}
|
|
|
|
|
2015-11-16 18:24:50 +01:00
|
|
|
protected function willFilterPage(array $methods) {
|
|
|
|
$application_phids = array();
|
|
|
|
foreach ($methods as $method) {
|
|
|
|
$application = $method->getApplication();
|
|
|
|
if ($application === null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$application_phids[] = $application->getPHID();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($application_phids) {
|
|
|
|
$applications = id(new PhabricatorApplicationQuery())
|
|
|
|
->setParentQuery($this)
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($application_phids)
|
|
|
|
->execute();
|
|
|
|
$applications = mpull($applications, null, 'getPHID');
|
|
|
|
} else {
|
|
|
|
$applications = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove methods which belong to an application the viewer can not see.
|
|
|
|
foreach ($methods as $key => $method) {
|
|
|
|
$application = $method->getApplication();
|
|
|
|
if ($application === null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($applications[$application->getPHID()])) {
|
|
|
|
$this->didRejectResult($method);
|
|
|
|
unset($methods[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $methods;
|
|
|
|
}
|
|
|
|
|
Lock policy queries to their applications
Summary:
While we mostly have reasonable effective object accessibility when you lock a user out of an application, it's primarily enforced at the controller level. Users can still, e.g., load the handles of objects they can't actually see. Instead, lock the queries to the applications so that you can, e.g., never load a revision if you don't have access to Differential.
This has several parts:
- For PolicyAware queries, provide an application class name method.
- If the query specifies a class name and the user doesn't have permission to use it, fail the entire query unconditionally.
- For handles, simplify query construction and count all the PHIDs as "restricted" so we get a UI full of "restricted" instead of "unknown" handles.
Test Plan:
- Added a unit test to verify I got all the class names right.
- Browsed around, logged in/out as a normal user with public policies on and off.
- Browsed around, logged in/out as a restricted user with public policies on and off. With restrictions, saw all traces of restricted apps removed or restricted.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7367
2013-10-22 02:20:27 +02:00
|
|
|
public function getQueryApplicationClass() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorConduitApplication';
|
Lock policy queries to their applications
Summary:
While we mostly have reasonable effective object accessibility when you lock a user out of an application, it's primarily enforced at the controller level. Users can still, e.g., load the handles of objects they can't actually see. Instead, lock the queries to the applications so that you can, e.g., never load a revision if you don't have access to Differential.
This has several parts:
- For PolicyAware queries, provide an application class name method.
- If the query specifies a class name and the user doesn't have permission to use it, fail the entire query unconditionally.
- For handles, simplify query construction and count all the PHIDs as "restricted" so we get a UI full of "restricted" instead of "unknown" handles.
Test Plan:
- Added a unit test to verify I got all the class names right.
- Browsed around, logged in/out as a normal user with public policies on and off.
- Browsed around, logged in/out as a restricted user with public policies on and off. With restrictions, saw all traces of restricted apps removed or restricted.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7367
2013-10-22 02:20:27 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 21:36:34 +02:00
|
|
|
}
|