Changeset View
Changeset View
Standalone View
Standalone View
src/applications/tokens/editor/PhabricatorTokenEditor.php
- This file was added.
| <?php | |||||
| final class PhabricatorTokenEditor | |||||
| extends PhabricatorApplicationTransactionEditor { | |||||
| public function getEditorApplicationClass() { | |||||
| return 'PhabricatorTokensApplication'; | |||||
| } | |||||
| public function getEditorObjectsDescription() { | |||||
| return pht('Phabricator Tokens'); | |||||
| } | |||||
| public function getTransactionTypes() { | |||||
| $types = parent::getTransactionTypes(); | |||||
| $types[] = PhabricatorTokensTransaction::TYPE_NAME; | |||||
| $types[] = PhabricatorTokensTransaction::TYPE_FLAVOR; | |||||
| $types[] = PhabricatorTokensTransaction::TYPE_STATUS; | |||||
| $types[] = PhabricatorTokensTransaction::TYPE_IMAGE; | |||||
| $types[] = PhabricatorTransactions::TYPE_COMMENT; | |||||
| $types[] = PhabricatorTransactions::TYPE_EDGE; | |||||
| $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; | |||||
| return $types; | |||||
| } | |||||
| protected function getCustomTransactionOldValue( | |||||
| PhabricatorLiskDAO $object, | |||||
| PhabricatorApplicationTransaction $xaction) { | |||||
| switch ($xaction->getTransactionType()) { | |||||
| case PhabricatorTokensTransaction::TYPE_NAME: | |||||
| return $object->getName(); | |||||
| case PhabricatorTokensTransaction::TYPE_FLAVOR: | |||||
| return $object->getFlavor(); | |||||
| case PhabricatorTokensTransaction::TYPE_STATUS: | |||||
| return $object->getStatus(); | |||||
| case PhabricatorTokensTransaction::TYPE_IMAGE: | |||||
| return $object->getImage(); | |||||
| } | |||||
| } | |||||
| protected function getCustomTransactionNewValue( | |||||
| PhabricatorLiskDAO $object, | |||||
| PhabricatorApplicationTransaction $xaction) { | |||||
| switch ($xaction->getTransactionType()) { | |||||
| case PhabricatorTokensTransaction::TYPE_NAME: | |||||
| case PhabricatorTokensTransaction::TYPE_FLAVOR: | |||||
| case PhabricatorTokensTransaction::TYPE_STATUS: | |||||
| case PhabricatorTokensTransaction::TYPE_IMAGE: | |||||
| return $xaction->getNewValue(); | |||||
| } | |||||
| } | |||||
| protected function applyCustomInternalTransaction( | |||||
| PhabricatorLiskDAO $object, | |||||
| PhabricatorApplicationTransaction $xaction) { | |||||
| switch ($xaction->getTransactionType()) { | |||||
| case PhabricatorTokensTransaction::TYPE_NAME: | |||||
| return $object->setName($xaction->getNewValue()); | |||||
| case PhabricatorTokensTransaction::TYPE_FLAVOR: | |||||
| return $object->setFlavor($xaction->getNewValue()); | |||||
| case PhabricatorTokensTransaction::TYPE_STATUS: | |||||
| return $object->setStatus($xaction->getNewValue()); | |||||
| case PhabricatorTokensTransaction::TYPE_IMAGE: | |||||
| return $object->setImage($xaction->getNewValue()); | |||||
| } | |||||
| return parent::applyCustomInternalTransaction($object, $xaction); | |||||
| } | |||||
| protected function applyCustomExternalTransaction( | |||||
| PhabricatorLiskDAO $object, | |||||
| PhabricatorApplicationTransaction $xaction) { | |||||
| switch ($xaction->getTransactionType()) { | |||||
| case PhabricatorTokensTransaction::TYPE_NAME: | |||||
| case PhabricatorTokensTransaction::TYPE_FLAVOR: | |||||
| case PhabricatorTokensTransaction::TYPE_STATUS: | |||||
| case PhabricatorTokensTransaction::TYPE_IMAGE: | |||||
| return; | |||||
| } | |||||
| return parent::applyCustomExternalTransaction($object, $xaction); | |||||
| } | |||||
| protected function validateTransaction( | |||||
| PhabricatorLiskDAO $object, | |||||
| $type, | |||||
| array $xactions) { | |||||
| $errors = parent::validateTransaction($object, $type, $xactions); | |||||
| switch ($type) { | |||||
| case PhabricatorTokensTransaction::TYPE_NAME: | |||||
| $missing = $this->validateIsEmptyTextField( | |||||
| $object->getName(), | |||||
| $xactions); | |||||
| if ($missing) { | |||||
| $error = new PhabricatorApplicationTransactionValidationError( | |||||
| $type, | |||||
| pht('Required'), | |||||
| pht('Name is required.'), | |||||
| nonempty(last($xactions), null)); | |||||
| $error->setIsMissingFieldError(true); | |||||
| $errors[] = $error; | |||||
| } | |||||
| break; | |||||
| } | |||||
epriestley: TYPE_IMAGE needs to verify that the image PHID exists, and that the viewer has permission to… | |||||
| return $errors; | |||||
| } | |||||
| protected function shouldSendMail( | |||||
| PhabricatorLiskDAO $object, | |||||
| array $xactions) { | |||||
| return true; | |||||
| } | |||||
| protected function shouldPublishFeedStory( | |||||
| PhabricatorLiskDAO $object, | |||||
| array $xactions) { | |||||
| return true; | |||||
| } | |||||
| protected function getMailTo(PhabricatorLiskDAO $object) { | |||||
| $phids = array(); | |||||
| $phids[] = $this->requireActor()->getPHID(); | |||||
| $phids[] = $object->getCreatorPHID(); | |||||
| return $phids; | |||||
| } | |||||
| protected function buildMailTemplate(PhabricatorLiskDAO $object) { | |||||
| $phid = $object->getPHID(); | |||||
| $name = $object->getName(); | |||||
| return id(new PhabricatorMetaMTAMail()) | |||||
| ->setSubject($name) | |||||
| ->addHeader('Thread-Topic', $phid); | |||||
| } | |||||
| protected function buildReplyHandler(PhabricatorLiskDAO $object) { | |||||
| return id(new PhabricatorTokensReplyHandler()) | |||||
| ->setMailReceiver($object); | |||||
| } | |||||
| protected function buildMailBody( | |||||
| PhabricatorLiskDAO $object, | |||||
| array $xactions) { | |||||
| $body = parent::buildMailBody($object, $xactions); | |||||
| $body->addLinkSection( | |||||
| pht('TOKEN DETAIL'), | |||||
| PhabricatorEnv::getProductionURI($object->getViewURI())); | |||||
| return $body; | |||||
| } | |||||
| public function getMailTagsMap() { | |||||
| return array( | |||||
| PhabricatorTokensTransaction::MAILTAG_DETAILS => | |||||
| pht("A token's details change."), | |||||
| PhabricatorTokensTransaction::MAILTAG_SUBSCRIBERS => | |||||
| pht("A token's subscribers change."), | |||||
| PhabricatorTokensTransaction::MAILTAG_OTHER => | |||||
| pht('Other token activity not listed above occurs.'), | |||||
| ); | |||||
| } | |||||
| protected function getMailSubjectPrefix() { | |||||
| return '[Tokens]'; | |||||
| } | |||||
| protected function supportsSearch() { | |||||
| return false; | |||||
| } | |||||
| protected function shouldApplyHeraldRules( | |||||
| PhabricatorLiskDAO $object, | |||||
| array $xactions) { | |||||
| return false; | |||||
| } | |||||
epriestleyUnsubmitted Not Done Inline ActionsWhen the IMAGE is updated, the Editor should emit the new image from extractFilePHIDs(). Otherwise, it won't get attached to the token and other users won't be able to see it. With modular transactions, this got simpler -- see PhabricatorPasteContentTransaction for an example. epriestley: When the IMAGE is updated, the Editor should emit the new image from `extractFilePHIDs()`. | |||||
| } | |||||
TYPE_IMAGE needs to verify that the image PHID exists, and that the viewer has permission to see it. Otherwise, you can do this to view any file whether you have permission to see it or not:
If we're going to use data URIs, it looks like they have a maximum length of 32KB in IE. I'm not sure what (if anything) we should do about that. Some possibilities might be:
It would be nice for TYPE_NAME to enforce the length restriction with an explicit error. If you try to create a 65+ character token name I think you'll get an unhelplful exception from MySQL.
It would be nice for TYPE_FLAVOR to enforce the length restriction with an explicit error, or to remove the restriction.