From 11578bfc90090ec5ed96c3ed878695fe12a531a0 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Sun, 21 May 2017 09:24:26 -0700 Subject: [PATCH] Add Revisions to User Profiles Summary: Ref T12423. Adds back revisions as a user profile page. I don't want to think about custom profiles for a while. Test Plan: Make some diffs, visit my profile, see diffs. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T12423 Differential Revision: https://secure.phabricator.com/D17987 --- src/__phutil_library_map__.php | 4 + .../PhabricatorPeopleApplication.php | 2 + ...bricatorPeopleProfileCommitsController.php | 8 -- ...icatorPeopleProfileRevisionsController.php | 82 +++++++++++++++++++ ...habricatorPeopleProfileTasksController.php | 4 - .../PhabricatorPeopleProfileMenuEngine.php | 11 +++ ...bricatorPeopleRevisionsProfileMenuItem.php | 59 +++++++++++++ 7 files changed, 158 insertions(+), 12 deletions(-) create mode 100644 src/applications/people/controller/PhabricatorPeopleProfileRevisionsController.php create mode 100644 src/applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index cbf324c847..f6b66d9ab8 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3457,10 +3457,12 @@ phutil_register_library_map(array( 'PhabricatorPeopleProfileManageController' => 'applications/people/controller/PhabricatorPeopleProfileManageController.php', 'PhabricatorPeopleProfileMenuEngine' => 'applications/people/engine/PhabricatorPeopleProfileMenuEngine.php', 'PhabricatorPeopleProfilePictureController' => 'applications/people/controller/PhabricatorPeopleProfilePictureController.php', + 'PhabricatorPeopleProfileRevisionsController' => 'applications/people/controller/PhabricatorPeopleProfileRevisionsController.php', 'PhabricatorPeopleProfileTasksController' => 'applications/people/controller/PhabricatorPeopleProfileTasksController.php', 'PhabricatorPeopleProfileViewController' => 'applications/people/controller/PhabricatorPeopleProfileViewController.php', 'PhabricatorPeopleQuery' => 'applications/people/query/PhabricatorPeopleQuery.php', 'PhabricatorPeopleRenameController' => 'applications/people/controller/PhabricatorPeopleRenameController.php', + 'PhabricatorPeopleRevisionsProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php', 'PhabricatorPeopleSearchEngine' => 'applications/people/query/PhabricatorPeopleSearchEngine.php', 'PhabricatorPeopleTasksProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleTasksProfileMenuItem.php', 'PhabricatorPeopleTestDataGenerator' => 'applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php', @@ -8825,10 +8827,12 @@ phutil_register_library_map(array( 'PhabricatorPeopleProfileManageController' => 'PhabricatorPeopleProfileController', 'PhabricatorPeopleProfileMenuEngine' => 'PhabricatorProfileMenuEngine', 'PhabricatorPeopleProfilePictureController' => 'PhabricatorPeopleProfileController', + 'PhabricatorPeopleProfileRevisionsController' => 'PhabricatorPeopleProfileController', 'PhabricatorPeopleProfileTasksController' => 'PhabricatorPeopleProfileController', 'PhabricatorPeopleProfileViewController' => 'PhabricatorPeopleProfileController', 'PhabricatorPeopleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorPeopleRenameController' => 'PhabricatorPeopleController', + 'PhabricatorPeopleRevisionsProfileMenuItem' => 'PhabricatorProfileMenuItem', 'PhabricatorPeopleSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorPeopleTasksProfileMenuItem' => 'PhabricatorProfileMenuItem', 'PhabricatorPeopleTestDataGenerator' => 'PhabricatorTestDataGenerator', diff --git a/src/applications/people/application/PhabricatorPeopleApplication.php b/src/applications/people/application/PhabricatorPeopleApplication.php index f2bb70e423..dde82f1d3a 100644 --- a/src/applications/people/application/PhabricatorPeopleApplication.php +++ b/src/applications/people/application/PhabricatorPeopleApplication.php @@ -70,6 +70,8 @@ final class PhabricatorPeopleApplication extends PhabricatorApplication { 'PhabricatorPeopleProfileTasksController', 'commits/(?P[1-9]\d*)/' => 'PhabricatorPeopleProfileCommitsController', + 'revisions/(?P[1-9]\d*)/' => + 'PhabricatorPeopleProfileRevisionsController', 'picture/(?P[1-9]\d*)/' => 'PhabricatorPeopleProfilePictureController', 'manage/(?P[1-9]\d*)/' => diff --git a/src/applications/people/controller/PhabricatorPeopleProfileCommitsController.php b/src/applications/people/controller/PhabricatorPeopleProfileCommitsController.php index f2adf4b23d..3e1e6de1ee 100644 --- a/src/applications/people/controller/PhabricatorPeopleProfileCommitsController.php +++ b/src/applications/people/controller/PhabricatorPeopleProfileCommitsController.php @@ -13,10 +13,6 @@ final class PhabricatorPeopleProfileCommitsController ->needProfile(true) ->needProfileImage(true) ->needAvailability(true) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - )) ->executeOne(); if (!$user) { return new Aphront404Response(); @@ -63,10 +59,6 @@ final class PhabricatorPeopleProfileCommitsController ->needAuditRequests(true) ->needCommitData(true) ->needDrafts(true) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - )) ->setLimit(100) ->execute(); diff --git a/src/applications/people/controller/PhabricatorPeopleProfileRevisionsController.php b/src/applications/people/controller/PhabricatorPeopleProfileRevisionsController.php new file mode 100644 index 0000000000..adb2a60e5d --- /dev/null +++ b/src/applications/people/controller/PhabricatorPeopleProfileRevisionsController.php @@ -0,0 +1,82 @@ +getViewer(); + $id = $request->getURIData('id'); + + $user = id(new PhabricatorPeopleQuery()) + ->setViewer($viewer) + ->withIDs(array($id)) + ->needProfile(true) + ->needProfileImage(true) + ->needAvailability(true) + ->executeOne(); + if (!$user) { + return new Aphront404Response(); + } + + $class = 'PhabricatorDifferentialApplication'; + if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { + return new Aphront404Response(); + } + + $this->setUser($user); + $title = array(pht('Recent Revisions'), $user->getUsername()); + $header = $this->buildProfileHeader(); + $commits = $this->buildRevisionsView($user); + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('Recent Revisions')); + $crumbs->setBorder(true); + + $nav = $this->getProfileMenu(); + $nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_REVISIONS); + + $view = id(new PHUITwoColumnView()) + ->setHeader($header) + ->addClass('project-view-home') + ->addClass('project-view-people-home') + ->setFooter(array( + $commits, + )); + + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->setNavigation($nav) + ->appendChild($view); + } + + private function buildRevisionsView(PhabricatorUser $user) { + $viewer = $this->getViewer(); + + $revisions = id(new DifferentialRevisionQuery()) + ->setViewer($viewer) + ->withAuthors(array($user->getPHID())) + ->needFlags(true) + ->needDrafts(true) + ->needReviewers(true) + ->setLimit(100) + ->execute(); + + $list = id(new DifferentialRevisionListView()) + ->setUser($viewer) + ->setNoBox(true) + ->setRevisions($revisions) + ->setNoDataString(pht('No recent revisions.')); + + $object_phids = $list->getRequiredHandlePHIDs(); + $handles = $this->loadViewerHandles($object_phids); + $list->setHandles($handles); + + $view = id(new PHUIObjectBoxView()) + ->setHeaderText(pht('Recent Revisions')) + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) + ->appendChild($list); + + return $view; + } +} diff --git a/src/applications/people/controller/PhabricatorPeopleProfileTasksController.php b/src/applications/people/controller/PhabricatorPeopleProfileTasksController.php index 52c88d89fa..47cc605bb8 100644 --- a/src/applications/people/controller/PhabricatorPeopleProfileTasksController.php +++ b/src/applications/people/controller/PhabricatorPeopleProfileTasksController.php @@ -13,10 +13,6 @@ final class PhabricatorPeopleProfileTasksController ->needProfile(true) ->needProfileImage(true) ->needAvailability(true) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - )) ->executeOne(); if (!$user) { return new Aphront404Response(); diff --git a/src/applications/people/engine/PhabricatorPeopleProfileMenuEngine.php b/src/applications/people/engine/PhabricatorPeopleProfileMenuEngine.php index e5f25eb4a0..6d6d239f5b 100644 --- a/src/applications/people/engine/PhabricatorPeopleProfileMenuEngine.php +++ b/src/applications/people/engine/PhabricatorPeopleProfileMenuEngine.php @@ -9,6 +9,7 @@ final class PhabricatorPeopleProfileMenuEngine const ITEM_BADGES = 'people.badges'; const ITEM_TASKS = 'people.tasks'; const ITEM_COMMITS = 'people.commits'; + const ITEM_REVISIONS = 'people.revisions'; protected function isMenuEngineConfigurable() { return false; @@ -52,6 +53,16 @@ final class PhabricatorPeopleProfileMenuEngine ->setMenuItemKey(PhabricatorPeopleTasksProfileMenuItem::MENUITEMKEY); } + $have_differential = PhabricatorApplication::isClassInstalledForViewer( + 'PhabricatorDifferentialApplication', + $viewer); + if ($have_differential) { + $items[] = $this->newItem() + ->setBuiltinKey(self::ITEM_REVISIONS) + ->setMenuItemKey( + PhabricatorPeopleRevisionsProfileMenuItem::MENUITEMKEY); + } + $have_diffusion = PhabricatorApplication::isClassInstalledForViewer( 'PhabricatorDiffusionApplication', $viewer); diff --git a/src/applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php b/src/applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php new file mode 100644 index 0000000000..499fc1d7f4 --- /dev/null +++ b/src/applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php @@ -0,0 +1,59 @@ +getMenuItemProperty('name'); + + if (strlen($name)) { + return $name; + } + + return $this->getDefaultName(); + } + + public function buildEditEngineFields( + PhabricatorProfileMenuItemConfiguration $config) { + return array( + id(new PhabricatorTextEditField()) + ->setKey('name') + ->setLabel(pht('Name')) + ->setPlaceholder($this->getDefaultName()) + ->setValue($config->getMenuItemProperty('name')), + ); + } + + protected function newNavigationMenuItems( + PhabricatorProfileMenuItemConfiguration $config) { + + $user = $config->getProfileObject(); + $id = $user->getID(); + + $item = $this->newItem() + ->setHref("/people/revisions/{$id}/") + ->setName($this->getDisplayName($config)) + ->setIcon('fa-gear'); + + return array( + $item, + ); + } + +}