2011-01-24 03:09:16 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorPeopleProfileController
|
|
|
|
extends PhabricatorPeopleController {
|
2011-01-24 03:09:16 +01:00
|
|
|
|
|
|
|
private $username;
|
|
|
|
|
2013-03-19 21:48:50 +01:00
|
|
|
public function shouldRequireAdmin() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-24 03:09:16 +01:00
|
|
|
public function willProcessRequest(array $data) {
|
2011-06-18 10:13:56 +02:00
|
|
|
$this->username = idx($data, 'username');
|
2013-02-05 22:46:02 +01:00
|
|
|
}
|
|
|
|
|
2011-01-24 03:09:16 +01:00
|
|
|
public function processRequest() {
|
2011-02-20 02:33:53 +01:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2013-07-10 14:10:54 +02:00
|
|
|
$user = id(new PhabricatorPeopleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withUsernames(array($this->username))
|
2013-09-08 18:43:27 +02:00
|
|
|
->needProfileImage(true)
|
2013-07-10 14:10:54 +02:00
|
|
|
->executeOne();
|
2011-01-24 03:09:16 +01:00
|
|
|
if (!$user) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2011-12-24 03:17:40 +01:00
|
|
|
require_celerity_resource('phabricator-profile-css');
|
|
|
|
|
2013-03-24 14:42:31 +01:00
|
|
|
$profile = $user->loadUserProfile();
|
2012-03-06 22:57:31 +01:00
|
|
|
$username = phutil_escape_uri($user->getUserName());
|
2011-02-20 03:28:41 +01:00
|
|
|
|
2012-04-28 02:44:10 +02:00
|
|
|
$picture = $user->loadProfileImageURI();
|
2011-12-24 03:17:40 +01:00
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
2013-07-10 01:23:22 +02:00
|
|
|
->setHeader($user->getUserName().' ('.$user->getRealName().')')
|
|
|
|
->setSubheader($profile->getTitle())
|
|
|
|
->setImage($picture);
|
2011-12-24 03:17:40 +01:00
|
|
|
|
2013-07-10 01:23:45 +02:00
|
|
|
$actions = id(new PhabricatorActionListView())
|
2013-07-10 14:11:08 +02:00
|
|
|
->setObject($user)
|
2013-07-12 20:39:47 +02:00
|
|
|
->setObjectURI($this->getRequest()->getRequestURI())
|
2013-07-10 01:23:45 +02:00
|
|
|
->setUser($viewer);
|
2011-12-24 03:17:40 +01:00
|
|
|
|
2013-07-10 01:23:45 +02:00
|
|
|
$can_edit = ($user->getPHID() == $viewer->getPHID());
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('edit')
|
|
|
|
->setName(pht('Edit Profile'))
|
|
|
|
->setHref($this->getApplicationURI('editprofile/'.$user->getID().'/'))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2013-07-10 01:23:54 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('image')
|
|
|
|
->setName(pht('Edit Profile Picture'))
|
|
|
|
->setHref($this->getApplicationURI('picture/'.$user->getID().'/'))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
2012-01-17 01:54:05 +01:00
|
|
|
if ($viewer->getIsAdmin()) {
|
2013-07-10 01:23:45 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('blame')
|
|
|
|
->setName(pht('Administrate User'))
|
|
|
|
->setHref($this->getApplicationURI('edit/'.$user->getID().'/')));
|
2012-01-17 01:54:05 +01:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:09:59 +02:00
|
|
|
$properties = $this->buildPropertyView($user);
|
|
|
|
|
2013-07-10 14:11:08 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName($user->getUsername()));
|
|
|
|
$feed = $this->renderUserFeed($user);
|
2013-07-10 01:23:45 +02:00
|
|
|
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
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 18:36:04 +02:00
|
|
|
->setActionList($actions)
|
|
|
|
->setPropertyList($properties);
|
2013-09-29 00:55:38 +02:00
|
|
|
|
2012-08-14 00:27:21 +02:00
|
|
|
return $this->buildApplicationPage(
|
2013-07-10 14:11:08 +02:00
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box,
|
2013-07-10 14:11:08 +02:00
|
|
|
$feed,
|
|
|
|
),
|
2011-02-20 02:33:53 +01:00
|
|
|
array(
|
2011-06-18 10:13:56 +02:00
|
|
|
'title' => $user->getUsername(),
|
2013-04-15 04:32:26 +02:00
|
|
|
'device' => true,
|
2011-02-20 02:33:53 +01:00
|
|
|
));
|
2011-06-18 10:13:56 +02:00
|
|
|
}
|
2011-02-20 02:33:53 +01:00
|
|
|
|
2013-07-10 14:09:59 +02:00
|
|
|
private function buildPropertyView(PhabricatorUser $user) {
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
2011-12-24 03:17:40 +01:00
|
|
|
|
2013-07-10 14:09:59 +02:00
|
|
|
$view = id(new PhabricatorPropertyListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($user);
|
2011-02-20 03:28:41 +01:00
|
|
|
|
2013-08-14 18:40:42 +02:00
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
2013-07-10 14:09:59 +02:00
|
|
|
$user,
|
|
|
|
PhabricatorCustomField::ROLE_VIEW);
|
Support configuration-driven custom fields
Summary:
Ref T1702. Ref T3718. There are a couple of things going on here:
**PhabricatorCustomFieldList**: I added `PhabricatorCustomFieldList`, which is just a convenience class for dealing with lists of fields. Often, current field code does something like this inline in a Controller:
foreach ($fields as $field) {
// do some junk
}
Often, that junk has some slightly subtle implications. Move all of it to `$list->doSomeJunk()` methods (like `appendFieldsToForm()`, `loadFieldsFromStorage()`) to reduce code duplication and prevent errors. This additionally moves an existing list-convenience method there, out of `PhabricatorPropertyListView`.
**PhabricatorUserConfiguredCustomFieldStorage**: Adds `PhabricatorUserConfiguredCustomFieldStorage` for storing custom field data (like "ICQ Handle", "Phone Number", "Desk", "Favorite Flower", etc).
**Configuration-Driven Custom Fields**: Previously, I was thinking about doing these with interfaces, but as I thought about it more I started to dislike that approach. Instead, I built proxies into `PhabricatorCustomField`. Basically, this means that fields (like a custom, configuration-driven "Favorite Flower" field) can just use some other Field to actually provide their implementation (like a "standard" field which knows how to render text areas). The previous approach would have involed subclasssing the "standard" field and implementing an interface, but that would mean that every application would have at least two "base" fields and generally just seemed bleh as I worked through it.
The cost of this approach is that we need a bunch of `proxy` junk in the base class, but that's a one-time cost and I think it simplifies all the implementations and makes them a lot less magical (e.g., all of the custom fields now extend the right base field classes).
**Fixed Some Bugs**: Some of this code hadn't really been run yet and had minor bugs.
Test Plan:
{F54240}
{F54241}
{F54242}
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1702, T1703, T3718
Differential Revision: https://secure.phabricator.com/D6749
2013-08-14 17:10:16 +02:00
|
|
|
$field_list->appendFieldsToPropertyList($user, $viewer, $view);
|
2013-07-10 14:09:59 +02:00
|
|
|
|
|
|
|
return $view;
|
2011-12-24 03:17:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderUserFeed(PhabricatorUser $user) {
|
2012-07-03 00:41:19 +02:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2011-12-24 03:17:40 +01:00
|
|
|
$query = new PhabricatorFeedQuery();
|
|
|
|
$query->setFilterPHIDs(
|
|
|
|
array(
|
|
|
|
$user->getPHID(),
|
|
|
|
));
|
2012-07-03 15:25:03 +02:00
|
|
|
$query->setLimit(100);
|
2012-07-03 00:41:19 +02:00
|
|
|
$query->setViewer($viewer);
|
2011-12-24 03:17:40 +01:00
|
|
|
$stories = $query->execute();
|
|
|
|
|
|
|
|
$builder = new PhabricatorFeedBuilder($stories);
|
2012-07-03 00:41:19 +02:00
|
|
|
$builder->setUser($viewer);
|
2013-08-14 22:20:25 +02:00
|
|
|
$builder->setShowHovercards(true);
|
2011-12-24 03:17:40 +01:00
|
|
|
$view = $builder->buildView();
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
return hsprintf(
|
2013-04-15 22:07:54 +02:00
|
|
|
'<div class="profile-feed profile-wrap-responsive">
|
2013-04-15 04:32:26 +02:00
|
|
|
%s
|
2013-02-13 23:50:15 +01:00
|
|
|
</div>',
|
|
|
|
$view->render());
|
2011-01-24 03:09:16 +01:00
|
|
|
}
|
|
|
|
}
|