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;
|
|
|
|
|
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');
|
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)
|
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
|
|
|
->needImages(true)
|
2013-10-06 17:07:20 -07:00
|
|
|
->executeOne();
|
2011-02-20 18:41:23 -08:00
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2012-08-15 10:44:58 -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
|
|
|
$picture = $project->getProfileImageURI();
|
2011-06-18 05:13:56 -03:00
|
|
|
|
2011-12-16 20:01:38 -08:00
|
|
|
require_celerity_resource('phabricator-profile-css');
|
|
|
|
|
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
|
|
|
$tasks = $this->renderTasksPage($project);
|
2013-04-15 13:07:54 -07:00
|
|
|
|
|
|
|
$query = new PhabricatorFeedQuery();
|
|
|
|
$query->setFilterPHIDs(
|
|
|
|
array(
|
|
|
|
$project->getPHID(),
|
|
|
|
));
|
|
|
|
$query->setLimit(50);
|
|
|
|
$query->setViewer($this->getRequest()->getUser());
|
|
|
|
$stories = $query->execute();
|
|
|
|
$feed = $this->renderStories($stories);
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2013-11-11 09:23:23 -08:00
|
|
|
$content = phutil_tag_div(
|
|
|
|
'phabricator-project-layout',
|
2013-12-31 16:28:35 -08:00
|
|
|
array($tasks, $feed));
|
2011-12-16 20:01:38 -08:00
|
|
|
|
2014-02-13 14:36:49 -08:00
|
|
|
$id = $this->id;
|
|
|
|
$icon = id(new PHUIIconView())
|
|
|
|
->setSpriteSheet(PHUIIconView::SPRITE_ICONS)
|
|
|
|
->setSpriteIcon('workboard');
|
|
|
|
$board_btn = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setText(pht('Workboards'))
|
|
|
|
->setHref($this->getApplicationURI("board/{$id}/"))
|
|
|
|
->setIcon($icon);
|
|
|
|
|
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)
|
2014-02-13 14:36:49 -08:00
|
|
|
->setImage($picture)
|
|
|
|
->addActionLink($board_btn);
|
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);
|
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
|
|
|
$properties = $this->buildPropertyListView($project, $actions);
|
2013-07-09 16:23:22 -07:00
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-18 17:47:34 -08:00
|
|
|
$crumbs->addTextCrumb($project->getName())
|
2013-11-27 12:03:30 -08:00
|
|
|
->setActionList($actions);
|
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
|
|
|
}
|
|
|
|
|
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 function renderFeedPage(PhabricatorProject $project) {
|
2011-12-16 20:01:38 -08:00
|
|
|
|
|
|
|
$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-11-11 09:23:23 -08:00
|
|
|
return phutil_tag_div(
|
2013-12-31 16:28:35 -08:00
|
|
|
'profile-feed',
|
2013-02-13 14:50:15 -08:00
|
|
|
$view->render());
|
2011-12-16 20:01:38 -08: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
|
|
|
private function renderTasksPage(PhabricatorProject $project) {
|
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()))
|
2014-02-17 15:59:31 -08:00
|
|
|
->withStatuses(ManiphestTaskStatus::getOpenStatusConstants())
|
2011-07-07 14:01:55 -07:00
|
|
|
->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
|
|
|
|
2014-02-13 14:36:49 -08:00
|
|
|
$phid = $project->getPHID();
|
|
|
|
$view_uri = '/maniphest/?statuses[]=0&allProjects[]='.$phid.'#R';
|
|
|
|
$create_uri = '/maniphest/task/create/?projects='.$phid;
|
|
|
|
$icon = id(new PHUIIconView())
|
|
|
|
->setSpriteSheet(PHUIIconView::SPRITE_ICONS)
|
|
|
|
->setSpriteIcon('action-menu');
|
|
|
|
$button_view = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setText(pht('View All'))
|
|
|
|
->setHref($view_uri)
|
|
|
|
->setIcon($icon);
|
|
|
|
$icon_new = id(new PHUIIconView())
|
|
|
|
->setSpriteSheet(PHUIIconView::SPRITE_ICONS)
|
|
|
|
->setSpriteIcon('new');
|
|
|
|
$button_add = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setText(pht('New Task'))
|
|
|
|
->setHref($create_uri)
|
|
|
|
->setIcon($icon_new);
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('Open Tasks'))
|
|
|
|
->addActionLink($button_add)
|
|
|
|
->addActionLink($button_view);
|
|
|
|
|
2013-09-28 15:55:38 -07:00
|
|
|
$content = id(new PHUIObjectBoxView())
|
2014-02-13 14:36:49 -08:00
|
|
|
->setHeader($header)
|
2013-12-31 15:27:05 -08:00
|
|
|
->appendChild($task_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')
|
2014-02-16 20:17:52 -08:00
|
|
|
->setHref($this->getApplicationURI("edit/{$id}/")));
|
2014-02-10 14:30:47 -08:00
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Members'))
|
2014-02-16 20:17:52 -08:00
|
|
|
->setIcon('user')
|
2013-07-22 09:01:22 -07:00
|
|
|
->setHref($this->getApplicationURI("members/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
|
|
|
$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,
|
|
|
|
PhabricatorActionListView $actions) {
|
2013-07-22 09:01:22 -07:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
2013-12-31 16:28:35 -08:00
|
|
|
$this->loadHandles($project->getMemberPHIDs());
|
|
|
|
|
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
|
|
|
|
2013-12-31 16:28:35 -08:00
|
|
|
$view->addProperty(
|
|
|
|
pht('Members'),
|
|
|
|
$project->getMemberPHIDs()
|
|
|
|
? $this->renderHandlesForPHIDs($project->getMemberPHIDs(), ',')
|
|
|
|
: phutil_tag('em', array(), pht('None')));
|
|
|
|
|
2014-02-10 14:31:34 -08:00
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
$project,
|
|
|
|
PhabricatorCustomField::ROLE_VIEW);
|
|
|
|
$field_list->appendFieldsToPropertyList($project, $viewer, $view);
|
|
|
|
|
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
|
|
|
}
|