2011-12-16 17:08:18 -08:00
|
|
|
<?php
|
|
|
|
|
|
2012-09-13 10:15:08 -07:00
|
|
|
final class PhabricatorProjectQuery
|
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
2011-12-16 17:08:18 -08:00
|
|
|
|
2012-01-17 16:29:35 -08:00
|
|
|
private $ids;
|
|
|
|
|
private $phids;
|
2012-08-07 11:54:24 -07:00
|
|
|
private $memberPHIDs;
|
2013-03-08 07:12:24 -08:00
|
|
|
private $slugs;
|
2015-12-27 02:28:36 -08:00
|
|
|
private $slugNormals;
|
|
|
|
|
private $slugMap;
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
private $allSlugs;
|
2013-10-25 10:16:39 -07:00
|
|
|
private $names;
|
2015-04-15 11:49:07 -07:00
|
|
|
private $nameTokens;
|
2014-08-12 08:04:38 -07:00
|
|
|
private $icons;
|
|
|
|
|
private $colors;
|
2015-12-23 07:01:27 -08:00
|
|
|
private $ancestorPHIDs;
|
|
|
|
|
private $parentPHIDs;
|
|
|
|
|
private $isMilestone;
|
2015-12-23 03:12:20 -08:00
|
|
|
private $hasSubprojects;
|
2015-12-23 07:01:27 -08:00
|
|
|
private $minDepth;
|
|
|
|
|
private $maxDepth;
|
2011-12-16 17:08:18 -08:00
|
|
|
|
2012-02-07 14:59:38 -08:00
|
|
|
private $status = 'status-any';
|
|
|
|
|
const STATUS_ANY = 'status-any';
|
|
|
|
|
const STATUS_OPEN = 'status-open';
|
|
|
|
|
const STATUS_CLOSED = 'status-closed';
|
|
|
|
|
const STATUS_ACTIVE = 'status-active';
|
|
|
|
|
const STATUS_ARCHIVED = 'status-archived';
|
2016-02-06 12:40:31 -08:00
|
|
|
private $statuses;
|
2012-02-07 14:59:38 -08:00
|
|
|
|
2014-05-22 11:19:03 -07:00
|
|
|
private $needSlugs;
|
2012-01-17 16:29:35 -08:00
|
|
|
private $needMembers;
|
2016-01-19 09:36:40 -08:00
|
|
|
private $needAncestorMembers;
|
2014-05-19 12:40:57 -07:00
|
|
|
private $needWatchers;
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
private $needImages;
|
2012-01-17 16:29:35 -08:00
|
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
|
$this->ids = $ids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
|
$this->phids = $phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 14:59:38 -08:00
|
|
|
public function withStatus($status) {
|
|
|
|
|
$this->status = $status;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-06 12:40:31 -08:00
|
|
|
public function withStatuses(array $statuses) {
|
|
|
|
|
$this->statuses = $statuses;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-07 11:54:24 -07:00
|
|
|
public function withMemberPHIDs(array $member_phids) {
|
|
|
|
|
$this->memberPHIDs = $member_phids;
|
2011-12-16 17:08:18 -08:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-22 11:19:03 -07:00
|
|
|
public function withSlugs(array $slugs) {
|
2013-03-08 07:12:24 -08:00
|
|
|
$this->slugs = $slugs;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 10:16:39 -07:00
|
|
|
public function withNames(array $names) {
|
|
|
|
|
$this->names = $names;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-15 11:49:07 -07:00
|
|
|
public function withNameTokens(array $tokens) {
|
|
|
|
|
$this->nameTokens = array_values($tokens);
|
2014-07-17 16:35:54 -07:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
public function withIcons(array $icons) {
|
|
|
|
|
$this->icons = $icons;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withColors(array $colors) {
|
|
|
|
|
$this->colors = $colors;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 07:01:27 -08:00
|
|
|
public function withParentProjectPHIDs($parent_phids) {
|
|
|
|
|
$this->parentPHIDs = $parent_phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withAncestorProjectPHIDs($ancestor_phids) {
|
|
|
|
|
$this->ancestorPHIDs = $ancestor_phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withIsMilestone($is_milestone) {
|
|
|
|
|
$this->isMilestone = $is_milestone;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 03:12:20 -08:00
|
|
|
public function withHasSubprojects($has_subprojects) {
|
|
|
|
|
$this->hasSubprojects = $has_subprojects;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 07:01:27 -08:00
|
|
|
public function withDepthBetween($min, $max) {
|
|
|
|
|
$this->minDepth = $min;
|
|
|
|
|
$this->maxDepth = $max;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-17 16:29:35 -08:00
|
|
|
public function needMembers($need_members) {
|
|
|
|
|
$this->needMembers = $need_members;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
public function needAncestorMembers($need_ancestor_members) {
|
|
|
|
|
$this->needAncestorMembers = $need_ancestor_members;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-19 12:40:57 -07:00
|
|
|
public function needWatchers($need_watchers) {
|
|
|
|
|
$this->needWatchers = $need_watchers;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
public function needImages($need_images) {
|
|
|
|
|
$this->needImages = $need_images;
|
2013-10-06 17:07:20 -07:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-22 11:19:03 -07:00
|
|
|
public function needSlugs($need_slugs) {
|
|
|
|
|
$this->needSlugs = $need_slugs;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:21:48 -07:00
|
|
|
public function newResultObject() {
|
|
|
|
|
return new PhabricatorProject();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-11 19:07:28 -07:00
|
|
|
protected function getDefaultOrderVector() {
|
|
|
|
|
return array('name');
|
2012-08-08 17:10:10 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:21:48 -07:00
|
|
|
public function getBuiltinOrders() {
|
2015-04-11 19:07:28 -07:00
|
|
|
return array(
|
2015-06-08 12:21:48 -07:00
|
|
|
'name' => array(
|
|
|
|
|
'vector' => array('name'),
|
|
|
|
|
'name' => pht('Name'),
|
|
|
|
|
),
|
|
|
|
|
) + parent::getBuiltinOrders();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getOrderableColumns() {
|
|
|
|
|
return parent::getOrderableColumns() + array(
|
2015-04-11 19:07:28 -07:00
|
|
|
'name' => array(
|
|
|
|
|
'table' => $this->getPrimaryTableAlias(),
|
|
|
|
|
'column' => 'name',
|
|
|
|
|
'reverse' => true,
|
|
|
|
|
'type' => 'string',
|
|
|
|
|
'unique' => true,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getPagingValueMap($cursor, array $keys) {
|
2015-04-12 16:44:15 -07:00
|
|
|
$project = $this->loadCursorObject($cursor);
|
2015-04-11 19:07:28 -07:00
|
|
|
return array(
|
2015-04-12 16:44:15 -07:00
|
|
|
'name' => $project->getName(),
|
2015-04-11 19:07:28 -07:00
|
|
|
);
|
2012-08-08 17:10:10 -07:00
|
|
|
}
|
|
|
|
|
|
2015-12-27 02:28:36 -08:00
|
|
|
public function getSlugMap() {
|
|
|
|
|
if ($this->slugMap === null) {
|
|
|
|
|
throw new PhutilInvalidStateException('execute');
|
|
|
|
|
}
|
|
|
|
|
return $this->slugMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function willExecute() {
|
|
|
|
|
$this->slugMap = array();
|
|
|
|
|
$this->slugNormals = array();
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
$this->allSlugs = array();
|
2015-12-27 02:28:36 -08:00
|
|
|
if ($this->slugs) {
|
|
|
|
|
foreach ($this->slugs as $slug) {
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
if (PhabricatorSlug::isValidProjectSlug($slug)) {
|
|
|
|
|
$normal = PhabricatorSlug::normalizeProjectSlug($slug);
|
|
|
|
|
$this->slugNormals[$slug] = $normal;
|
|
|
|
|
$this->allSlugs[$normal] = $normal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: At least for now, we query for the normalized slugs but also
|
|
|
|
|
// for the slugs exactly as entered. This allows older projects with
|
|
|
|
|
// slugs that are no longer valid to continue to work.
|
|
|
|
|
$this->allSlugs[$slug] = $slug;
|
2015-12-27 02:28:36 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-01 11:28:02 -08:00
|
|
|
protected function loadPage() {
|
2015-12-23 03:42:42 -08:00
|
|
|
return $this->loadStandardPage($this->newResultObject());
|
|
|
|
|
}
|
2012-01-17 16:29:35 -08:00
|
|
|
|
2015-12-23 03:42:42 -08:00
|
|
|
protected function willFilterPage(array $projects) {
|
2015-12-23 03:42:51 -08:00
|
|
|
$ancestor_paths = array();
|
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
|
foreach ($project->getAncestorProjectPaths() as $path) {
|
|
|
|
|
$ancestor_paths[$path] = $path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($ancestor_paths) {
|
|
|
|
|
$ancestors = id(new PhabricatorProject())->loadAllWhere(
|
|
|
|
|
'projectPath IN (%Ls)',
|
|
|
|
|
$ancestor_paths);
|
|
|
|
|
} else {
|
|
|
|
|
$ancestors = array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$projects = $this->linkProjectGraph($projects, $ancestors);
|
|
|
|
|
|
2015-12-23 03:42:42 -08:00
|
|
|
$viewer_phid = $this->getViewer()->getPHID();
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2015-12-27 04:27:58 -08:00
|
|
|
$material_type = PhabricatorProjectMaterializedMemberEdgeType::EDGECONST;
|
2015-12-23 03:42:42 -08:00
|
|
|
$watcher_type = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2015-12-23 03:42:42 -08:00
|
|
|
$types = array();
|
2015-12-27 04:27:58 -08:00
|
|
|
$types[] = $material_type;
|
2015-12-23 03:42:42 -08:00
|
|
|
if ($this->needWatchers) {
|
|
|
|
|
$types[] = $watcher_type;
|
|
|
|
|
}
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
$all_graph = $this->getAllReachableAncestors($projects);
|
|
|
|
|
|
|
|
|
|
if ($this->needAncestorMembers) {
|
|
|
|
|
$src_projects = $all_graph;
|
|
|
|
|
} else {
|
|
|
|
|
$src_projects = $projects;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 03:12:20 -08:00
|
|
|
$all_sources = array();
|
2016-01-19 09:36:40 -08:00
|
|
|
foreach ($src_projects as $project) {
|
2015-12-23 03:12:20 -08:00
|
|
|
if ($project->isMilestone()) {
|
|
|
|
|
$phid = $project->getParentProjectPHID();
|
|
|
|
|
} else {
|
|
|
|
|
$phid = $project->getPHID();
|
|
|
|
|
}
|
|
|
|
|
$all_sources[$phid] = $phid;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 03:42:42 -08:00
|
|
|
$edge_query = id(new PhabricatorEdgeQuery())
|
2015-12-23 03:12:20 -08:00
|
|
|
->withSourcePHIDs($all_sources)
|
2015-12-23 03:42:42 -08:00
|
|
|
->withEdgeTypes($types);
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
$need_all_edges =
|
|
|
|
|
$this->needMembers ||
|
|
|
|
|
$this->needWatchers ||
|
|
|
|
|
$this->needAncestorMembers;
|
|
|
|
|
|
2015-12-23 03:42:42 -08:00
|
|
|
// If we only need to know if the viewer is a member, we can restrict
|
|
|
|
|
// the query to just their PHID.
|
2015-12-27 04:15:39 -08:00
|
|
|
$any_edges = true;
|
2016-01-19 09:36:40 -08:00
|
|
|
if (!$need_all_edges) {
|
2015-12-27 04:15:39 -08:00
|
|
|
if ($viewer_phid) {
|
|
|
|
|
$edge_query->withDestinationPHIDs(array($viewer_phid));
|
|
|
|
|
} else {
|
|
|
|
|
// If we don't need members or watchers and don't have a viewer PHID
|
|
|
|
|
// (viewer is logged-out or omnipotent), they'll never be a member
|
|
|
|
|
// so we don't need to issue this query at all.
|
|
|
|
|
$any_edges = false;
|
|
|
|
|
}
|
2015-12-23 03:42:42 -08:00
|
|
|
}
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2015-12-27 04:15:39 -08:00
|
|
|
if ($any_edges) {
|
|
|
|
|
$edge_query->execute();
|
|
|
|
|
}
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
$membership_projects = array();
|
2016-01-19 09:36:40 -08:00
|
|
|
foreach ($src_projects as $project) {
|
2015-12-23 03:42:42 -08:00
|
|
|
$project_phid = $project->getPHID();
|
|
|
|
|
|
2015-12-23 03:12:20 -08:00
|
|
|
if ($project->isMilestone()) {
|
|
|
|
|
$source_phids = array($project->getParentProjectPHID());
|
|
|
|
|
} else {
|
|
|
|
|
$source_phids = array($project_phid);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 04:15:39 -08:00
|
|
|
if ($any_edges) {
|
|
|
|
|
$member_phids = $edge_query->getDestinationPHIDs(
|
|
|
|
|
$source_phids,
|
2015-12-27 04:27:58 -08:00
|
|
|
array($material_type));
|
2015-12-27 04:15:39 -08:00
|
|
|
} else {
|
|
|
|
|
$member_phids = array();
|
|
|
|
|
}
|
2015-12-23 03:42:42 -08:00
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
if (in_array($viewer_phid, $member_phids)) {
|
|
|
|
|
$membership_projects[$project_phid] = $project;
|
|
|
|
|
}
|
2015-12-23 03:42:42 -08:00
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
if ($this->needMembers || $this->needAncestorMembers) {
|
2015-12-23 03:42:42 -08:00
|
|
|
$project->attachMemberPHIDs($member_phids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->needWatchers) {
|
|
|
|
|
$watcher_phids = $edge_query->getDestinationPHIDs(
|
2015-12-23 03:12:20 -08:00
|
|
|
$source_phids,
|
2015-12-23 03:42:42 -08:00
|
|
|
array($watcher_type));
|
|
|
|
|
$project->attachWatcherPHIDs($watcher_phids);
|
|
|
|
|
$project->setIsUserWatcher(
|
|
|
|
|
$viewer_phid,
|
|
|
|
|
in_array($viewer_phid, $watcher_phids));
|
2014-05-19 12:40:57 -07:00
|
|
|
}
|
Fix some file policy issues and add a "Query Workspace"
Summary:
Ref T603. Several issues here:
1. Currently, `FileQuery` does not actually respect object attachment edges when doing policy checks. Everything else works fine, but this was missing an `array_keys()`.
2. Once that's fixed, we hit a bunch of recursion issues. For example, when loading a User we load the profile picture, and then that loads the User, and that loads the profile picture, etc.
3. Introduce a "Query Workspace", which holds objects we know we've loaded and know we can see but haven't finished filtering and/or attaching data to. This allows subqueries to look up objects instead of querying for them.
- We can probably generalize this a bit to make a few other queries more efficient. Pholio currently has a similar (but less general) "mock cache". However, it's keyed by ID instead of PHID so it's not easy to reuse this right now.
This is a bit complex for the problem being solved, but I think it's the cleanest approach and I believe the primitive will be useful in the future.
Test Plan: Looked at pastes, macros, mocks and projects as a logged-in and logged-out user.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7309
2013-10-14 14:36:06 -07:00
|
|
|
}
|
2013-10-06 17:07:20 -07:00
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
// If we loaded ancestor members, we've already populated membership
|
|
|
|
|
// lists above, so we can skip this step.
|
|
|
|
|
if (!$this->needAncestorMembers) {
|
|
|
|
|
$member_graph = $this->getAllReachableAncestors($membership_projects);
|
2015-12-23 03:42:51 -08:00
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
foreach ($all_graph as $phid => $project) {
|
|
|
|
|
$is_member = isset($member_graph[$phid]);
|
|
|
|
|
$project->setIsUserMember($viewer_phid, $is_member);
|
|
|
|
|
}
|
2015-12-23 03:42:51 -08:00
|
|
|
}
|
|
|
|
|
|
Fix some file policy issues and add a "Query Workspace"
Summary:
Ref T603. Several issues here:
1. Currently, `FileQuery` does not actually respect object attachment edges when doing policy checks. Everything else works fine, but this was missing an `array_keys()`.
2. Once that's fixed, we hit a bunch of recursion issues. For example, when loading a User we load the profile picture, and then that loads the User, and that loads the profile picture, etc.
3. Introduce a "Query Workspace", which holds objects we know we've loaded and know we can see but haven't finished filtering and/or attaching data to. This allows subqueries to look up objects instead of querying for them.
- We can probably generalize this a bit to make a few other queries more efficient. Pholio currently has a similar (but less general) "mock cache". However, it's keyed by ID instead of PHID so it's not easy to reuse this right now.
This is a bit complex for the problem being solved, but I think it's the cleanest approach and I believe the primitive will be useful in the future.
Test Plan: Looked at pastes, macros, mocks and projects as a logged-in and logged-out user.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7309
2013-10-14 14:36:06 -07:00
|
|
|
return $projects;
|
|
|
|
|
}
|
2013-10-06 17:07:43 -07:00
|
|
|
|
Fix some file policy issues and add a "Query Workspace"
Summary:
Ref T603. Several issues here:
1. Currently, `FileQuery` does not actually respect object attachment edges when doing policy checks. Everything else works fine, but this was missing an `array_keys()`.
2. Once that's fixed, we hit a bunch of recursion issues. For example, when loading a User we load the profile picture, and then that loads the User, and that loads the profile picture, etc.
3. Introduce a "Query Workspace", which holds objects we know we've loaded and know we can see but haven't finished filtering and/or attaching data to. This allows subqueries to look up objects instead of querying for them.
- We can probably generalize this a bit to make a few other queries more efficient. Pholio currently has a similar (but less general) "mock cache". However, it's keyed by ID instead of PHID so it's not easy to reuse this right now.
This is a bit complex for the problem being solved, but I think it's the cleanest approach and I believe the primitive will be useful in the future.
Test Plan: Looked at pastes, macros, mocks and projects as a logged-in and logged-out user.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7309
2013-10-14 14:36:06 -07:00
|
|
|
protected function didFilterPage(array $projects) {
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
if ($this->needImages) {
|
Fix some file policy issues and add a "Query Workspace"
Summary:
Ref T603. Several issues here:
1. Currently, `FileQuery` does not actually respect object attachment edges when doing policy checks. Everything else works fine, but this was missing an `array_keys()`.
2. Once that's fixed, we hit a bunch of recursion issues. For example, when loading a User we load the profile picture, and then that loads the User, and that loads the profile picture, etc.
3. Introduce a "Query Workspace", which holds objects we know we've loaded and know we can see but haven't finished filtering and/or attaching data to. This allows subqueries to look up objects instead of querying for them.
- We can probably generalize this a bit to make a few other queries more efficient. Pholio currently has a similar (but less general) "mock cache". However, it's keyed by ID instead of PHID so it's not easy to reuse this right now.
This is a bit complex for the problem being solved, but I think it's the cleanest approach and I believe the primitive will be useful in the future.
Test Plan: Looked at pastes, macros, mocks and projects as a logged-in and logged-out user.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7309
2013-10-14 14:36:06 -07:00
|
|
|
$default = null;
|
|
|
|
|
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
$file_phids = mpull($projects, 'getProfileImagePHID');
|
2015-06-30 11:19:24 -07:00
|
|
|
$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();
|
|
|
|
|
}
|
|
|
|
|
|
Fix some file policy issues and add a "Query Workspace"
Summary:
Ref T603. Several issues here:
1. Currently, `FileQuery` does not actually respect object attachment edges when doing policy checks. Everything else works fine, but this was missing an `array_keys()`.
2. Once that's fixed, we hit a bunch of recursion issues. For example, when loading a User we load the profile picture, and then that loads the User, and that loads the profile picture, etc.
3. Introduce a "Query Workspace", which holds objects we know we've loaded and know we can see but haven't finished filtering and/or attaching data to. This allows subqueries to look up objects instead of querying for them.
- We can probably generalize this a bit to make a few other queries more efficient. Pholio currently has a similar (but less general) "mock cache". However, it's keyed by ID instead of PHID so it's not easy to reuse this right now.
This is a bit complex for the problem being solved, but I think it's the cleanest approach and I believe the primitive will be useful in the future.
Test Plan: Looked at pastes, macros, mocks and projects as a logged-in and logged-out user.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7309
2013-10-14 14:36:06 -07:00
|
|
|
foreach ($projects as $project) {
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
$file = idx($files, $project->getProfileImagePHID());
|
|
|
|
|
if (!$file) {
|
Fix some file policy issues and add a "Query Workspace"
Summary:
Ref T603. Several issues here:
1. Currently, `FileQuery` does not actually respect object attachment edges when doing policy checks. Everything else works fine, but this was missing an `array_keys()`.
2. Once that's fixed, we hit a bunch of recursion issues. For example, when loading a User we load the profile picture, and then that loads the User, and that loads the profile picture, etc.
3. Introduce a "Query Workspace", which holds objects we know we've loaded and know we can see but haven't finished filtering and/or attaching data to. This allows subqueries to look up objects instead of querying for them.
- We can probably generalize this a bit to make a few other queries more efficient. Pholio currently has a similar (but less general) "mock cache". However, it's keyed by ID instead of PHID so it's not easy to reuse this right now.
This is a bit complex for the problem being solved, but I think it's the cleanest approach and I believe the primitive will be useful in the future.
Test Plan: Looked at pastes, macros, mocks and projects as a logged-in and logged-out user.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7309
2013-10-14 14:36:06 -07:00
|
|
|
if (!$default) {
|
|
|
|
|
$default = PhabricatorFile::loadBuiltin(
|
|
|
|
|
$this->getViewer(),
|
2013-10-17 09:32:34 -07:00
|
|
|
'project.png');
|
2013-10-06 17:07:20 -07:00
|
|
|
}
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
$file = $default;
|
2013-10-06 17:07:20 -07:00
|
|
|
}
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
$project->attachProfileImageFile($file);
|
2013-10-06 17:07:20 -07:00
|
|
|
}
|
2012-01-17 16:29:35 -08:00
|
|
|
}
|
|
|
|
|
|
2015-12-27 02:28:36 -08:00
|
|
|
$this->loadSlugs($projects);
|
2014-05-22 11:19:03 -07:00
|
|
|
|
2012-01-17 16:29:35 -08:00
|
|
|
return $projects;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
2012-01-17 16:29:35 -08:00
|
|
|
|
2012-02-07 14:59:38 -08:00
|
|
|
if ($this->status != self::STATUS_ANY) {
|
|
|
|
|
switch ($this->status) {
|
|
|
|
|
case self::STATUS_OPEN:
|
|
|
|
|
case self::STATUS_ACTIVE:
|
2012-08-07 18:02:05 -07:00
|
|
|
$filter = array(
|
|
|
|
|
PhabricatorProjectStatus::STATUS_ACTIVE,
|
|
|
|
|
);
|
2012-02-07 14:59:38 -08:00
|
|
|
break;
|
2012-08-07 18:02:05 -07:00
|
|
|
case self::STATUS_CLOSED:
|
2012-02-07 14:59:38 -08:00
|
|
|
case self::STATUS_ARCHIVED:
|
2012-08-07 18:02:05 -07:00
|
|
|
$filter = array(
|
|
|
|
|
PhabricatorProjectStatus::STATUS_ARCHIVED,
|
|
|
|
|
);
|
2012-02-07 14:59:38 -08:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new Exception(
|
2015-05-22 17:27:56 +10:00
|
|
|
pht(
|
|
|
|
|
"Unknown project status '%s'!",
|
|
|
|
|
$this->status));
|
2012-02-07 14:59:38 -08:00
|
|
|
}
|
2012-08-07 18:02:05 -07:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2012-08-07 18:02:05 -07:00
|
|
|
'status IN (%Ld)',
|
|
|
|
|
$filter);
|
2012-02-07 14:59:38 -08:00
|
|
|
}
|
|
|
|
|
|
2016-02-06 12:40:31 -08:00
|
|
|
if ($this->statuses !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'status IN (%Ls)',
|
|
|
|
|
$this->statuses);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->ids !== null) {
|
2012-01-17 16:29:35 -08:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2012-01-17 16:29:35 -08:00
|
|
|
'id IN (%Ld)',
|
|
|
|
|
$this->ids);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->phids !== null) {
|
2012-01-17 16:29:35 -08:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2012-01-17 16:29:35 -08:00
|
|
|
'phid IN (%Ls)',
|
|
|
|
|
$this->phids);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->memberPHIDs !== null) {
|
2012-08-07 18:02:05 -07:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2012-08-11 07:05:01 -07:00
|
|
|
'e.dst IN (%Ls)',
|
2012-08-07 18:02:05 -07:00
|
|
|
$this->memberPHIDs);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->slugs !== null) {
|
2013-03-08 07:12:24 -08:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2014-05-22 11:19:03 -07:00
|
|
|
'slug.slug IN (%Ls)',
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
$this->allSlugs);
|
2013-03-08 07:12:24 -08:00
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->names !== null) {
|
2013-10-25 10:16:39 -07:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2013-10-25 10:16:39 -07:00
|
|
|
'name IN (%Ls)',
|
|
|
|
|
$this->names);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->icons !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2014-08-12 08:04:38 -07:00
|
|
|
'icon IN (%Ls)',
|
|
|
|
|
$this->icons);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->colors !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2014-08-12 08:04:38 -07:00
|
|
|
'color IN (%Ls)',
|
|
|
|
|
$this->colors);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 07:01:27 -08:00
|
|
|
if ($this->parentPHIDs !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'parentProjectPHID IN (%Ls)',
|
|
|
|
|
$this->parentPHIDs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->ancestorPHIDs !== null) {
|
|
|
|
|
$ancestor_paths = queryfx_all(
|
|
|
|
|
$conn,
|
|
|
|
|
'SELECT projectPath, projectDepth FROM %T WHERE phid IN (%Ls)',
|
|
|
|
|
id(new PhabricatorProject())->getTableName(),
|
|
|
|
|
$this->ancestorPHIDs);
|
|
|
|
|
if (!$ancestor_paths) {
|
|
|
|
|
throw new PhabricatorEmptyQueryException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = array();
|
|
|
|
|
foreach ($ancestor_paths as $ancestor_path) {
|
|
|
|
|
$sql[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'(projectPath LIKE %> AND projectDepth > %d)',
|
|
|
|
|
$ancestor_path['projectPath'],
|
|
|
|
|
$ancestor_path['projectDepth']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$where[] = '('.implode(' OR ', $sql).')';
|
|
|
|
|
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'parentProjectPHID IS NOT NULL');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->isMilestone !== null) {
|
|
|
|
|
if ($this->isMilestone) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'milestoneNumber IS NOT NULL');
|
|
|
|
|
} else {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'milestoneNumber IS NULL');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 03:12:20 -08:00
|
|
|
if ($this->hasSubprojects !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'hasSubprojects = %d',
|
|
|
|
|
(int)$this->hasSubprojects);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 07:01:27 -08:00
|
|
|
if ($this->minDepth !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'projectDepth >= %d',
|
|
|
|
|
$this->minDepth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->maxDepth !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'projectDepth <= %d',
|
|
|
|
|
$this->maxDepth);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
return $where;
|
2011-12-16 17:08:18 -08:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
protected function shouldGroupQueryResultRows() {
|
2015-04-15 11:49:07 -07:00
|
|
|
if ($this->memberPHIDs || $this->nameTokens) {
|
2015-06-08 12:20:53 -07:00
|
|
|
return true;
|
2012-08-07 18:02:05 -07:00
|
|
|
}
|
2015-06-08 12:20:53 -07:00
|
|
|
return parent::shouldGroupQueryResultRows();
|
2012-08-07 18:02:05 -07:00
|
|
|
}
|
2011-12-16 17:08:18 -08:00
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
|
$joins = parent::buildJoinClauseParts($conn);
|
2012-08-07 18:02:05 -07:00
|
|
|
|
2014-07-17 16:35:54 -07:00
|
|
|
if ($this->memberPHIDs !== null) {
|
2011-12-16 17:08:18 -08:00
|
|
|
$joins[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2012-08-11 07:05:01 -07:00
|
|
|
'JOIN %T e ON e.src = p.phid AND e.type = %d',
|
|
|
|
|
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
|
2015-12-27 04:27:58 -08:00
|
|
|
PhabricatorProjectMaterializedMemberEdgeType::EDGECONST);
|
2011-12-16 17:08:18 -08:00
|
|
|
}
|
|
|
|
|
|
2014-07-17 16:35:54 -07:00
|
|
|
if ($this->slugs !== null) {
|
2014-05-22 11:19:03 -07:00
|
|
|
$joins[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2014-05-22 11:19:03 -07:00
|
|
|
'JOIN %T slug on slug.projectPHID = p.phid',
|
|
|
|
|
id(new PhabricatorProjectSlug())->getTableName());
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-15 11:49:07 -07:00
|
|
|
if ($this->nameTokens !== null) {
|
|
|
|
|
foreach ($this->nameTokens as $key => $token) {
|
|
|
|
|
$token_table = 'token_'.$key;
|
|
|
|
|
$joins[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2015-04-15 11:49:07 -07:00
|
|
|
'JOIN %T %T ON %T.projectID = p.id AND %T.token LIKE %>',
|
|
|
|
|
PhabricatorProject::TABLE_DATASOURCE_TOKEN,
|
|
|
|
|
$token_table,
|
|
|
|
|
$token_table,
|
|
|
|
|
$token_table,
|
|
|
|
|
$token);
|
2014-07-17 16:35:54 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
return $joins;
|
2011-12-16 17:08:18 -08:00
|
|
|
}
|
|
|
|
|
|
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-21 17:20:27 -07:00
|
|
|
public function getQueryApplicationClass() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return 'PhabricatorProjectApplication';
|
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-21 17:20:27 -07:00
|
|
|
}
|
|
|
|
|
|
2015-04-11 19:00:53 -07:00
|
|
|
protected function getPrimaryTableAlias() {
|
|
|
|
|
return 'p';
|
2014-02-10 14:31:34 -08:00
|
|
|
}
|
|
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
private function linkProjectGraph(array $projects, array $ancestors) {
|
|
|
|
|
$ancestor_map = mpull($ancestors, null, 'getPHID');
|
|
|
|
|
$projects_map = mpull($projects, null, 'getPHID');
|
|
|
|
|
|
|
|
|
|
$all_map = $projects_map + $ancestor_map;
|
|
|
|
|
|
|
|
|
|
$done = array();
|
|
|
|
|
foreach ($projects as $key => $project) {
|
|
|
|
|
$seen = array($project->getPHID() => true);
|
|
|
|
|
|
|
|
|
|
if (!$this->linkProject($project, $all_map, $done, $seen)) {
|
|
|
|
|
$this->didRejectResult($project);
|
|
|
|
|
unset($projects[$key]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($project->getAncestorProjects() as $ancestor) {
|
|
|
|
|
$seen[$ancestor->getPHID()] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $projects;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function linkProject($project, array $all, array $done, array $seen) {
|
|
|
|
|
$parent_phid = $project->getParentProjectPHID();
|
|
|
|
|
|
|
|
|
|
// This project has no parent, so just attach `null` and return.
|
|
|
|
|
if (!$parent_phid) {
|
|
|
|
|
$project->attachParentProject(null);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This project has a parent, but it failed to load.
|
|
|
|
|
if (empty($all[$parent_phid])) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test for graph cycles. If we encounter one, we're going to hide the
|
|
|
|
|
// entire cycle since we can't meaningfully resolve it.
|
|
|
|
|
if (isset($seen[$parent_phid])) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$seen[$parent_phid] = true;
|
|
|
|
|
|
|
|
|
|
$parent = $all[$parent_phid];
|
|
|
|
|
$project->attachParentProject($parent);
|
|
|
|
|
|
|
|
|
|
if (!empty($done[$parent_phid])) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->linkProject($parent, $all, $done, $seen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getAllReachableAncestors(array $projects) {
|
|
|
|
|
$ancestors = array();
|
|
|
|
|
|
|
|
|
|
$seen = mpull($projects, null, 'getPHID');
|
|
|
|
|
|
|
|
|
|
$stack = $projects;
|
|
|
|
|
while ($stack) {
|
|
|
|
|
$project = array_pop($stack);
|
|
|
|
|
|
|
|
|
|
$phid = $project->getPHID();
|
|
|
|
|
$ancestors[$phid] = $project;
|
|
|
|
|
|
|
|
|
|
$parent_phid = $project->getParentProjectPHID();
|
|
|
|
|
if (!$parent_phid) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($seen[$parent_phid])) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$seen[$parent_phid] = true;
|
|
|
|
|
$stack[] = $project->getParentProject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ancestors;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 02:28:36 -08:00
|
|
|
private function loadSlugs(array $projects) {
|
|
|
|
|
// Build a map from primary slugs to projects.
|
|
|
|
|
$primary_map = array();
|
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
|
$primary_slug = $project->getPrimarySlug();
|
|
|
|
|
if ($primary_slug === null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$primary_map[$primary_slug] = $project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Link up all of the queried slugs which correspond to primary
|
|
|
|
|
// slugs. If we can link up everything from this (no slugs were queried,
|
|
|
|
|
// or only primary slugs were queried) we don't need to load anything
|
|
|
|
|
// else.
|
|
|
|
|
$unknown = $this->slugNormals;
|
|
|
|
|
foreach ($unknown as $input => $normal) {
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
if (isset($primary_map[$input])) {
|
|
|
|
|
$match = $input;
|
|
|
|
|
} else if (isset($primary_map[$normal])) {
|
|
|
|
|
$match = $normal;
|
|
|
|
|
} else {
|
2015-12-27 02:28:36 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->slugMap[$input] = array(
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
'slug' => $match,
|
|
|
|
|
'projectPHID' => $primary_map[$match]->getPHID(),
|
2015-12-27 02:28:36 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
unset($unknown[$input]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we need slugs, we have to load everything.
|
|
|
|
|
// If we still have some queried slugs which we haven't mapped, we only
|
|
|
|
|
// need to look for them.
|
|
|
|
|
// If we've mapped everything, we don't have to do any work.
|
|
|
|
|
$project_phids = mpull($projects, 'getPHID');
|
|
|
|
|
if ($this->needSlugs) {
|
|
|
|
|
$slugs = id(new PhabricatorProjectSlug())->loadAllWhere(
|
|
|
|
|
'projectPHID IN (%Ls)',
|
|
|
|
|
$project_phids);
|
|
|
|
|
} else if ($unknown) {
|
|
|
|
|
$slugs = id(new PhabricatorProjectSlug())->loadAllWhere(
|
|
|
|
|
'projectPHID IN (%Ls) AND slug IN (%Ls)',
|
|
|
|
|
$project_phids,
|
|
|
|
|
$unknown);
|
|
|
|
|
} else {
|
|
|
|
|
$slugs = array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Link up any slugs we were not able to link up earlier.
|
|
|
|
|
$extra_map = mpull($slugs, 'getProjectPHID', 'getSlug');
|
|
|
|
|
foreach ($unknown as $input => $normal) {
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
if (isset($extra_map[$input])) {
|
|
|
|
|
$match = $input;
|
|
|
|
|
} else if (isset($extra_map[$normal])) {
|
|
|
|
|
$match = $normal;
|
|
|
|
|
} else {
|
2015-12-27 02:28:36 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->slugMap[$input] = array(
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
'slug' => $match,
|
|
|
|
|
'projectPHID' => $extra_map[$match],
|
2015-12-27 02:28:36 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
unset($unknown[$input]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->needSlugs) {
|
|
|
|
|
$slug_groups = mgroup($slugs, 'getProjectPHID');
|
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
|
$project_slugs = idx($slug_groups, $project->getPHID(), array());
|
|
|
|
|
$project->attachSlugs($project_slugs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-16 17:08:18 -08:00
|
|
|
}
|