diff --git a/resources/sql/autopatches/20161212.dashboardpanel.01.author.sql b/resources/sql/autopatches/20161212.dashboardpanel.01.author.sql new file mode 100644 index 0000000000..00c52d19cb --- /dev/null +++ b/resources/sql/autopatches/20161212.dashboardpanel.01.author.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_dashboard.dashboard_panel + ADD authorPHID VARBINARY(64) NOT NULL; diff --git a/resources/sql/autopatches/20161212.dashboardpanel.02.author.php b/resources/sql/autopatches/20161212.dashboardpanel.02.author.php new file mode 100644 index 0000000000..bc87aef91c --- /dev/null +++ b/resources/sql/autopatches/20161212.dashboardpanel.02.author.php @@ -0,0 +1,39 @@ +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"); diff --git a/src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php b/src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php index b85498c13c..787d1c63ee 100644 --- a/src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php @@ -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(); diff --git a/src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php b/src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php index 3a6589a32c..6fbdb3d99c 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php +++ b/src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php @@ -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; } diff --git a/src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php b/src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php index 113ed8ff94..d9fe25ab02 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php +++ b/src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php @@ -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; } diff --git a/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php b/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php index 70325de3bb..389bbb6bdc 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php +++ b/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php @@ -56,7 +56,7 @@ final class PhabricatorDashboardSearchEngine return $query; case 'authored': return $query->setParameter( - 'authored', + 'authorPHIDs', array( $viewer->getPHID(), )); diff --git a/src/applications/dashboard/storage/PhabricatorDashboardPanel.php b/src/applications/dashboard/storage/PhabricatorDashboardPanel.php index 64e6ea5b87..6067abf79f 100644 --- a/src/applications/dashboard/storage/PhabricatorDashboardPanel.php +++ b/src/applications/dashboard/storage/PhabricatorDashboardPanel.php @@ -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();