@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+87 -7
+2
resources/sql/autopatches/20161212.dashboardpanel.01.author.sql
··· 1 + ALTER TABLE {$NAMESPACE}_dashboard.dashboard_panel 2 + ADD authorPHID VARBINARY(64) NOT NULL;
+39
resources/sql/autopatches/20161212.dashboardpanel.02.author.php
··· 1 + <?php 2 + 3 + // Set authorPHID on Dashboard Panels 4 + // 5 + $table = new PhabricatorDashboardPanel(); 6 + $conn_w = $table->establishConnection('w'); 7 + 8 + $txn_table = new PhabricatorDashboardPanelTransaction(); 9 + $txn_conn = $table->establishConnection('r'); 10 + 11 + echo pht("Building Dashboard Panel authorPHIDs...\n"); 12 + 13 + foreach (new LiskMigrationIterator($table) as $panel) { 14 + 15 + if ($panel->getAuthorPHID()) { 16 + continue; 17 + } 18 + 19 + $panel_row = queryfx_one( 20 + $txn_conn, 21 + 'SELECT authorPHID FROM %T WHERE objectPHID = %s ORDER BY id ASC LIMIT 1', 22 + $txn_table->getTableName(), 23 + $panel->getPHID()); 24 + 25 + if (!$panel_row) { 26 + $author_phid = id(new PhabricatorDashboardApplication())->getPHID(); 27 + } else { 28 + $author_phid = $panel_row['authorPHID']; 29 + } 30 + 31 + queryfx( 32 + $conn_w, 33 + 'UPDATE %T SET authorPHID = %s WHERE id = %d', 34 + $table->getTableName(), 35 + $author_phid, 36 + $panel->getID()); 37 + } 38 + 39 + echo pht("Done\n");
+1 -1
src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php
··· 400 400 $viewer = $request->getUser(); 401 401 402 402 $copy = PhabricatorDashboardPanel::initializeNewPanel($viewer); 403 - $copy = PhabricatorDashboardPanel::copyPanel($copy, $panel); 403 + $copy = PhabricatorDashboardPanel::copyPanel($copy, $panel, $viewer); 404 404 405 405 $copy->openTransaction(); 406 406 $copy->save();
+13
src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php
··· 7 7 private $phids; 8 8 private $archived; 9 9 private $panelTypes; 10 + private $authorPHIDs; 10 11 11 12 public function withIDs(array $ids) { 12 13 $this->ids = $ids; ··· 25 26 26 27 public function withPanelTypes(array $types) { 27 28 $this->panelTypes = $types; 29 + return $this; 30 + } 31 + 32 + public function withAuthorPHIDs(array $authors) { 33 + $this->authorPHIDs = $authors; 28 34 return $this; 29 35 } 30 36 ··· 73 79 $conn, 74 80 'panelType IN (%Ls)', 75 81 $this->panelTypes); 82 + } 83 + 84 + if ($this->authorPHIDs !== null) { 85 + $where[] = qsprintf( 86 + $conn, 87 + 'authorPHID IN (%Ls)', 88 + $this->authorPHIDs); 76 89 } 77 90 78 91 return $where;
+25 -4
src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php
··· 34 34 $query->withPanelTypes(array($map['paneltype'])); 35 35 } 36 36 37 + if ($map['authorPHIDs']) { 38 + $query->withAuthorPHIDs($map['authorPHIDs']); 39 + } 40 + 37 41 return $query; 38 42 } 39 43 40 44 protected function buildCustomSearchFields() { 41 45 42 46 return array( 47 + id(new PhabricatorSearchDatasourceField()) 48 + ->setLabel(pht('Authored By')) 49 + ->setKey('authorPHIDs') 50 + ->setDatasource(new PhabricatorPeopleUserFunctionDatasource()), 43 51 id(new PhabricatorSearchSelectField()) 44 52 ->setKey('status') 45 53 ->setLabel(pht('Status')) ··· 60 68 } 61 69 62 70 protected function getBuiltinQueryNames() { 63 - return array( 64 - 'active' => pht('Active Panels'), 65 - 'all' => pht('All Panels'), 66 - ); 71 + $names = array(); 72 + 73 + if ($this->requireViewer()->isLoggedIn()) { 74 + $names['authored'] = pht('Authored'); 75 + } 76 + 77 + $names['active'] = pht('Active Panels'); 78 + $names['all'] = pht('All Panels'); 79 + 80 + return $names; 67 81 } 68 82 69 83 public function buildSavedQueryFromBuiltin($query_key) { 70 84 $query = $this->newSavedQuery(); 71 85 $query->setQueryKey($query_key); 86 + $viewer = $this->requireViewer(); 72 87 73 88 switch ($query_key) { 74 89 case 'active': 75 90 return $query->setParameter('status', 'active'); 91 + case 'authored': 92 + return $query->setParameter( 93 + 'authorPHIDs', 94 + array( 95 + $viewer->getPHID(), 96 + )); 76 97 case 'all': 77 98 return $query; 78 99 }
+1 -1
src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php
··· 56 56 return $query; 57 57 case 'authored': 58 58 return $query->setParameter( 59 - 'authored', 59 + 'authorPHIDs', 60 60 array( 61 61 $viewer->getPHID(), 62 62 ));
+6 -1
src/applications/dashboard/storage/PhabricatorDashboardPanel.php
··· 16 16 protected $panelType; 17 17 protected $viewPolicy; 18 18 protected $editPolicy; 19 + protected $authorPHID; 19 20 protected $isArchived = 0; 20 21 protected $properties = array(); 21 22 ··· 24 25 public static function initializeNewPanel(PhabricatorUser $actor) { 25 26 return id(new PhabricatorDashboardPanel()) 26 27 ->setName('') 28 + ->setAuthorPHID($actor->getPHID()) 27 29 ->setViewPolicy(PhabricatorPolicies::POLICY_USER) 28 30 ->setEditPolicy($actor->getPHID()); 29 31 } 30 32 31 33 public static function copyPanel( 32 34 PhabricatorDashboardPanel $dst, 33 - PhabricatorDashboardPanel $src) { 35 + PhabricatorDashboardPanel $src, 36 + PhabricatorUser $user) { 34 37 35 38 $dst->name = $src->name; 36 39 $dst->panelType = $src->panelType; 37 40 $dst->properties = $src->properties; 41 + $dst->authorPHID = $user->getPHID(); 38 42 39 43 return $dst; 40 44 } ··· 48 52 self::CONFIG_COLUMN_SCHEMA => array( 49 53 'name' => 'text255', 50 54 'panelType' => 'text64', 55 + 'authorPHID' => 'phid', 51 56 'isArchived' => 'bool', 52 57 ), 53 58 ) + parent::getConfiguration();