2012-07-19 18:03:10 +02:00
|
|
|
<?php
|
|
|
|
|
2012-10-15 23:49:52 +02:00
|
|
|
final class PhameBlogQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
2012-07-19 18:03:10 +02:00
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
private $ids;
|
2012-07-19 18:03:10 +02:00
|
|
|
private $phids;
|
2012-10-01 02:10:27 +02:00
|
|
|
private $domain;
|
2015-11-21 17:51:07 +01:00
|
|
|
private $statuses;
|
2015-11-28 21:42:36 +01:00
|
|
|
|
2012-07-19 18:03:10 +02:00
|
|
|
private $needBloggers;
|
2015-11-28 21:42:36 +01:00
|
|
|
private $needProfileImage;
|
2012-07-19 18:03:10 +02:00
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
2012-07-19 18:03:10 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
2012-10-01 02:10:27 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:12 +02:00
|
|
|
public function withDomain($domain) {
|
|
|
|
$this->domain = $domain;
|
2012-07-19 18:03:10 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-11-21 17:51:07 +01:00
|
|
|
public function withStatuses(array $status) {
|
|
|
|
$this->statuses = $status;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-11-28 21:42:36 +01:00
|
|
|
public function needProfileImage($need) {
|
|
|
|
$this->needProfileImage = $need;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-07-22 22:31:47 +02:00
|
|
|
public function newResultObject() {
|
|
|
|
return new PhameBlog();
|
|
|
|
}
|
2012-07-19 18:03:10 +02:00
|
|
|
|
2015-07-22 22:31:47 +02:00
|
|
|
protected function loadPage() {
|
|
|
|
return $this->loadStandardPage($this->newResultObject());
|
2012-07-19 18:03:10 +02:00
|
|
|
}
|
|
|
|
|
2015-07-22 22:31:47 +02:00
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
2012-07-19 18:03:10 +02:00
|
|
|
|
2015-11-21 17:51:07 +01:00
|
|
|
if ($this->statuses !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'status IN (%Ls)',
|
|
|
|
$this->statuses);
|
|
|
|
}
|
|
|
|
|
2015-07-22 22:31:47 +02:00
|
|
|
if ($this->ids !== null) {
|
2012-10-15 23:50:12 +02:00
|
|
|
$where[] = qsprintf(
|
2015-07-22 22:31:47 +02:00
|
|
|
$conn,
|
2012-10-15 23:50:12 +02:00
|
|
|
'id IN (%Ls)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2015-07-22 22:31:47 +02:00
|
|
|
if ($this->phids !== null) {
|
2012-07-19 18:03:10 +02:00
|
|
|
$where[] = qsprintf(
|
2015-07-22 22:31:47 +02:00
|
|
|
$conn,
|
2012-07-19 18:03:10 +02:00
|
|
|
'phid IN (%Ls)',
|
2012-10-15 23:49:52 +02:00
|
|
|
$this->phids);
|
2012-10-01 02:10:27 +02:00
|
|
|
}
|
|
|
|
|
2015-07-22 22:31:47 +02:00
|
|
|
if ($this->domain !== null) {
|
2012-10-01 02:10:27 +02:00
|
|
|
$where[] = qsprintf(
|
2015-07-22 22:31:47 +02:00
|
|
|
$conn,
|
2012-10-01 02:10:27 +02:00
|
|
|
'domain = %s',
|
2012-10-15 23:49:52 +02:00
|
|
|
$this->domain);
|
2012-07-19 18:03:10 +02:00
|
|
|
}
|
|
|
|
|
2015-07-22 22:31:47 +02:00
|
|
|
return $where;
|
2012-07-19 18:03:10 +02:00
|
|
|
}
|
|
|
|
|
2015-11-28 21:42:36 +01:00
|
|
|
protected function didFilterPage(array $blogs) {
|
|
|
|
if ($this->needProfileImage) {
|
|
|
|
$default = null;
|
|
|
|
|
|
|
|
$file_phids = mpull($blogs, 'getProfileImagePHID');
|
|
|
|
$file_phids = array_filter($file_phids);
|
|
|
|
if ($file_phids) {
|
|
|
|
$files = id(new PhabricatorFileQuery())
|
|
|
|
->setParentQuery($this)
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($file_phids)
|
|
|
|
->execute();
|
|
|
|
$files = mpull($files, null, 'getPHID');
|
|
|
|
} else {
|
|
|
|
$files = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($blogs as $blog) {
|
|
|
|
$file = idx($files, $blog->getProfileImagePHID());
|
|
|
|
if (!$file) {
|
|
|
|
if (!$default) {
|
|
|
|
$default = PhabricatorFile::loadBuiltin(
|
|
|
|
$this->getViewer(),
|
|
|
|
'blog.png');
|
|
|
|
}
|
|
|
|
$file = $default;
|
|
|
|
}
|
|
|
|
$blog->attachProfileImageFile($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $blogs;
|
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
// TODO: Can we set this without breaking public blogs?
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-07-19 18:03:10 +02:00
|
|
|
}
|