mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
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
This commit is contained in:
parent
730d88c414
commit
eec6cd865c
11 changed files with 114 additions and 14 deletions
|
@ -67,7 +67,7 @@ final class PhabricatorBadgesAwardController
|
|||
))));
|
||||
|
||||
$dialog = $this->newDialog()
|
||||
->setTitle(pht('Grant Badge'))
|
||||
->setTitle(pht('Award Badge'))
|
||||
->appendForm($form)
|
||||
->addCancelButton($view_uri)
|
||||
->addSubmitButton(pht('Award'));
|
||||
|
|
|
@ -29,7 +29,7 @@ final class PhabricatorBadgesRemoveRecipientsController
|
|||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$view_uri = $this->getApplicationURI('view/'.$badge->getID().'/');
|
||||
$view_uri = $this->getApplicationURI('recipients/'.$badge->getID().'/');
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$xactions = array();
|
||||
|
|
|
@ -90,7 +90,6 @@ final class PhabricatorBadgesViewController
|
|||
$id = $badge->getID();
|
||||
$edit_uri = $this->getApplicationURI("/edit/{$id}/");
|
||||
$archive_uri = $this->getApplicationURI("/archive/{$id}/");
|
||||
$award_uri = $this->getApplicationURI("/recipients/{$id}/add/");
|
||||
|
||||
$curtain = $this->newCurtainView($badge);
|
||||
|
||||
|
@ -119,14 +118,6 @@ final class PhabricatorBadgesViewController
|
|||
->setHref($archive_uri));
|
||||
}
|
||||
|
||||
$curtain->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName('Add Recipients')
|
||||
->setIcon('fa-users')
|
||||
->setDisabled(!$can_edit)
|
||||
->setWorkflow(true)
|
||||
->setHref($award_uri));
|
||||
|
||||
return $curtain;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ final class PhabricatorBadgesEditEngine
|
|||
->setIsRequired(true),
|
||||
id(new PhabricatorTextEditField())
|
||||
->setKey('flavor')
|
||||
->setLabel(pht('Flavor text'))
|
||||
->setLabel(pht('Flavor Text'))
|
||||
->setDescription(pht('Short description of the badge.'))
|
||||
->setConduitTypeDescription(pht('New badge flavor.'))
|
||||
->setValue($object->getFlavor())
|
||||
|
|
|
@ -55,6 +55,30 @@ final class PhabricatorBadgesEditor
|
|||
return true;
|
||||
}
|
||||
|
||||
protected function expandTransactions(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
|
||||
$actor = $this->getActor();
|
||||
$actor_phid = $actor->getPHID();
|
||||
|
||||
$results = parent::expandTransactions($object, $xactions);
|
||||
|
||||
// Automatically subscribe the author when they create a badge.
|
||||
if ($this->getIsNewObject()) {
|
||||
if ($actor_phid) {
|
||||
$results[] = id(new PhabricatorBadgesTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
|
||||
->setNewValue(
|
||||
array(
|
||||
'+' => array($actor_phid => $actor_phid),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
|
||||
return id(new PhabricatorBadgesReplyHandler())
|
||||
->setMailReceiver($object);
|
||||
|
|
|
@ -147,7 +147,7 @@ final class PhabricatorBadgesSearchEngine
|
|||
->setTitle(pht('Welcome to %s', $app_name))
|
||||
->setDescription(
|
||||
pht('Badges let you award and distinguish special users '.
|
||||
'throughout your instance.'))
|
||||
'throughout your install.'))
|
||||
->addAction($create_button);
|
||||
|
||||
return $view;
|
||||
|
|
|
@ -156,7 +156,7 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
|||
|
||||
|
||||
public function isAutomaticallySubscribed($phid) {
|
||||
return ($this->creatorPHID == $phid);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -59,4 +59,32 @@ final class PhabricatorBadgesBadgeAwardTransaction
|
|||
return 'fa-user-plus';
|
||||
}
|
||||
|
||||
public function validateTransactions($object, array $xactions) {
|
||||
$errors = array();
|
||||
|
||||
foreach ($xactions as $xaction) {
|
||||
$user_phids = $xaction->getNewValue();
|
||||
if (!$user_phids) {
|
||||
$errors[] = $this->newRequiredError(
|
||||
pht('Recipient is required.'));
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($user_phids as $user_phid) {
|
||||
$user = id(new PhabricatorPeopleQuery())
|
||||
->setViewer($this->getActor())
|
||||
->withPHIDs(array($user_phid))
|
||||
->executeOne();
|
||||
if (!$user) {
|
||||
$errors[] = $this->newInvalidError(
|
||||
pht(
|
||||
'Recipient PHID "%s" is not a valid user PHID.',
|
||||
$user_phid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,4 +30,21 @@ final class PhabricatorBadgesBadgeFlavorTransaction
|
|||
$this->renderNewValue());
|
||||
}
|
||||
|
||||
public function validateTransactions($object, array $xactions) {
|
||||
$errors = array();
|
||||
|
||||
$max_length = $object->getColumnMaximumByteLength('flavor');
|
||||
foreach ($xactions as $xaction) {
|
||||
$new_value = $xaction->getNewValue();
|
||||
$new_length = strlen($new_value);
|
||||
if ($new_length > $max_length) {
|
||||
$errors[] = $this->newRequiredError(
|
||||
pht('The flavor text can be no longer than %s characters.',
|
||||
new PhutilNumber($max_length)));
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,17 @@ final class PhabricatorBadgesBadgeNameTransaction
|
|||
pht('Badges must have a name.'));
|
||||
}
|
||||
|
||||
$max_length = $object->getColumnMaximumByteLength('name');
|
||||
foreach ($xactions as $xaction) {
|
||||
$new_value = $xaction->getNewValue();
|
||||
$new_length = strlen($new_value);
|
||||
if ($new_length > $max_length) {
|
||||
$errors[] = $this->newRequiredError(
|
||||
pht('The name can be no longer than %s characters.',
|
||||
new PhutilNumber($max_length)));
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,4 +51,33 @@ final class PhabricatorBadgesBadgeRevokeTransaction
|
|||
return 'fa-user-times';
|
||||
}
|
||||
|
||||
public function validateTransactions($object, array $xactions) {
|
||||
$errors = array();
|
||||
|
||||
foreach ($xactions as $xaction) {
|
||||
$award_phids = $xaction->getNewValue();
|
||||
if (!$award_phids) {
|
||||
$errors[] = $this->newRequiredError(
|
||||
pht('Recipient is required.'));
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($award_phids as $award_phid) {
|
||||
$award = id(new PhabricatorBadgesAwardQuery())
|
||||
->setViewer($this->getActor())
|
||||
->withRecipientPHIDs(array($award_phid))
|
||||
->withBadgePHIDs(array($object->getPHID()))
|
||||
->executeOne();
|
||||
if (!$award) {
|
||||
$errors[] = $this->newInvalidError(
|
||||
pht(
|
||||
'Recipient PHID "%s" has not been awarded.',
|
||||
$award_phid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue