1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 14:30:56 +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:
Chad Little 2017-02-24 15:21:23 -08:00
parent 730d88c414
commit eec6cd865c
11 changed files with 114 additions and 14 deletions

View file

@ -67,7 +67,7 @@ final class PhabricatorBadgesAwardController
)))); ))));
$dialog = $this->newDialog() $dialog = $this->newDialog()
->setTitle(pht('Grant Badge')) ->setTitle(pht('Award Badge'))
->appendForm($form) ->appendForm($form)
->addCancelButton($view_uri) ->addCancelButton($view_uri)
->addSubmitButton(pht('Award')); ->addSubmitButton(pht('Award'));

View file

@ -29,7 +29,7 @@ final class PhabricatorBadgesRemoveRecipientsController
return new Aphront404Response(); return new Aphront404Response();
} }
$view_uri = $this->getApplicationURI('view/'.$badge->getID().'/'); $view_uri = $this->getApplicationURI('recipients/'.$badge->getID().'/');
if ($request->isFormPost()) { if ($request->isFormPost()) {
$xactions = array(); $xactions = array();

View file

@ -90,7 +90,6 @@ final class PhabricatorBadgesViewController
$id = $badge->getID(); $id = $badge->getID();
$edit_uri = $this->getApplicationURI("/edit/{$id}/"); $edit_uri = $this->getApplicationURI("/edit/{$id}/");
$archive_uri = $this->getApplicationURI("/archive/{$id}/"); $archive_uri = $this->getApplicationURI("/archive/{$id}/");
$award_uri = $this->getApplicationURI("/recipients/{$id}/add/");
$curtain = $this->newCurtainView($badge); $curtain = $this->newCurtainView($badge);
@ -119,14 +118,6 @@ final class PhabricatorBadgesViewController
->setHref($archive_uri)); ->setHref($archive_uri));
} }
$curtain->addAction(
id(new PhabricatorActionView())
->setName('Add Recipients')
->setIcon('fa-users')
->setDisabled(!$can_edit)
->setWorkflow(true)
->setHref($award_uri));
return $curtain; return $curtain;
} }

View file

@ -92,7 +92,7 @@ final class PhabricatorBadgesEditEngine
->setIsRequired(true), ->setIsRequired(true),
id(new PhabricatorTextEditField()) id(new PhabricatorTextEditField())
->setKey('flavor') ->setKey('flavor')
->setLabel(pht('Flavor text')) ->setLabel(pht('Flavor Text'))
->setDescription(pht('Short description of the badge.')) ->setDescription(pht('Short description of the badge.'))
->setConduitTypeDescription(pht('New badge flavor.')) ->setConduitTypeDescription(pht('New badge flavor.'))
->setValue($object->getFlavor()) ->setValue($object->getFlavor())

View file

@ -55,6 +55,30 @@ final class PhabricatorBadgesEditor
return true; 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) { protected function buildReplyHandler(PhabricatorLiskDAO $object) {
return id(new PhabricatorBadgesReplyHandler()) return id(new PhabricatorBadgesReplyHandler())
->setMailReceiver($object); ->setMailReceiver($object);

View file

@ -147,7 +147,7 @@ final class PhabricatorBadgesSearchEngine
->setTitle(pht('Welcome to %s', $app_name)) ->setTitle(pht('Welcome to %s', $app_name))
->setDescription( ->setDescription(
pht('Badges let you award and distinguish special users '. pht('Badges let you award and distinguish special users '.
'throughout your instance.')) 'throughout your install.'))
->addAction($create_button); ->addAction($create_button);
return $view; return $view;

View file

@ -156,7 +156,7 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
public function isAutomaticallySubscribed($phid) { public function isAutomaticallySubscribed($phid) {
return ($this->creatorPHID == $phid); return false;
} }

View file

@ -59,4 +59,32 @@ final class PhabricatorBadgesBadgeAwardTransaction
return 'fa-user-plus'; 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;
}
} }

View file

@ -30,4 +30,21 @@ final class PhabricatorBadgesBadgeFlavorTransaction
$this->renderNewValue()); $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;
}
} }

View file

@ -38,6 +38,17 @@ final class PhabricatorBadgesBadgeNameTransaction
pht('Badges must have a name.')); 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; return $errors;
} }

View file

@ -51,4 +51,33 @@ final class PhabricatorBadgesBadgeRevokeTransaction
return 'fa-user-times'; 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;
}
} }