From 7d4c0f002f115d01d8b77e0098b44479e87bb818 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Tue, 21 Mar 2017 09:25:05 -0700 Subject: [PATCH] Allow searching Dashboards by Editable Summary: Ref T10390. I find myself wanting to find dashboards I can edit, even if I am not the author. I think this is useful for larger installs with multiple admins. Also make disabled Dashboards more grey in UI results. Test Plan: Log in a test user, create a dashboard with I cannot edit. Log into my account, search for editable dashboards and only see mine. Set dashboard to all users, search under test account and see editable dashboards. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T10390 Differential Revision: https://secure.phabricator.com/D17524 --- .../dashboard/query/PhabricatorDashboardQuery.php | 15 +++++++++++++++ .../query/PhabricatorDashboardSearchEngine.php | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/applications/dashboard/query/PhabricatorDashboardQuery.php b/src/applications/dashboard/query/PhabricatorDashboardQuery.php index c005197df2..9f5e256391 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardQuery.php +++ b/src/applications/dashboard/query/PhabricatorDashboardQuery.php @@ -7,6 +7,7 @@ final class PhabricatorDashboardQuery private $phids; private $statuses; private $authorPHIDs; + private $canEdit; private $needPanels; private $needProjects; @@ -41,6 +42,11 @@ final class PhabricatorDashboardQuery return $this; } + public function withCanEdit($can_edit) { + $this->canEdit = $can_edit; + return $this; + } + public function withNameNgrams($ngrams) { return $this->withNgramsConstraint( id(new PhabricatorDashboardNgrams()), @@ -59,6 +65,15 @@ final class PhabricatorDashboardQuery $phids = mpull($dashboards, 'getPHID'); + if ($this->canEdit) { + $dashboards = id(new PhabricatorPolicyFilter()) + ->setViewer($this->getViewer()) + ->requireCapabilities(array( + PhabricatorPolicyCapability::CAN_EDIT, + )) + ->apply($dashboards); + } + if ($this->needPanels) { $edge_query = id(new PhabricatorEdgeQuery()) ->withSourcePHIDs($phids) diff --git a/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php b/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php index a854b066f8..a05d1c4121 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php +++ b/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php @@ -34,6 +34,10 @@ final class PhabricatorDashboardSearchEngine ->setKey('statuses') ->setLabel(pht('Status')) ->setOptions(PhabricatorDashboard::getStatusNameMap()), + id(new PhabricatorSearchCheckboxesField()) + ->setKey('editable') + ->setLabel(pht('Editable')) + ->setOptions(array('editable' => null)), ); } @@ -94,6 +98,10 @@ final class PhabricatorDashboardSearchEngine $query->withNameNgrams($map['name']); } + if ($map['editable'] !== null) { + $query->withCanEdit($map['editable']); + } + return $query; } @@ -126,8 +134,10 @@ final class PhabricatorDashboardSearchEngine ->setHref($this->getApplicationURI("view/{$id}/")) ->setObject($dashboard); + $bg_color = 'bg-dark'; if ($dashboard->isArchived()) { $item->setDisabled(true); + $bg_color = 'bg-grey'; } $panels = $dashboard->getPanels(); @@ -142,7 +152,7 @@ final class PhabricatorDashboardSearchEngine $icon = id(new PHUIIconView()) ->setIcon($dashboard->getIcon()) - ->setBackground('bg-dark'); + ->setBackground($bg_color); $item->setImageIcon($icon); $item->setEpoch($dashboard->getDateModified());