1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 13:30:55 +01:00

Add authorPHID to Dashboard Panels

Summary: Adds authorPHID to panels so we can default to the panels you made.

Test Plan: Run upgrade, visit manage panels, see my panels. Create a new panel. Edit a panel.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D17036
This commit is contained in:
Chad Little 2016-12-13 09:51:25 -08:00
parent 8a2afa14d2
commit c03a412d5c
7 changed files with 87 additions and 7 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_dashboard.dashboard_panel
ADD authorPHID VARBINARY(64) NOT NULL;

View file

@ -0,0 +1,39 @@
<?php
// Set authorPHID on Dashboard Panels
//
$table = new PhabricatorDashboardPanel();
$conn_w = $table->establishConnection('w');
$txn_table = new PhabricatorDashboardPanelTransaction();
$txn_conn = $table->establishConnection('r');
echo pht("Building Dashboard Panel authorPHIDs...\n");
foreach (new LiskMigrationIterator($table) as $panel) {
if ($panel->getAuthorPHID()) {
continue;
}
$panel_row = queryfx_one(
$txn_conn,
'SELECT authorPHID FROM %T WHERE objectPHID = %s ORDER BY id ASC LIMIT 1',
$txn_table->getTableName(),
$panel->getPHID());
if (!$panel_row) {
$author_phid = id(new PhabricatorDashboardApplication())->getPHID();
} else {
$author_phid = $panel_row['authorPHID'];
}
queryfx(
$conn_w,
'UPDATE %T SET authorPHID = %s WHERE id = %d',
$table->getTableName(),
$author_phid,
$panel->getID());
}
echo pht("Done\n");

View file

@ -400,7 +400,7 @@ final class PhabricatorDashboardPanelEditController
$viewer = $request->getUser();
$copy = PhabricatorDashboardPanel::initializeNewPanel($viewer);
$copy = PhabricatorDashboardPanel::copyPanel($copy, $panel);
$copy = PhabricatorDashboardPanel::copyPanel($copy, $panel, $viewer);
$copy->openTransaction();
$copy->save();

View file

@ -7,6 +7,7 @@ final class PhabricatorDashboardPanelQuery
private $phids;
private $archived;
private $panelTypes;
private $authorPHIDs;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -28,6 +29,11 @@ final class PhabricatorDashboardPanelQuery
return $this;
}
public function withAuthorPHIDs(array $authors) {
$this->authorPHIDs = $authors;
return $this;
}
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
@ -75,6 +81,13 @@ final class PhabricatorDashboardPanelQuery
$this->panelTypes);
}
if ($this->authorPHIDs !== null) {
$where[] = qsprintf(
$conn,
'authorPHID IN (%Ls)',
$this->authorPHIDs);
}
return $where;
}

View file

@ -34,12 +34,20 @@ final class PhabricatorDashboardPanelSearchEngine
$query->withPanelTypes(array($map['paneltype']));
}
if ($map['authorPHIDs']) {
$query->withAuthorPHIDs($map['authorPHIDs']);
}
return $query;
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Authored By'))
->setKey('authorPHIDs')
->setDatasource(new PhabricatorPeopleUserFunctionDatasource()),
id(new PhabricatorSearchSelectField())
->setKey('status')
->setLabel(pht('Status'))
@ -60,19 +68,32 @@ final class PhabricatorDashboardPanelSearchEngine
}
protected function getBuiltinQueryNames() {
return array(
'active' => pht('Active Panels'),
'all' => pht('All Panels'),
);
$names = array();
if ($this->requireViewer()->isLoggedIn()) {
$names['authored'] = pht('Authored');
}
$names['active'] = pht('Active Panels');
$names['all'] = pht('All Panels');
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
$viewer = $this->requireViewer();
switch ($query_key) {
case 'active':
return $query->setParameter('status', 'active');
case 'authored':
return $query->setParameter(
'authorPHIDs',
array(
$viewer->getPHID(),
));
case 'all':
return $query;
}

View file

@ -56,7 +56,7 @@ final class PhabricatorDashboardSearchEngine
return $query;
case 'authored':
return $query->setParameter(
'authored',
'authorPHIDs',
array(
$viewer->getPHID(),
));

View file

@ -16,6 +16,7 @@ final class PhabricatorDashboardPanel
protected $panelType;
protected $viewPolicy;
protected $editPolicy;
protected $authorPHID;
protected $isArchived = 0;
protected $properties = array();
@ -24,17 +25,20 @@ final class PhabricatorDashboardPanel
public static function initializeNewPanel(PhabricatorUser $actor) {
return id(new PhabricatorDashboardPanel())
->setName('')
->setAuthorPHID($actor->getPHID())
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
->setEditPolicy($actor->getPHID());
}
public static function copyPanel(
PhabricatorDashboardPanel $dst,
PhabricatorDashboardPanel $src) {
PhabricatorDashboardPanel $src,
PhabricatorUser $user) {
$dst->name = $src->name;
$dst->panelType = $src->panelType;
$dst->properties = $src->properties;
$dst->authorPHID = $user->getPHID();
return $dst;
}
@ -48,6 +52,7 @@ final class PhabricatorDashboardPanel
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text255',
'panelType' => 'text64',
'authorPHID' => 'phid',
'isArchived' => 'bool',
),
) + parent::getConfiguration();