@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

Validate color existence when setting project color

Summary:
Do not allow setting an invalid project color via the `project.edit` Conduit API but validate the value.

Same game as in D26430, D26459.

Closes T16237

Test Plan:
* Run `echo '{"transactions":[{"type":"name","value":"projectWithInvalidColor"},{"type":"color","value":"purpleyellowgreyish"},{"type":"description","value":"project project new new new"}]}' | /var/www/html/phorge/arcanist/bin/arc call-conduit --conduit-uri http://phorge.localhost --conduit-token "cli-xxx" project.edit --`
* Succeed before applying this patch
* Fail after applying this patch:
```
{
"error": "ERR-CONDUIT-CORE",
"errorMessage": "ERR-CONDUIT-CORE: <project.edit> Validation errors:\n - Value for \"project:color\" is invalid: \"purpleyellowgreyish\".",
"response": null
}
```
* Still succeed with a valid name like `{"type":"color","value":"checkered"}`
* Manually set a color in the project using the frontend. It works.
* Change every single other color, like Red, Orange, Yellow, ... Grey, Checkered, they all works
* Set color to Orange. Archive the project. Activate the project. It still works, you still see the original color Orange.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

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

Maniphest Tasks: T16323, T16237

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

+24
+24
src/applications/project/xaction/PhabricatorProjectColorTransaction.php
··· 30 30 $this->renderValue(PHUITagView::getShadeName($new))); 31 31 } 32 32 33 + public function validateTransactions($object, array $xactions) { 34 + $errors = array(); 35 + 36 + if (!$xactions) { 37 + return $errors; 38 + } 39 + 40 + foreach ($xactions as $xaction) { 41 + $new_color = $xaction->getNewValue(); 42 + if (!PhabricatorProjectIconSet::getColorName($new_color)) { 43 + $errors[] = new PhabricatorApplicationTransactionValidationError( 44 + self::TRANSACTIONTYPE, 45 + pht('Invalid'), 46 + pht( 47 + 'Value for "%s" is invalid: "%s".', 48 + self::TRANSACTIONTYPE, 49 + $new_color)); 50 + break; 51 + } 52 + } 53 + 54 + return $errors; 55 + } 56 + 33 57 }