2011-02-20 18:41:23 -08:00
|
|
|
<?php
|
|
|
|
|
2012-03-09 15:46:25 -08:00
|
|
|
final class PhabricatorProjectProfileController
|
2011-02-20 18:41:23 -08:00
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
|
|
|
private $id;
|
2011-06-18 05:13:56 -03:00
|
|
|
private $page;
|
2011-02-20 18:41:23 -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
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-20 18:41:23 -08:00
|
|
|
public function willProcessRequest(array $data) {
|
2011-06-18 05:13:56 -03:00
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
$this->page = idx($data, 'page');
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
2011-06-18 05:13:56 -03:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2013-10-06 17:07:20 -07:00
|
|
|
$project = id(new PhabricatorProjectQuery())
|
2012-08-15 10:44:58 -07:00
|
|
|
->setViewer($user)
|
2013-04-15 13:07:54 -07:00
|
|
|
->withIDs(array($this->id))
|
2013-10-06 17:07:20 -07:00
|
|
|
->needMembers(true)
|
|
|
|
->needProfiles(true)
|
|
|
|
->executeOne();
|
2011-02-20 18:41:23 -08:00
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2012-08-15 10:44:58 -07:00
|
|
|
|
2013-10-06 17:07:20 -07:00
|
|
|
$profile = $project->getProfile();
|
2013-10-06 17:07:43 -07:00
|
|
|
$picture = $profile->getProfileImageURI();
|
2011-06-18 05:13:56 -03:00
|
|
|
|
2011-12-16 20:01:38 -08:00
|
|
|
require_celerity_resource('phabricator-profile-css');
|
|
|
|
|
2013-04-15 13:07:54 -07:00
|
|
|
$tasks = $this->renderTasksPage($project, $profile);
|
|
|
|
|
|
|
|
$query = new PhabricatorFeedQuery();
|
|
|
|
$query->setFilterPHIDs(
|
|
|
|
array(
|
|
|
|
$project->getPHID(),
|
|
|
|
));
|
|
|
|
$query->setLimit(50);
|
|
|
|
$query->setViewer($this->getRequest()->getUser());
|
|
|
|
$stories = $query->execute();
|
|
|
|
$feed = $this->renderStories($stories);
|
|
|
|
$people = $this->renderPeoplePage($project, $profile);
|
|
|
|
|
|
|
|
$content = id(new AphrontMultiColumnView())
|
2013-07-22 09:01:22 -07:00
|
|
|
->addColumn($people)
|
2013-04-15 13:07:54 -07:00
|
|
|
->addColumn($feed)
|
|
|
|
->setFluidLayout(true);
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2013-04-15 13:07:54 -07:00
|
|
|
$content = hsprintf(
|
|
|
|
'<div class="phabricator-project-layout">%s%s</div>',
|
|
|
|
$tasks,
|
|
|
|
$content);
|
2011-12-16 20:01:38 -08:00
|
|
|
|
2013-09-17 09:12:37 -07:00
|
|
|
$header = id(new PHUIHeaderView())
|
2013-07-09 16:23:22 -07:00
|
|
|
->setHeader($project->getName())
|
2013-10-21 11:34:45 -07:00
|
|
|
->setUser($user)
|
|
|
|
->setPolicyObject($project)
|
2013-07-09 16:23:22 -07:00
|
|
|
->setImage($picture);
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2013-10-21 11:34:45 -07:00
|
|
|
if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ACTIVE) {
|
|
|
|
$header->setStatus('oh-ok', '', pht('Active'));
|
|
|
|
} else {
|
|
|
|
$header->setStatus('policy-noone', '', pht('Archived'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
$actions = $this->buildActionListView($project);
|
2013-10-21 11:34:45 -07:00
|
|
|
$properties = $this->buildPropertyListView($project, $profile, $actions);
|
2013-07-09 16:23:22 -07:00
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName($project->getName()));
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2013-09-28 15:55:38 -07:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
2013-10-11 07:53:56 -07:00
|
|
|
->addPropertyList($properties);
|
2013-09-28 15:55:38 -07:00
|
|
|
|
2013-02-13 09:22:14 -08:00
|
|
|
return $this->buildApplicationPage(
|
2011-02-20 18:41:23 -08:00
|
|
|
array(
|
2013-07-22 09:01:22 -07:00
|
|
|
$crumbs,
|
2013-09-28 15:55:38 -07:00
|
|
|
$object_box,
|
2013-07-22 09:01:22 -07:00
|
|
|
$content,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $project->getName(),
|
2013-04-15 13:07:54 -07:00
|
|
|
'device' => true,
|
2011-12-16 20:01:38 -08:00
|
|
|
));
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|
|
|
|
|
2011-12-16 20:01:38 -08:00
|
|
|
private function renderPeoplePage(
|
|
|
|
PhabricatorProject $project,
|
|
|
|
PhabricatorProjectProfile $profile) {
|
|
|
|
|
2012-08-15 10:44:58 -07:00
|
|
|
$member_phids = $project->getMemberPHIDs();
|
2012-09-04 19:02:56 -07:00
|
|
|
$handles = $this->loadViewerHandles($member_phids);
|
2011-12-16 20:01:38 -08:00
|
|
|
|
|
|
|
$affiliated = array();
|
2012-08-07 11:55:00 -07:00
|
|
|
foreach ($handles as $phids => $handle) {
|
2013-02-13 14:50:15 -08:00
|
|
|
$affiliated[] = phutil_tag('li', array(), $handle->renderLink());
|
2011-12-16 20:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($affiliated) {
|
2013-02-13 14:50:15 -08:00
|
|
|
$affiliated = phutil_tag('ul', array(), $affiliated);
|
2011-12-16 20:01:38 -08:00
|
|
|
} else {
|
2013-02-13 14:50:15 -08:00
|
|
|
$affiliated = hsprintf('<p><em>%s</em></p>', pht(
|
|
|
|
'No one is affiliated with this project.'));
|
2011-12-16 20:01:38 -08:00
|
|
|
}
|
|
|
|
|
2013-02-13 14:50:15 -08:00
|
|
|
return hsprintf(
|
2013-04-15 13:07:54 -07:00
|
|
|
'<div class="phabricator-profile-info-group profile-wrap-responsive">'.
|
2013-02-13 14:50:15 -08:00
|
|
|
'<h1 class="phabricator-profile-info-header">%s</h1>'.
|
|
|
|
'<div class="phabricator-profile-info-pane">%s</div>'.
|
|
|
|
'</div>',
|
|
|
|
pht('People'),
|
|
|
|
$affiliated);
|
2011-12-16 20:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderFeedPage(
|
|
|
|
PhabricatorProject $project,
|
|
|
|
PhabricatorProjectProfile $profile) {
|
|
|
|
|
|
|
|
$query = new PhabricatorFeedQuery();
|
|
|
|
$query->setFilterPHIDs(array($project->getPHID()));
|
2012-07-02 15:41:19 -07:00
|
|
|
$query->setViewer($this->getRequest()->getUser());
|
2012-07-03 06:25:03 -07:00
|
|
|
$query->setLimit(100);
|
2011-12-16 20:01:38 -08:00
|
|
|
$stories = $query->execute();
|
|
|
|
|
|
|
|
if (!$stories) {
|
2013-02-13 09:22:14 -08:00
|
|
|
return pht('There are no stories about this project.');
|
2011-12-16 20:01:38 -08:00
|
|
|
}
|
|
|
|
|
2011-12-22 08:22:07 -08:00
|
|
|
return $this->renderStories($stories);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderStories(array $stories) {
|
2012-04-03 12:10:45 -07:00
|
|
|
assert_instances_of($stories, 'PhabricatorFeedStory');
|
2011-12-22 08:22:07 -08:00
|
|
|
|
2011-12-16 20:01:38 -08:00
|
|
|
$builder = new PhabricatorFeedBuilder($stories);
|
|
|
|
$builder->setUser($this->getRequest()->getUser());
|
2013-08-14 13:20:25 -07:00
|
|
|
$builder->setShowHovercards(true);
|
2011-12-16 20:01:38 -08:00
|
|
|
$view = $builder->buildView();
|
|
|
|
|
2013-02-13 14:50:15 -08:00
|
|
|
return hsprintf(
|
2013-04-15 13:07:54 -07:00
|
|
|
'<div class="profile-feed profile-wrap-responsive">'.
|
|
|
|
'%s'.
|
2013-02-13 14:50:15 -08:00
|
|
|
'</div>',
|
|
|
|
$view->render());
|
2011-12-16 20:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function renderTasksPage(
|
|
|
|
PhabricatorProject $project,
|
|
|
|
PhabricatorProjectProfile $profile) {
|
2011-07-07 14:01:55 -07:00
|
|
|
|
2013-03-23 14:38:01 -07:00
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
2011-07-07 14:01:55 -07:00
|
|
|
$query = id(new ManiphestTaskQuery())
|
2013-09-10 07:44:22 -07:00
|
|
|
->setViewer($user)
|
2012-10-04 15:31:04 -07:00
|
|
|
->withAnyProjects(array($project->getPHID()))
|
2011-07-07 14:01:55 -07:00
|
|
|
->withStatus(ManiphestTaskQuery::STATUS_OPEN)
|
|
|
|
->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)
|
2013-09-25 13:44:36 -07:00
|
|
|
->setLimit(10);
|
2011-07-07 14:01:55 -07:00
|
|
|
$tasks = $query->execute();
|
|
|
|
|
2011-07-07 16:06:27 -07:00
|
|
|
$phids = mpull($tasks, 'getOwnerPHID');
|
2013-03-23 14:38:01 -07:00
|
|
|
$phids = array_merge(
|
|
|
|
$phids,
|
|
|
|
array_mergev(mpull($tasks, 'getProjectPHIDs')));
|
2011-07-07 16:06:27 -07:00
|
|
|
$phids = array_filter($phids);
|
2012-09-04 19:02:56 -07:00
|
|
|
$handles = $this->loadViewerHandles($phids);
|
2011-07-07 16:06:27 -07:00
|
|
|
|
2013-03-23 14:38:01 -07:00
|
|
|
$task_list = new ManiphestTaskListView();
|
|
|
|
$task_list->setUser($user);
|
|
|
|
$task_list->setTasks($tasks);
|
|
|
|
$task_list->setHandles($handles);
|
2011-07-07 14:01:55 -07:00
|
|
|
|
2013-09-28 15:55:38 -07:00
|
|
|
$list = id(new PHUIBoxView())
|
|
|
|
->addPadding(PHUI::PADDING_LARGE)
|
|
|
|
->appendChild($task_list);
|
|
|
|
|
|
|
|
$content = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('Open Tasks'))
|
Provide more structure to PHUIObjectBoxView
Summary:
Three changes here.
- Add `setActionList()`, and use that to set the action list.
- Add `setPropertyList()`, and use that to set the property list.
These will let us add some apropriate CSS so we can fix the border issue, and get rid of a bunch of goofy `.x + .y` selectors.
- Replace `addContent()` with `appendChild()`.
This is just a consistency thing; `AphrontView` already provides `appendChild()`, and `addContent()` did the same thing.
Test Plan:
- Viewed "All Config".
- Viewed a countdown.
- Viewed a revision (add comment, change list, table of contents, comment, local commits, open revisions affecting these files, update history).
- Viewed Diffusion (browse, change, history, repository, lint).
- Viewed Drydock (resource, lease).
- Viewed Files.
- Viewed Herald.
- Viewed Legalpad.
- Viewed macro (edit, edit audio, view).
- Viewed Maniphest.
- Viewed Applications.
- Viewed Paste.
- Viewed People.
- Viewed Phulux.
- Viewed Pholio.
- Viewed Phame (blog, post).
- Viewed Phortune (account, product).
- Viewed Ponder (questions, answers, comments).
- Viewed Releeph.
- Viewed Projects.
- Viewed Slowvote.
NOTE: Images in Files aren't on a black background anymore -- I assume that's on purpose?
NOTE: Some jankiness in Phortune, I'll clean that up when I get back to it. Not related to this diff.
Reviewers: chad
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D7174
2013-09-30 09:36:04 -07:00
|
|
|
->appendChild($list);
|
2011-06-18 05:13:56 -03:00
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
2011-07-19 15:50:15 -03:00
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
private function buildActionListView(PhabricatorProject $project) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$id = $project->getID();
|
|
|
|
|
|
|
|
$view = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($project)
|
|
|
|
->setObjectURI($request->getRequestURI());
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$project,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Project'))
|
|
|
|
->setIcon('edit')
|
|
|
|
->setHref($this->getApplicationURI("edit/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Members'))
|
|
|
|
->setIcon('edit')
|
|
|
|
->setHref($this->getApplicationURI("members/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
2013-10-17 09:32:34 -07:00
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Picture'))
|
|
|
|
->setIcon('image')
|
|
|
|
->setHref($this->getApplicationURI("picture/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
|
|
|
|
$action = null;
|
|
|
|
if (!$project->isUserMember($viewer->getPHID())) {
|
|
|
|
$can_join = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$project,
|
|
|
|
PhabricatorPolicyCapability::CAN_JOIN);
|
|
|
|
|
|
|
|
$action = id(new PhabricatorActionView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setRenderAsForm(true)
|
|
|
|
->setHref('/project/update/'.$project->getID().'/join/')
|
|
|
|
->setIcon('new')
|
|
|
|
->setDisabled(!$can_join)
|
|
|
|
->setName(pht('Join Project'));
|
|
|
|
} else {
|
|
|
|
$action = id(new PhabricatorActionView())
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setHref('/project/update/'.$project->getID().'/leave/')
|
|
|
|
->setIcon('delete')
|
|
|
|
->setName(pht('Leave Project...'));
|
|
|
|
}
|
|
|
|
$view->addAction($action);
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2013-10-11 07:53:56 -07:00
|
|
|
private function buildPropertyListView(
|
|
|
|
PhabricatorProject $project,
|
2013-10-21 11:34:45 -07:00
|
|
|
PhabricatorProjectProfile $profile,
|
2013-10-11 07:53:56 -07:00
|
|
|
PhabricatorActionListView $actions) {
|
2013-07-22 09:01:22 -07:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
2013-10-11 07:53:56 -07:00
|
|
|
$view = id(new PHUIPropertyListView())
|
2013-07-22 09:01:22 -07:00
|
|
|
->setUser($viewer)
|
2013-10-11 07:53:56 -07:00
|
|
|
->setObject($project)
|
|
|
|
->setActionList($actions);
|
2013-07-22 09:01:22 -07:00
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Created'),
|
|
|
|
phabricator_datetime($project->getDateCreated(), $viewer));
|
|
|
|
|
2013-10-21 11:34:45 -07:00
|
|
|
$view->addSectionHeader(pht('Description'));
|
|
|
|
$view->addTextContent(
|
|
|
|
PhabricatorMarkupEngine::renderOneObject(
|
|
|
|
id(new PhabricatorMarkupOneOff())->setContent($profile->getBlurb()),
|
|
|
|
'default',
|
|
|
|
$viewer));
|
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
return $view;
|
2013-04-15 13:07:54 -07:00
|
|
|
}
|
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|