Page MenuHomestyx hydra

No OneTemporary

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
@@ -1,159 +1,174 @@
<?php
final class PhabricatorDashboardQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $statuses;
private $authorPHIDs;
+ private $canEdit;
private $needPanels;
private $needProjects;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withStatuses(array $statuses) {
$this->statuses = $statuses;
return $this;
}
public function withAuthorPHIDs(array $authors) {
$this->authorPHIDs = $authors;
return $this;
}
public function needPanels($need_panels) {
$this->needPanels = $need_panels;
return $this;
}
public function needProjects($need_projects) {
$this->needProjects = $need_projects;
return $this;
}
+ public function withCanEdit($can_edit) {
+ $this->canEdit = $can_edit;
+ return $this;
+ }
+
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
id(new PhabricatorDashboardNgrams()),
$ngrams);
}
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
public function newResultObject() {
return new PhabricatorDashboard();
}
protected function didFilterPage(array $dashboards) {
$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)
->withEdgeTypes(
array(
PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST,
));
$edge_query->execute();
$panel_phids = $edge_query->getDestinationPHIDs();
if ($panel_phids) {
// NOTE: We explicitly disable policy exceptions when loading panels.
// If a particular panel is invalid or not visible to the viewer,
// we'll still render the dashboard, just not that panel.
$panels = id(new PhabricatorDashboardPanelQuery())
->setParentQuery($this)
->setRaisePolicyExceptions(false)
->setViewer($this->getViewer())
->withPHIDs($panel_phids)
->execute();
$panels = mpull($panels, null, 'getPHID');
} else {
$panels = array();
}
foreach ($dashboards as $dashboard) {
$dashboard_phids = $edge_query->getDestinationPHIDs(
array($dashboard->getPHID()));
$dashboard_panels = array_select_keys($panels, $dashboard_phids);
$dashboard->attachPanelPHIDs($dashboard_phids);
$dashboard->attachPanels($dashboard_panels);
}
}
if ($this->needProjects) {
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($phids)
->withEdgeTypes(
array(
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
));
$edge_query->execute();
foreach ($dashboards as $dashboard) {
$project_phids = $edge_query->getDestinationPHIDs(
array($dashboard->getPHID()));
$dashboard->attachProjectPHIDs($project_phids);
}
}
return $dashboards;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'phid IN (%Ls)',
$this->phids);
}
if ($this->statuses !== null) {
$where[] = qsprintf(
$conn,
'status IN (%Ls)',
$this->statuses);
}
if ($this->authorPHIDs !== null) {
$where[] = qsprintf(
$conn,
'authorPHID IN (%Ls)',
$this->authorPHIDs);
}
return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorDashboardApplication';
}
protected function getPrimaryTableAlias() {
return 'dashboard';
}
}
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
@@ -1,183 +1,193 @@
<?php
final class PhabricatorDashboardSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Dashboards');
}
public function getApplicationClassName() {
return 'PhabricatorDashboardApplication';
}
public function newQuery() {
return id(new PhabricatorDashboardQuery())
->needPanels(true);
}
public function canUseInPanelContext() {
return false;
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('name')
->setDescription(pht('Search for dashboards by name substring.')),
id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Authored By'))
->setKey('authorPHIDs')
->setDatasource(new PhabricatorPeopleUserFunctionDatasource()),
id(new PhabricatorSearchCheckboxesField())
->setKey('statuses')
->setLabel(pht('Status'))
->setOptions(PhabricatorDashboard::getStatusNameMap()),
+ id(new PhabricatorSearchCheckboxesField())
+ ->setKey('editable')
+ ->setLabel(pht('Editable'))
+ ->setOptions(array('editable' => null)),
);
}
protected function getURI($path) {
return '/dashboard/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array();
if ($this->requireViewer()->isLoggedIn()) {
$names['authored'] = pht('Authored');
}
$names['open'] = pht('Active Dashboards');
$names['all'] = pht('All Dashboards');
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
$viewer = $this->requireViewer();
switch ($query_key) {
case 'all':
return $query;
case 'authored':
return $query->setParameter(
'authorPHIDs',
array(
$viewer->getPHID(),
));
case 'open':
return $query->setParameter(
'statuses',
array(
PhabricatorDashboard::STATUS_ACTIVE,
));
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['statuses']) {
$query->withStatuses($map['statuses']);
}
if ($map['authorPHIDs']) {
$query->withAuthorPHIDs($map['authorPHIDs']);
}
if ($map['name'] !== null) {
$query->withNameNgrams($map['name']);
}
+ if ($map['editable'] !== null) {
+ $query->withCanEdit($map['editable']);
+ }
+
return $query;
}
protected function renderResultList(
array $dashboards,
PhabricatorSavedQuery $query,
array $handles) {
$viewer = $this->requireViewer();
$phids = array();
foreach ($dashboards as $dashboard) {
$author_phid = $dashboard->getAuthorPHID();
if ($author_phid) {
$phids[] = $author_phid;
}
}
$handles = $viewer->loadHandles($phids);
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
foreach ($dashboards as $dashboard) {
$id = $dashboard->getID();
$item = id(new PHUIObjectItemView())
->setUser($viewer)
->setHeader($dashboard->getName())
->setHref($this->getApplicationURI("view/{$id}/"))
->setObject($dashboard);
+ $bg_color = 'bg-dark';
if ($dashboard->isArchived()) {
$item->setDisabled(true);
+ $bg_color = 'bg-grey';
}
$panels = $dashboard->getPanels();
foreach ($panels as $panel) {
$item->addAttribute($panel->getName());
}
if (empty($panels)) {
$empty = phutil_tag('em', array(), pht('No panels.'));
$item->addAttribute($empty);
}
$icon = id(new PHUIIconView())
->setIcon($dashboard->getIcon())
- ->setBackground('bg-dark');
+ ->setBackground($bg_color);
$item->setImageIcon($icon);
$item->setEpoch($dashboard->getDateModified());
$author_phid = $dashboard->getAuthorPHID();
$author_name = $handles[$author_phid]->renderLink();
$item->addByline(pht('Author: %s', $author_name));
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No dashboards found.'));
return $result;
}
protected function getNewUserBody() {
$create_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Create a Dashboard'))
->setHref('/dashboard/create/')
->setColor(PHUIButtonView::GREEN);
$icon = $this->getApplication()->getIcon();
$app_name = $this->getApplication()->getName();
$view = id(new PHUIBigInfoView())
->setIcon($icon)
->setTitle(pht('Welcome to %s', $app_name))
->setDescription(
pht('Customize your homepage with different panels and '.
'search queries.'))
->addAction($create_button);
return $view;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Mar 14, 8:09 AM (19 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
71703
Default Alt Text
(10 KB)

Event Timeline