diff --git a/src/applications/macro/editor/PhabricatorMacroEditEngine.php b/src/applications/macro/editor/PhabricatorMacroEditEngine.php index 2cafea937f..95627d2e11 100644 --- a/src/applications/macro/editor/PhabricatorMacroEditEngine.php +++ b/src/applications/macro/editor/PhabricatorMacroEditEngine.php @@ -1,88 +1,107 @@ getViewer(); return PhabricatorFileImageMacro::initializeNewFileImageMacro($viewer); } protected function newObjectQuery() { return new PhabricatorMacroQuery(); } protected function getObjectCreateTitleText($object) { return pht('Create New Macro'); } protected function getObjectEditTitleText($object) { - return pht('Edit %s', $object->getName()); + return pht('Edit Macro %s', $object->getName()); } protected function getObjectEditShortText($object) { return $object->getName(); } protected function getObjectCreateShortText() { return pht('Create Macro'); } protected function getObjectName() { return pht('Macro'); } protected function getObjectViewURI($object) { return $object->getViewURI(); } protected function getEditorURI() { return $this->getApplication()->getApplicationURI('edit/'); } protected function getCreateNewObjectPolicy() { return $this->getApplication()->getPolicy( PhabricatorMacroManageCapability::CAPABILITY); } + protected function willConfigureFields($object, array $fields) { + if ($this->getIsCreate()) { + $subscribers_field = idx($fields, + PhabricatorSubscriptionsEditEngineExtension::FIELDKEY); + if ($subscribers_field) { + // By default, hide the subscribers field when creating a macro + // because it makes the workflow SO HARD and wastes SO MUCH TIME. + $subscribers_field->setIsHidden(true); + } + } + return $fields; + } + protected function buildCustomEditFields($object) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setDescription(pht('Macro name.')) ->setConduitDescription(pht('Rename the macro.')) ->setConduitTypeDescription(pht('New macro name.')) ->setTransactionType(PhabricatorMacroNameTransaction::TRANSACTIONTYPE) + ->setIsRequired(true) ->setValue($object->getName()), id(new PhabricatorFileEditField()) ->setKey('filePHID') ->setLabel(pht('Image File')) ->setDescription(pht('Image file to import.')) ->setTransactionType(PhabricatorMacroFileTransaction::TRANSACTIONTYPE) ->setConduitDescription(pht('File PHID to import.')) - ->setConduitTypeDescription(pht('File PHID.')), + ->setConduitTypeDescription(pht('File PHID.')) + ->setValue($object->getFilePHID()), ); } } diff --git a/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php b/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php index 35091cd585..fb0c56f1c1 100644 --- a/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php +++ b/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php @@ -1,96 +1,104 @@ getFilePHID(); } public function applyInternalEffects($object, $value) { $object->setFilePHID($value); } public function applyExternalEffects($object, $value) { $old = $this->generateOldValue($object); $new = $value; $all = array(); if ($old) { $all[] = $old; } if ($new) { $all[] = $new; } $files = id(new PhabricatorFileQuery()) ->setViewer($this->getActor()) ->withPHIDs($all) ->execute(); $files = mpull($files, null, 'getPHID'); $old_file = idx($files, $old); if ($old_file) { $old_file->detachFromObject($object->getPHID()); } $new_file = idx($files, $new); if ($new_file) { $new_file->attachToObject($object->getPHID()); } } public function getTitle() { return pht( '%s changed the image for this macro.', $this->renderAuthor()); } public function getTitleForFeed() { return pht( - '%s changed the image for macro %s.', + '%s changed the image for %s.', $this->renderAuthor(), $this->renderObject()); } public function validateTransactions($object, array $xactions) { $errors = array(); $viewer = $this->getActor(); + $old_phid = $object->getFilePHID(); + foreach ($xactions as $xaction) { $file_phid = $xaction->getNewValue(); - if ($this->isEmptyTextTransaction($file_phid, $xactions)) { - $errors[] = $this->newRequiredError( - pht('Image macros must have a file.')); + if (!$old_phid) { + if ($this->isEmptyTextTransaction($file_phid, $xactions)) { + $errors[] = $this->newRequiredError( + pht('Image macros must have a file.')); + return $errors; + } } - $file = id(new PhabricatorFileQuery()) - ->setViewer($viewer) - ->withPHIDs(array($file_phid)) - ->executeOne(); - - if (!$file) { - $errors[] = $this->newInvalidError( - pht('"%s" is not a valid file PHID.', - $file_phid)); - } else { - if (!$file->isViewableInBrowser()) { - $mime_type = $file->getMimeType(); + // Only validate if file was uploaded + if ($file_phid) { + $file = id(new PhabricatorFileQuery()) + ->setViewer($viewer) + ->withPHIDs(array($file_phid)) + ->executeOne(); + + if (!$file) { $errors[] = $this->newInvalidError( - pht('File mime type of "%s" is not a valid viewable image.', - $mime_type)); + pht('"%s" is not a valid file PHID.', + $file_phid)); + } else { + if (!$file->isViewableImage()) { + $mime_type = $file->getMimeType(); + $errors[] = $this->newInvalidError( + pht('File mime type of "%s" is not a valid viewable image.', + $mime_type)); + } } } } return $errors; } public function getIcon() { return 'fa-file-image-o'; } } diff --git a/src/applications/macro/xaction/PhabricatorMacroNameTransaction.php b/src/applications/macro/xaction/PhabricatorMacroNameTransaction.php index 5b7b6f4417..68710605aa 100644 --- a/src/applications/macro/xaction/PhabricatorMacroNameTransaction.php +++ b/src/applications/macro/xaction/PhabricatorMacroNameTransaction.php @@ -1,80 +1,81 @@ getName(); } public function applyInternalEffects($object, $value) { $object->setName($value); } public function getTitle() { return pht( '%s renamed this macro from %s to %s.', $this->renderAuthor(), $this->renderOldValue(), $this->renderNewValue()); } public function getTitleForFeed() { return pht( - '%s renamed %s macro %s to %s.', + '%s renamed %s from %s to %s.', $this->renderAuthor(), $this->renderObject(), $this->renderOldValue(), $this->renderNewValue()); } public function validateTransactions($object, array $xactions) { $errors = array(); $viewer = $this->getActor(); if ($this->isEmptyTextTransaction($object->getName(), $xactions)) { $errors[] = $this->newRequiredError( pht('Macros must have a name.')); + return $errors; } $max_length = $object->getColumnMaximumByteLength('name'); foreach ($xactions as $xaction) { $old_value = $this->generateOldValue($object); $new_value = $xaction->getNewValue(); $new_length = strlen($new_value); if ($new_length > $max_length) { $errors[] = $this->newInvalidError( pht('The name can be no longer than %s characters.', new PhutilNumber($max_length))); } if (!preg_match('/^[a-z0-9:_-]{3,}\z/', $new_value)) { $errors[] = $this->newInvalidError( pht('Macro name "%s" be at least three characters long and contain '. 'only lowercase letters, digits, hyphens, colons and '. 'underscores.', $new_value)); } // Check name is unique when updating / creating if ($old_value != $new_value) { $macro = id(new PhabricatorMacroQuery()) ->setViewer($viewer) ->withNames(array($new_value)) ->executeOne(); if ($macro) { $errors[] = $this->newInvalidError( pht('Macro "%s" already exists.', $new_value)); } } } return $errors; } } diff --git a/src/applications/subscriptions/engineextension/PhabricatorSubscriptionsEditEngineExtension.php b/src/applications/subscriptions/engineextension/PhabricatorSubscriptionsEditEngineExtension.php index ac0d3896cc..c37933a938 100644 --- a/src/applications/subscriptions/engineextension/PhabricatorSubscriptionsEditEngineExtension.php +++ b/src/applications/subscriptions/engineextension/PhabricatorSubscriptionsEditEngineExtension.php @@ -1,74 +1,75 @@ getPHID(); if ($object_phid) { $sub_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID( $object_phid); } else { $sub_phids = array(); } $subscribers_field = id(new PhabricatorSubscribersEditField()) - ->setKey('subscriberPHIDs') + ->setKey(self::FIELDKEY) ->setLabel(pht('Subscribers')) ->setEditTypeKey('subscribers') ->setAliases(array('subscriber', 'subscribers')) ->setIsCopyable(true) ->setUseEdgeTransactions(true) ->setCommentActionLabel(pht('Change Subscribers')) ->setCommentActionOrder(9000) ->setDescription(pht('Choose subscribers.')) ->setTransactionType($subscribers_type) ->setValue($sub_phids); $subscribers_field->setViewer($engine->getViewer()); $edit_add = $subscribers_field->getConduitEditType(self::EDITKEY_ADD) ->setConduitDescription(pht('Add subscribers.')); $edit_set = $subscribers_field->getConduitEditType(self::EDITKEY_SET) ->setConduitDescription( pht('Set subscribers, overwriting current value.')); $edit_rem = $subscribers_field->getConduitEditType(self::EDITKEY_REMOVE) ->setConduitDescription(pht('Remove subscribers.')); return array( $subscribers_field, ); } }