Move roles and status into properties on profile view
Summary: See discussion in D6403.
Test Plan: {F49488}
Reviewers: chad, btrahan
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D6409
This commit is contained in:
@@ -1614,10 +1614,12 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorUserProfile' => 'applications/people/storage/PhabricatorUserProfile.php',
|
'PhabricatorUserProfile' => 'applications/people/storage/PhabricatorUserProfile.php',
|
||||||
'PhabricatorUserProfileEditor' => 'applications/people/editor/PhabricatorUserProfileEditor.php',
|
'PhabricatorUserProfileEditor' => 'applications/people/editor/PhabricatorUserProfileEditor.php',
|
||||||
'PhabricatorUserRealNameField' => 'applications/people/customfield/PhabricatorUserRealNameField.php',
|
'PhabricatorUserRealNameField' => 'applications/people/customfield/PhabricatorUserRealNameField.php',
|
||||||
|
'PhabricatorUserRolesField' => 'applications/people/customfield/PhabricatorUserRolesField.php',
|
||||||
'PhabricatorUserSSHKey' => 'applications/settings/storage/PhabricatorUserSSHKey.php',
|
'PhabricatorUserSSHKey' => 'applications/settings/storage/PhabricatorUserSSHKey.php',
|
||||||
'PhabricatorUserSearchIndexer' => 'applications/people/search/PhabricatorUserSearchIndexer.php',
|
'PhabricatorUserSearchIndexer' => 'applications/people/search/PhabricatorUserSearchIndexer.php',
|
||||||
'PhabricatorUserSinceField' => 'applications/people/customfield/PhabricatorUserSinceField.php',
|
'PhabricatorUserSinceField' => 'applications/people/customfield/PhabricatorUserSinceField.php',
|
||||||
'PhabricatorUserStatus' => 'applications/people/storage/PhabricatorUserStatus.php',
|
'PhabricatorUserStatus' => 'applications/people/storage/PhabricatorUserStatus.php',
|
||||||
|
'PhabricatorUserStatusField' => 'applications/people/customfield/PhabricatorUserStatusField.php',
|
||||||
'PhabricatorUserStatusInvalidEpochException' => 'applications/people/exception/PhabricatorUserStatusInvalidEpochException.php',
|
'PhabricatorUserStatusInvalidEpochException' => 'applications/people/exception/PhabricatorUserStatusInvalidEpochException.php',
|
||||||
'PhabricatorUserStatusOverlapException' => 'applications/people/exception/PhabricatorUserStatusOverlapException.php',
|
'PhabricatorUserStatusOverlapException' => 'applications/people/exception/PhabricatorUserStatusOverlapException.php',
|
||||||
'PhabricatorUserTestCase' => 'applications/people/storage/__tests__/PhabricatorUserTestCase.php',
|
'PhabricatorUserTestCase' => 'applications/people/storage/__tests__/PhabricatorUserTestCase.php',
|
||||||
@@ -3567,10 +3569,12 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorUserProfile' => 'PhabricatorUserDAO',
|
'PhabricatorUserProfile' => 'PhabricatorUserDAO',
|
||||||
'PhabricatorUserProfileEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PhabricatorUserProfileEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'PhabricatorUserRealNameField' => 'PhabricatorUserCustomField',
|
'PhabricatorUserRealNameField' => 'PhabricatorUserCustomField',
|
||||||
|
'PhabricatorUserRolesField' => 'PhabricatorUserCustomField',
|
||||||
'PhabricatorUserSSHKey' => 'PhabricatorUserDAO',
|
'PhabricatorUserSSHKey' => 'PhabricatorUserDAO',
|
||||||
'PhabricatorUserSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
|
'PhabricatorUserSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
|
||||||
'PhabricatorUserSinceField' => 'PhabricatorUserCustomField',
|
'PhabricatorUserSinceField' => 'PhabricatorUserCustomField',
|
||||||
'PhabricatorUserStatus' => 'PhabricatorUserDAO',
|
'PhabricatorUserStatus' => 'PhabricatorUserDAO',
|
||||||
|
'PhabricatorUserStatusField' => 'PhabricatorUserCustomField',
|
||||||
'PhabricatorUserStatusInvalidEpochException' => 'Exception',
|
'PhabricatorUserStatusInvalidEpochException' => 'Exception',
|
||||||
'PhabricatorUserStatusOverlapException' => 'Exception',
|
'PhabricatorUserStatusOverlapException' => 'Exception',
|
||||||
'PhabricatorUserTestCase' => 'PhabricatorTestCase',
|
'PhabricatorUserTestCase' => 'PhabricatorTestCase',
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ final class PhabricatorUserConfigOptions
|
|||||||
id(new PhabricatorUserRealNameField())->getFieldKey() => true,
|
id(new PhabricatorUserRealNameField())->getFieldKey() => true,
|
||||||
id(new PhabricatorUserTitleField())->getFieldKey() => true,
|
id(new PhabricatorUserTitleField())->getFieldKey() => true,
|
||||||
id(new PhabricatorUserSinceField())->getFieldKey() => true,
|
id(new PhabricatorUserSinceField())->getFieldKey() => true,
|
||||||
|
id(new PhabricatorUserRolesField())->getFieldKey() => true,
|
||||||
|
id(new PhabricatorUserStatusField())->getFieldKey() => true,
|
||||||
id(new PhabricatorUserBlurbField())->getFieldKey() => true,
|
id(new PhabricatorUserBlurbField())->getFieldKey() => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -36,41 +36,6 @@ final class PhabricatorPeopleProfileController
|
|||||||
->setSubheader($profile->getTitle())
|
->setSubheader($profile->getTitle())
|
||||||
->setImage($picture);
|
->setImage($picture);
|
||||||
|
|
||||||
if ($user->getIsDisabled()) {
|
|
||||||
$header->addTag(
|
|
||||||
id(new PhabricatorTagView())
|
|
||||||
->setType(PhabricatorTagView::TYPE_STATE)
|
|
||||||
->setBackgroundColor(PhabricatorTagView::COLOR_GREY)
|
|
||||||
->setName(pht('Disabled')));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($user->getIsAdmin()) {
|
|
||||||
$header->addTag(
|
|
||||||
id(new PhabricatorTagView())
|
|
||||||
->setType(PhabricatorTagView::TYPE_STATE)
|
|
||||||
->setBackgroundColor(PhabricatorTagView::COLOR_RED)
|
|
||||||
->setName(pht('Administrator')));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($user->getIsSystemAgent()) {
|
|
||||||
$header->addTag(
|
|
||||||
id(new PhabricatorTagView())
|
|
||||||
->setType(PhabricatorTagView::TYPE_STATE)
|
|
||||||
->setBackgroundColor(PhabricatorTagView::COLOR_BLUE)
|
|
||||||
->setName(pht('Bot')));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$statuses = id(new PhabricatorUserStatus())
|
|
||||||
->loadCurrentStatuses(array($user->getPHID()));
|
|
||||||
if ($statuses) {
|
|
||||||
$header->addTag(
|
|
||||||
id(new PhabricatorTagView())
|
|
||||||
->setType(PhabricatorTagView::TYPE_STATE)
|
|
||||||
->setBackgroundColor(PhabricatorTagView::COLOR_ORANGE)
|
|
||||||
->setName(head($statuses)->getTerseSummary($viewer)));
|
|
||||||
}
|
|
||||||
|
|
||||||
$actions = id(new PhabricatorActionListView())
|
$actions = id(new PhabricatorActionListView())
|
||||||
->setObject($user)
|
->setObject($user)
|
||||||
->setUser($viewer);
|
->setUser($viewer);
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorUserRolesField
|
||||||
|
extends PhabricatorUserCustomField {
|
||||||
|
|
||||||
|
private $value;
|
||||||
|
|
||||||
|
public function getFieldKey() {
|
||||||
|
return 'user:roles';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFieldName() {
|
||||||
|
return pht('Roles');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFieldDescription() {
|
||||||
|
return pht('Shows roles like "Administrator" and "Disabled".');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shouldAppearInPropertyView() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderPropertyViewValue() {
|
||||||
|
$user = $this->getObject();
|
||||||
|
|
||||||
|
$roles = array();
|
||||||
|
if ($user->getIsAdmin()) {
|
||||||
|
$roles[] = pht('Administrator');
|
||||||
|
}
|
||||||
|
if ($user->getIsDisabled()) {
|
||||||
|
$roles[] = pht('Disabled');
|
||||||
|
}
|
||||||
|
if ($user->getIsSystemAgent()) {
|
||||||
|
$roles[] = pht('Bot');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($roles) {
|
||||||
|
return implode(', ', $roles);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,9 +22,15 @@ final class PhabricatorUserSinceField
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue() {
|
public function renderPropertyViewValue() {
|
||||||
return phabricator_datetime(
|
$absolute = phabricator_datetime(
|
||||||
$this->getObject()->getDateCreated(),
|
$this->getObject()->getDateCreated(),
|
||||||
$this->getViewer());
|
$this->getViewer());
|
||||||
|
|
||||||
|
$relative = phabricator_format_relative_time_detailed(
|
||||||
|
time() - $this->getObject()->getDateCreated(),
|
||||||
|
$levels = 2);
|
||||||
|
|
||||||
|
return hsprintf('%s (%s)', $absolute, $relative);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorUserStatusField
|
||||||
|
extends PhabricatorUserCustomField {
|
||||||
|
|
||||||
|
private $value;
|
||||||
|
|
||||||
|
public function getFieldKey() {
|
||||||
|
return 'user:status';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFieldName() {
|
||||||
|
return pht('Status');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFieldDescription() {
|
||||||
|
return pht('Shows when a user is away or busy.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shouldAppearInPropertyView() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderPropertyViewValue() {
|
||||||
|
$user = $this->getObject();
|
||||||
|
$viewer = $this->requireViewer();
|
||||||
|
|
||||||
|
$statuses = id(new PhabricatorUserStatus())
|
||||||
|
->loadCurrentStatuses(array($user->getPHID()));
|
||||||
|
if (!$statuses) {
|
||||||
|
return pht('Available');
|
||||||
|
}
|
||||||
|
|
||||||
|
$status = head($statuses);
|
||||||
|
|
||||||
|
return $status->getTerseSummary($viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -84,6 +84,28 @@ final class PhabricatorPropertyListView extends AphrontView {
|
|||||||
public function applyCustomFields(array $fields) {
|
public function applyCustomFields(array $fields) {
|
||||||
assert_instances_of($fields, 'PhabricatorCustomField');
|
assert_instances_of($fields, 'PhabricatorCustomField');
|
||||||
|
|
||||||
|
// Move all the blocks to the end, regardless of their configuration order,
|
||||||
|
// because it always looks silly to render a block in the middle of a list
|
||||||
|
// of properties.
|
||||||
|
$head = array();
|
||||||
|
$tail = array();
|
||||||
|
foreach ($fields as $key => $field) {
|
||||||
|
$style = $field->getStyleForPropertyView();
|
||||||
|
switch ($style) {
|
||||||
|
case 'property':
|
||||||
|
$head[$key] = $field;
|
||||||
|
break;
|
||||||
|
case 'block':
|
||||||
|
$tail[$key] = $field;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception(
|
||||||
|
"Unknown field property view style '{$style}'; valid styles are ".
|
||||||
|
"'block' and 'property'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$fields = $head + $tail;
|
||||||
|
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$label = $field->renderPropertyViewLabel();
|
$label = $field->renderPropertyViewLabel();
|
||||||
$value = $field->renderPropertyViewValue();
|
$value = $field->renderPropertyViewValue();
|
||||||
@@ -99,10 +121,6 @@ final class PhabricatorPropertyListView extends AphrontView {
|
|||||||
}
|
}
|
||||||
$this->addTextContent($value);
|
$this->addTextContent($value);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
throw new Exception(
|
|
||||||
"Unknown field property view style; valid styles are ".
|
|
||||||
"'block' and 'property'.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user