@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

Dashboards: Edit Chart Panel: Add proper chart key validation

Summary:
Add proper validation by actually querying for existing chart keys.
This replaces my quick and dirty code from D26378.

Closes T16281

Test Plan:
* Go to http://phorge.localhost/dashboard/panel/edit/?panelType=chart
* Enter rubbish into the "Chart" field or leave it empty and try to create that panel, get an error instead of creating a panel
* Enter a random 12 character chart key into the field, now get an error
* Enter an existing 12 character chart key into the field taken from `SELECT chartKey FROM phabricator_fact.fact_chart;`, succeed

Reviewers: O1 Blessed Committers, mainframe98

Reviewed By: O1 Blessed Committers, mainframe98

Subscribers: mainframe98, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T16281

Differential Revision: https://we.phorge.it/D26396

+24 -3
+20 -3
src/applications/dashboard/xaction/panel/PhabricatorDashboardChartPanelChartTransaction.php
··· 14 14 15 15 foreach ($xactions as $xaction) { 16 16 $new = $xaction->getNewValue(); 17 - // per PhabricatorFactChart::newChartKey() 18 - if (strlen($new) !== 12) { 17 + if (!$this->loadChart($new)) { 19 18 $errors[] = $this->newInvalidError( 20 - pht('Chart must be specified by its %d character long key.', 12), 19 + pht('Chart with this key does not exist. A chart must be '. 20 + 'specified by its %d character long key.', 21 + 12), 21 22 $xaction); 22 23 continue; 23 24 } 24 25 } 25 26 return $errors; 27 + } 28 + 29 + private function loadChart($chart_key) { 30 + // PhabricatorFactChartQuery does not exist so use queryfx_one() 31 + $chart = new PhabricatorFactChart(); 32 + $conn_r = $chart->establishConnection('r'); 33 + $chart = queryfx_one( 34 + $conn_r, 35 + 'SELECT 36 + id 37 + FROM %R 38 + WHERE chartKey = %s', 39 + $chart, 40 + $chart_key); 41 + 42 + return $chart; 26 43 } 27 44 28 45 }
+4
src/infrastructure/storage/lisk/PhabricatorLiskDAO.php
··· 180 180 181 181 182 182 /** 183 + * Get the database table name 184 + * @return string Name of the database table 183 185 * @task config 184 186 */ 185 187 public function getTableName() { ··· 203 205 } 204 206 205 207 /** 208 + * Get the database name 209 + * @return string Name of the database 206 210 * @task config 207 211 */ 208 212 abstract public function getApplicationName();