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())
|
2014-05-12 18:51:40 +02:00
|
|
|
->setHeader($user->getFullName())
|
2013-07-10 01:23:22 +02:00
|
|
|
->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
|
|
|
|
2014-04-02 21:05:34 +02:00
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$user,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
2013-07-10 01:23:45 +02:00
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-pencil')
|
2013-07-10 01:23:45 +02:00
|
|
|
->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())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-picture-o')
|
2013-07-10 01:23:54 +02:00
|
|
|
->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()) {
|
2014-04-02 21:06:05 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-wrench')
|
2014-04-02 21:06:05 +02:00
|
|
|
->setName(pht('Edit Settings'))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit)
|
|
|
|
->setHref('/settings/'.$user->getID().'/'));
|
|
|
|
|
2014-04-02 21:05:49 +02:00
|
|
|
if ($user->getIsAdmin()) {
|
2014-05-12 19:08:32 +02:00
|
|
|
$empower_icon = 'fa-arrow-circle-o-down';
|
2014-04-02 21:05:49 +02:00
|
|
|
$empower_name = pht('Remove Administrator');
|
|
|
|
} else {
|
2014-05-12 19:08:32 +02:00
|
|
|
$empower_icon = 'fa-arrow-circle-o-up';
|
2014-04-02 21:05:49 +02:00
|
|
|
$empower_name = pht('Make Administrator');
|
|
|
|
}
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon($empower_icon)
|
|
|
|
->setName($empower_name)
|
|
|
|
->setDisabled(($user->getPHID() == $viewer->getPHID()))
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setHref($this->getApplicationURI('empower/'.$user->getID().'/')));
|
|
|
|
|
2014-04-02 21:05:19 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-tag')
|
2014-04-02 21:05:19 +02:00
|
|
|
->setName(pht('Change Username'))
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setHref($this->getApplicationURI('rename/'.$user->getID().'/')));
|
|
|
|
|
2014-04-02 21:05:49 +02:00
|
|
|
if ($user->getIsDisabled()) {
|
2014-05-12 19:08:32 +02:00
|
|
|
$disable_icon = 'fa-check-circle-o';
|
2014-04-02 21:05:49 +02:00
|
|
|
$disable_name = pht('Enable User');
|
|
|
|
} else {
|
2014-05-12 19:08:32 +02:00
|
|
|
$disable_icon = 'fa-ban';
|
2014-04-02 21:05:49 +02:00
|
|
|
$disable_name = pht('Disable User');
|
|
|
|
}
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon($disable_icon)
|
|
|
|
->setName($disable_name)
|
|
|
|
->setDisabled(($user->getPHID() == $viewer->getPHID()))
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setHref($this->getApplicationURI('disable/'.$user->getID().'/')));
|
|
|
|
|
2014-04-02 21:05:07 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-times')
|
2014-04-02 21:05:07 +02:00
|
|
|
->setName(pht('Delete User'))
|
|
|
|
->setDisabled(($user->getPHID() == $viewer->getPHID()))
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setHref($this->getApplicationURI('delete/'.$user->getID().'/')));
|
|
|
|
|
2013-07-10 01:23:45 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-envelope')
|
2014-04-02 21:06:17 +02:00
|
|
|
->setName(pht('Send Welcome Email'))
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setHref($this->getApplicationURI('welcome/'.$user->getID().'/')));
|
2012-01-17 01:54:05 +01:00
|
|
|
}
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$properties = $this->buildPropertyView($user, $actions);
|
2013-07-10 14:09:59 +02:00
|
|
|
|
2013-07-10 14:11:08 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb($user->getUsername());
|
2014-05-22 21:04:11 +02:00
|
|
|
$crumbs->setActionList($actions);
|
2013-07-10 14:11:08 +02:00
|
|
|
$feed = $this->renderUserFeed($user);
|
2014-02-24 19:04:23 +01:00
|
|
|
$calendar = $this->renderUserCalendar($user);
|
|
|
|
$activity = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'profile-activity-view grouped'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$calendar,
|
|
|
|
$feed
|
|
|
|
));
|
2013-07-10 01:23:45 +02:00
|
|
|
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
2013-10-11 16:53:56 +02:00
|
|
|
->addPropertyList($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,
|
2014-02-24 19:04:23 +01:00
|
|
|
$activity,
|
2013-07-10 14:11:08 +02:00
|
|
|
),
|
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-10-11 16:53:56 +02:00
|
|
|
private function buildPropertyView(
|
|
|
|
PhabricatorUser $user,
|
|
|
|
PhabricatorActionListView $actions) {
|
2011-12-24 03:17:40 +01:00
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
$view = id(new PHUIPropertyListView())
|
2013-07-10 14:09:59 +02:00
|
|
|
->setUser($viewer)
|
2013-10-11 16:53:56 +02:00
|
|
|
->setObject($user)
|
|
|
|
->setActionList($actions);
|
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-11-11 18:23:23 +01:00
|
|
|
return phutil_tag_div(
|
2014-01-01 01:28:35 +01:00
|
|
|
'profile-feed',
|
2013-02-13 23:50:15 +01:00
|
|
|
$view->render());
|
2011-01-24 03:09:16 +01:00
|
|
|
}
|
2014-02-24 19:04:23 +01:00
|
|
|
|
|
|
|
private function renderUserCalendar(PhabricatorUser $user) {
|
2014-02-25 22:43:31 +01:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
$epochs = CalendarTimeUtil::getCalendarEventEpochs(
|
|
|
|
$viewer,
|
|
|
|
'today',
|
|
|
|
7);
|
|
|
|
$start_epoch = $epochs['start_epoch'];
|
|
|
|
$end_epoch = $epochs['end_epoch'];
|
2014-02-24 19:04:23 +01:00
|
|
|
$statuses = id(new PhabricatorCalendarEventQuery())
|
2014-02-25 22:43:31 +01:00
|
|
|
->setViewer($viewer)
|
2014-02-24 19:04:23 +01:00
|
|
|
->withInvitedPHIDs(array($user->getPHID()))
|
2014-02-25 22:43:31 +01:00
|
|
|
->withDateRange($start_epoch, $end_epoch)
|
2014-02-24 19:04:23 +01:00
|
|
|
->execute();
|
|
|
|
|
2014-02-25 22:43:31 +01:00
|
|
|
$timestamps = CalendarTimeUtil::getCalendarWeekTimestamps(
|
|
|
|
$viewer);
|
|
|
|
$today = $timestamps['today'];
|
|
|
|
$epoch_stamps = $timestamps['epoch_stamps'];
|
2014-02-24 19:04:23 +01:00
|
|
|
$events = array();
|
2014-02-25 22:43:31 +01:00
|
|
|
|
|
|
|
foreach ($epoch_stamps as $day) {
|
|
|
|
$epoch_start = $day->format('U');
|
|
|
|
$next_day = clone $day;
|
|
|
|
$next_day->modify('+1 day');
|
|
|
|
$epoch_end = $next_day->format('U');
|
|
|
|
|
|
|
|
foreach ($statuses as $status) {
|
2014-02-25 23:20:59 +01:00
|
|
|
if ($status->getDateTo() < $epoch_start) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-25 22:43:31 +01:00
|
|
|
if ($status->getDateFrom() >= $epoch_end) {
|
2014-02-25 23:20:59 +01:00
|
|
|
continue;
|
2014-02-25 22:43:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$event = new AphrontCalendarEventView();
|
|
|
|
$event->setEpochRange($status->getDateFrom(), $status->getDateTo());
|
|
|
|
|
|
|
|
$status_text = $status->getHumanStatus();
|
|
|
|
$event->setUserPHID($status->getUserPHID());
|
|
|
|
$event->setName($status_text);
|
|
|
|
$event->setDescription($status->getDescription());
|
|
|
|
$event->setEventID($status->getID());
|
|
|
|
$events[$epoch_start][] = $event;
|
2014-02-24 19:04:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$week = array();
|
2014-02-25 22:43:31 +01:00
|
|
|
foreach ($epoch_stamps as $day) {
|
|
|
|
$epoch = $day->format('U');
|
|
|
|
$headertext = phabricator_format_local_time($epoch, $user, 'l, M d');
|
2014-02-24 19:04:23 +01:00
|
|
|
|
|
|
|
$list = new PHUICalendarListView();
|
2014-02-25 22:43:31 +01:00
|
|
|
$list->setUser($viewer);
|
2014-02-24 19:04:23 +01:00
|
|
|
$list->showBlankState(true);
|
2014-02-25 22:43:31 +01:00
|
|
|
if (isset($events[$epoch])) {
|
|
|
|
foreach ($events[$epoch] as $event) {
|
2014-02-24 19:04:23 +01:00
|
|
|
$list->addEvent($event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$header = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $this->getRequest()->getRequestURI().'calendar/'
|
|
|
|
),
|
|
|
|
$headertext);
|
|
|
|
|
|
|
|
$calendar = new PHUICalendarWidgetView();
|
|
|
|
$calendar->setHeader($header);
|
|
|
|
$calendar->setCalendarList($list);
|
|
|
|
$week[] = $calendar;
|
|
|
|
}
|
|
|
|
|
|
|
|
return phutil_tag_div(
|
|
|
|
'profile-calendar',
|
|
|
|
$week);
|
|
|
|
}
|
2011-01-24 03:09:16 +01:00
|
|
|
}
|