@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Miscellanous badge fixes

Summary: Ref T12270. Add transaction validation for name, alias, award, revoke. Change auto subscribe for authors. Fix some typos.

Test Plan: Add badge, award badge, revoke badge, edit badge.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T12270

Differential Revision: https://secure.phabricator.com/D17412

+114 -14
+1 -1
src/applications/badges/controller/PhabricatorBadgesAwardController.php
··· 67 67 )))); 68 68 69 69 $dialog = $this->newDialog() 70 - ->setTitle(pht('Grant Badge')) 70 + ->setTitle(pht('Award Badge')) 71 71 ->appendForm($form) 72 72 ->addCancelButton($view_uri) 73 73 ->addSubmitButton(pht('Award'));
+1 -1
src/applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php
··· 29 29 return new Aphront404Response(); 30 30 } 31 31 32 - $view_uri = $this->getApplicationURI('view/'.$badge->getID().'/'); 32 + $view_uri = $this->getApplicationURI('recipients/'.$badge->getID().'/'); 33 33 34 34 if ($request->isFormPost()) { 35 35 $xactions = array();
-9
src/applications/badges/controller/PhabricatorBadgesViewController.php
··· 90 90 $id = $badge->getID(); 91 91 $edit_uri = $this->getApplicationURI("/edit/{$id}/"); 92 92 $archive_uri = $this->getApplicationURI("/archive/{$id}/"); 93 - $award_uri = $this->getApplicationURI("/recipients/{$id}/add/"); 94 93 95 94 $curtain = $this->newCurtainView($badge); 96 95 ··· 118 117 ->setWorkflow($can_edit) 119 118 ->setHref($archive_uri)); 120 119 } 121 - 122 - $curtain->addAction( 123 - id(new PhabricatorActionView()) 124 - ->setName('Add Recipients') 125 - ->setIcon('fa-users') 126 - ->setDisabled(!$can_edit) 127 - ->setWorkflow(true) 128 - ->setHref($award_uri)); 129 120 130 121 return $curtain; 131 122 }
+1 -1
src/applications/badges/editor/PhabricatorBadgesEditEngine.php
··· 92 92 ->setIsRequired(true), 93 93 id(new PhabricatorTextEditField()) 94 94 ->setKey('flavor') 95 - ->setLabel(pht('Flavor text')) 95 + ->setLabel(pht('Flavor Text')) 96 96 ->setDescription(pht('Short description of the badge.')) 97 97 ->setConduitTypeDescription(pht('New badge flavor.')) 98 98 ->setValue($object->getFlavor())
+24
src/applications/badges/editor/PhabricatorBadgesEditor.php
··· 55 55 return true; 56 56 } 57 57 58 + protected function expandTransactions( 59 + PhabricatorLiskDAO $object, 60 + array $xactions) { 61 + 62 + $actor = $this->getActor(); 63 + $actor_phid = $actor->getPHID(); 64 + 65 + $results = parent::expandTransactions($object, $xactions); 66 + 67 + // Automatically subscribe the author when they create a badge. 68 + if ($this->getIsNewObject()) { 69 + if ($actor_phid) { 70 + $results[] = id(new PhabricatorBadgesTransaction()) 71 + ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) 72 + ->setNewValue( 73 + array( 74 + '+' => array($actor_phid => $actor_phid), 75 + )); 76 + } 77 + } 78 + 79 + return $results; 80 + } 81 + 58 82 protected function buildReplyHandler(PhabricatorLiskDAO $object) { 59 83 return id(new PhabricatorBadgesReplyHandler()) 60 84 ->setMailReceiver($object);
+1 -1
src/applications/badges/query/PhabricatorBadgesSearchEngine.php
··· 147 147 ->setTitle(pht('Welcome to %s', $app_name)) 148 148 ->setDescription( 149 149 pht('Badges let you award and distinguish special users '. 150 - 'throughout your instance.')) 150 + 'throughout your install.')) 151 151 ->addAction($create_button); 152 152 153 153 return $view;
+1 -1
src/applications/badges/storage/PhabricatorBadgesBadge.php
··· 156 156 157 157 158 158 public function isAutomaticallySubscribed($phid) { 159 - return ($this->creatorPHID == $phid); 159 + return false; 160 160 } 161 161 162 162
+28
src/applications/badges/xaction/PhabricatorBadgesBadgeAwardTransaction.php
··· 59 59 return 'fa-user-plus'; 60 60 } 61 61 62 + public function validateTransactions($object, array $xactions) { 63 + $errors = array(); 64 + 65 + foreach ($xactions as $xaction) { 66 + $user_phids = $xaction->getNewValue(); 67 + if (!$user_phids) { 68 + $errors[] = $this->newRequiredError( 69 + pht('Recipient is required.')); 70 + continue; 71 + } 72 + 73 + foreach ($user_phids as $user_phid) { 74 + $user = id(new PhabricatorPeopleQuery()) 75 + ->setViewer($this->getActor()) 76 + ->withPHIDs(array($user_phid)) 77 + ->executeOne(); 78 + if (!$user) { 79 + $errors[] = $this->newInvalidError( 80 + pht( 81 + 'Recipient PHID "%s" is not a valid user PHID.', 82 + $user_phid)); 83 + } 84 + } 85 + } 86 + 87 + return $errors; 88 + } 89 + 62 90 }
+17
src/applications/badges/xaction/PhabricatorBadgesBadgeFlavorTransaction.php
··· 30 30 $this->renderNewValue()); 31 31 } 32 32 33 + public function validateTransactions($object, array $xactions) { 34 + $errors = array(); 35 + 36 + $max_length = $object->getColumnMaximumByteLength('flavor'); 37 + foreach ($xactions as $xaction) { 38 + $new_value = $xaction->getNewValue(); 39 + $new_length = strlen($new_value); 40 + if ($new_length > $max_length) { 41 + $errors[] = $this->newRequiredError( 42 + pht('The flavor text can be no longer than %s characters.', 43 + new PhutilNumber($max_length))); 44 + } 45 + } 46 + 47 + return $errors; 48 + } 49 + 33 50 }
+11
src/applications/badges/xaction/PhabricatorBadgesBadgeNameTransaction.php
··· 38 38 pht('Badges must have a name.')); 39 39 } 40 40 41 + $max_length = $object->getColumnMaximumByteLength('name'); 42 + foreach ($xactions as $xaction) { 43 + $new_value = $xaction->getNewValue(); 44 + $new_length = strlen($new_value); 45 + if ($new_length > $max_length) { 46 + $errors[] = $this->newRequiredError( 47 + pht('The name can be no longer than %s characters.', 48 + new PhutilNumber($max_length))); 49 + } 50 + } 51 + 41 52 return $errors; 42 53 } 43 54
+29
src/applications/badges/xaction/PhabricatorBadgesBadgeRevokeTransaction.php
··· 51 51 return 'fa-user-times'; 52 52 } 53 53 54 + public function validateTransactions($object, array $xactions) { 55 + $errors = array(); 56 + 57 + foreach ($xactions as $xaction) { 58 + $award_phids = $xaction->getNewValue(); 59 + if (!$award_phids) { 60 + $errors[] = $this->newRequiredError( 61 + pht('Recipient is required.')); 62 + continue; 63 + } 64 + 65 + foreach ($award_phids as $award_phid) { 66 + $award = id(new PhabricatorBadgesAwardQuery()) 67 + ->setViewer($this->getActor()) 68 + ->withRecipientPHIDs(array($award_phid)) 69 + ->withBadgePHIDs(array($object->getPHID())) 70 + ->executeOne(); 71 + if (!$award) { 72 + $errors[] = $this->newInvalidError( 73 + pht( 74 + 'Recipient PHID "%s" has not been awarded.', 75 + $award_phid)); 76 + } 77 + } 78 + } 79 + 80 + return $errors; 81 + } 82 + 54 83 }