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)
|
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
|
|
|
|
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);
|
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()))
|
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
|
|
|
$content = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('Open Tasks'))
|
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')
|
|
|
|
->setHref($this->getApplicationURI("edit/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
2014-02-10 14:30:47 -08:00
|
|
|
if ($project->isArchived()) {
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Unarchive Project'))
|
|
|
|
->setIcon('enable')
|
|
|
|
->setHref($this->getApplicationURI("archive/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(true));
|
|
|
|
} else {
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Archive Project'))
|
|
|
|
->setIcon('disable')
|
|
|
|
->setHref($this->getApplicationURI("archive/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(true));
|
|
|
|
}
|
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
$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);
|
|
|
|
|
Make Projects a PhabricatorSubscribableInterface, but with restricted defaults
Summary:
Ref T4379. I want project subscriptions to work like this (yell if this seems whacky, since it makes subscriptions mean somethign a little different for projects than they do for other objects):
- You can only subscribe to a project if you're a project member.
- When you're added as a member, you're added as a subscriber.
- When you're removed as a member, you're removed as a subscriber.
- While you're a member, you can optionally unsubscribe.
From a UI perspective:
- We don't show the subscriber list, since it's going to be some uninteresting subset of the member list.
- We don't show CC transactions in history, since they're an uninteresting near-approximation of the membership transactions.
- You only see the subscription controls if you're a member.
To do this, I've augmented `PhabricatorSubscribableInterface` with two new methods. It would be nice if we were on PHP 5.4+ and could just use traits for this, but we should get data about version usage before we think about this. For now, copy/paste the default implementations into every implementing class.
Then, I implemented the interface in `PhabricatorProject` but with alternate defaults.
Test Plan:
- Used the normal interaction on existing objects.
- This has no actual effect on projects, verified no subscription stuff mysteriously appeared.
- Hit the new error case by fiddling with the UI.
Reviewers: btrahan
Reviewed By: btrahan
CC: chad, aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8165
2014-02-10 14:29:17 -08:00
|
|
|
|
2013-10-22 13:49:37 -07:00
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('View History'))
|
|
|
|
->setHref($this->getApplicationURI("history/{$id}/"))
|
|
|
|
->setIcon('transcript'));
|
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
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
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Created'),
|
|
|
|
phabricator_datetime($project->getDateCreated(), $viewer));
|
|
|
|
|
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
|
|
|
}
|