1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Add award and revoke conduit calls to Badges

Summary: Allow people to award and remove badges via conduit, but not from the standard badges form.

Test Plan:
Build a generator and generate awards. Didn't test the revoke yet.

{F3857766}

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T12270

Differential Revision: https://secure.phabricator.com/D17482
This commit is contained in:
Chad Little 2017-03-09 11:30:03 -08:00
parent 3277d8b8c8
commit fa569c35d3
3 changed files with 55 additions and 0 deletions

View file

@ -2018,6 +2018,7 @@ phutil_register_library_map(array(
'PhabricatorBadgesAward' => 'applications/badges/storage/PhabricatorBadgesAward.php',
'PhabricatorBadgesAwardController' => 'applications/badges/controller/PhabricatorBadgesAwardController.php',
'PhabricatorBadgesAwardQuery' => 'applications/badges/query/PhabricatorBadgesAwardQuery.php',
'PhabricatorBadgesAwardTestDataGenerator' => 'applications/badges/lipsum/PhabricatorBadgesAwardTestDataGenerator.php',
'PhabricatorBadgesBadge' => 'applications/badges/storage/PhabricatorBadgesBadge.php',
'PhabricatorBadgesBadgeAwardTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeAwardTransaction.php',
'PhabricatorBadgesBadgeDescriptionTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeDescriptionTransaction.php',
@ -7000,6 +7001,7 @@ phutil_register_library_map(array(
),
'PhabricatorBadgesAwardController' => 'PhabricatorBadgesController',
'PhabricatorBadgesAwardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorBadgesAwardTestDataGenerator' => 'PhabricatorTestDataGenerator',
'PhabricatorBadgesBadge' => array(
'PhabricatorBadgesDAO',
'PhabricatorPolicyInterface',

View file

@ -124,6 +124,23 @@ final class PhabricatorBadgesEditEngine
->setTransactionType(
PhabricatorBadgesBadgeDescriptionTransaction::TRANSACTIONTYPE)
->setValue($object->getDescription()),
id(new PhabricatorUsersEditField())
->setKey('award')
->setIsConduitOnly(true)
->setDescription(pht('New badge award recipients.'))
->setConduitTypeDescription(pht('New badge award recipients.'))
->setTransactionType(
PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE)
->setLabel(pht('Award Recipients')),
id(new PhabricatorUsersEditField())
->setKey('revoke')
->setIsConduitOnly(true)
->setDescription(pht('Revoke badge award recipients.'))
->setConduitTypeDescription(pht('Revoke badge award recipients.'))
->setTransactionType(
PhabricatorBadgesBadgeRevokeTransaction::TRANSACTIONTYPE)
->setLabel(pht('Revoke Recipients')),
);
}

View file

@ -0,0 +1,36 @@
<?php
final class PhabricatorBadgesAwardTestDataGenerator
extends PhabricatorTestDataGenerator {
const GENERATORKEY = 'badges.award';
public function getGeneratorName() {
return pht('Badges Award');
}
public function generateObject() {
$author = $this->loadRandomUser();
$recipient = $this->loadRandomUser();
$badge_phid = $this->loadRandomPHID(new PhabricatorBadgesBadge());
$xactions = array();
$xactions[] = array(
'type' => 'award',
'value' => array($recipient->getPHID()),
);
$params = array(
'transactions' => $xactions,
'objectIdentifier' => $badge_phid,
);
$result = id(new ConduitCall('badges.edit', $params))
->setUser($author)
->execute();
return $result['object']['phid'];
}
}