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 {
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 10:04:01 -08:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2015-12-27 02:04:37 -08:00
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
|
|
$response = $this->loadProject();
|
|
|
|
|
if ($response) {
|
|
|
|
|
return $response;
|
2014-05-22 15:16:16 -07:00
|
|
|
}
|
2012-08-15 10:44:58 -07:00
|
|
|
|
2015-12-27 02:04:37 -08:00
|
|
|
$project = $this->getProject();
|
|
|
|
|
$id = $project->getID();
|
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();
|
2014-02-13 14:36:49 -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())
|
2015-12-27 02:04:37 -08:00
|
|
|
->setUser($viewer)
|
2013-10-21 11:34:45 -07:00
|
|
|
->setPolicyObject($project)
|
2015-01-19 10:14:27 -08: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) {
|
2014-05-18 16:10:54 -07:00
|
|
|
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
|
2013-10-21 11:34:45 -07:00
|
|
|
} else {
|
2015-01-06 11:13:04 -08:00
|
|
|
$header->setStatus('fa-ban', 'red', pht('Archived'));
|
2013-10-21 11:34:45 -07:00
|
|
|
}
|
|
|
|
|
|
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-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
|
|
|
|
2015-01-19 10:14:27 -08:00
|
|
|
$timeline = $this->buildTransactionTimeline(
|
|
|
|
|
$project,
|
|
|
|
|
new PhabricatorProjectTransactionQuery());
|
|
|
|
|
$timeline->setShouldTerminate(true);
|
|
|
|
|
|
2016-01-12 14:15:59 -08:00
|
|
|
$nav = $this->getProfileMenu();
|
2016-01-12 10:27:39 -08:00
|
|
|
$nav->selectFilter(PhabricatorProject::PANEL_PROFILE);
|
2015-12-27 02:04:37 -08:00
|
|
|
|
2015-12-27 04:10:59 -08:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
|
|
2015-12-27 02:04:37 -08:00
|
|
|
return $this->newPage()
|
|
|
|
|
->setNavigation($nav)
|
2015-12-27 04:10:59 -08:00
|
|
|
->setCrumbs($crumbs)
|
2015-12-27 02:04:37 -08:00
|
|
|
->setTitle($project->getName())
|
|
|
|
|
->setPageObjectPHIDs(array($project->getPHID()))
|
|
|
|
|
->appendChild($object_box)
|
|
|
|
|
->appendChild($timeline);
|
2011-02-20 18:41:23 -08: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)
|
Remove all setObjectURI() from ActionListViews
Summary:
Ref T10004. After D14804, we get this behavior by default and no longer need to set it explicitly.
(If some endpoint did eventually need to set it explicitly, it could just change what it passes to `setHref()`, but I believe we currently have no such endpoints and do not foresee ever having any.)
Test Plan:
- As a logged out user, clicked various links in Differential, Maniphest, Files, etc., always got redirected to a sensible place after login.
- Grepped for `setObjectURI()`, `getObjectURI()` (there are a few remaining callsites, but to a different method with the same name in Doorkeeper).
Reviewers: chad
Reviewed By: chad
Subscribers: hach-que
Maniphest Tasks: T10004
Differential Revision: https://secure.phabricator.com/D14805
2015-12-17 06:31:33 -08:00
|
|
|
->setObject($project);
|
2013-07-22 09:01:22 -07:00
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
|
$viewer,
|
|
|
|
|
$project,
|
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
2015-01-14 11:17:22 -08:00
|
|
|
$view->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
2015-01-19 10:14:27 -08:00
|
|
|
->setName(pht('Edit Details'))
|
2015-01-14 11:17:22 -08:00
|
|
|
->setIcon('fa-pencil')
|
2015-12-27 06:45:53 -08:00
|
|
|
->setHref($this->getApplicationURI("edit/{$id}/"))
|
2015-12-23 16:29:06 -08:00
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
|
->setWorkflow(!$can_edit));
|
2015-01-14 11:17:22 -08:00
|
|
|
|
2015-01-19 10:14:27 -08:00
|
|
|
$view->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setName(pht('Edit Picture'))
|
|
|
|
|
->setIcon('fa-picture-o')
|
|
|
|
|
->setHref($this->getApplicationURI("picture/{$id}/"))
|
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
|
|
|
|
|
if ($project->isArchived()) {
|
|
|
|
|
$view->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setName(pht('Activate Project'))
|
|
|
|
|
->setIcon('fa-check')
|
|
|
|
|
->setHref($this->getApplicationURI("archive/{$id}/"))
|
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
|
->setWorkflow(true));
|
|
|
|
|
} else {
|
|
|
|
|
$view->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setName(pht('Archive Project'))
|
|
|
|
|
->setIcon('fa-ban')
|
|
|
|
|
->setHref($this->getApplicationURI("archive/{$id}/"))
|
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
|
->setWorkflow(true));
|
|
|
|
|
}
|
2015-01-14 11:17:22 -08:00
|
|
|
|
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-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
|
|
|
|
2014-07-05 10:16:47 -07:00
|
|
|
$hashtags = array();
|
|
|
|
|
foreach ($project->getSlugs() as $slug) {
|
|
|
|
|
$hashtags[] = id(new PHUITagView())
|
|
|
|
|
->setType(PHUITagView::TYPE_OBJECT)
|
|
|
|
|
->setName('#'.$slug->getSlug());
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-29 04:38:21 -08:00
|
|
|
if ($hashtags) {
|
|
|
|
|
$view->addProperty(pht('Hashtags'), phutil_implode_html(' ', $hashtags));
|
|
|
|
|
}
|
2014-07-05 10:16:47 -07:00
|
|
|
|
2013-12-31 16:28:35 -08:00
|
|
|
$view->addProperty(
|
|
|
|
|
pht('Members'),
|
|
|
|
|
$project->getMemberPHIDs()
|
2015-03-30 07:39:37 -07:00
|
|
|
? $viewer
|
|
|
|
|
->renderHandleList($project->getMemberPHIDs())
|
|
|
|
|
->setAsInline(true)
|
2014-05-19 12:40:57 -07:00
|
|
|
: phutil_tag('em', array(), pht('None')));
|
|
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
|
pht('Watchers'),
|
|
|
|
|
$project->getWatcherPHIDs()
|
2015-03-30 07:39:37 -07:00
|
|
|
? $viewer
|
|
|
|
|
->renderHandleList($project->getWatcherPHIDs())
|
|
|
|
|
->setAsInline(true)
|
2014-05-19 12:40:57 -07:00
|
|
|
: phutil_tag('em', array(), pht('None')));
|
2013-12-31 16:28:35 -08:00
|
|
|
|
2015-01-19 10:14:27 -08:00
|
|
|
$view->addProperty(
|
|
|
|
|
pht('Looks Like'),
|
2015-03-30 07:39:37 -07:00
|
|
|
$viewer->renderHandle($project->getPHID())->setAsTag(true));
|
2015-01-19 10:14:27 -08:00
|
|
|
|
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
|
|
|
}
|