1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

Allow users to unset "Editor", tailor short error messages properly on settings forms

Summary:
Ref T11098.

  - Allow "Editor" to be set to the empty string.
  - Don't match a validation error to a field unless the actual settings for the field and error match.

Test Plan:
  - Tried to set "Editor" to "", success.
  - Tried to set "Editor" to "javascript://", only that field got marked "Invalid".

Reviewers: avivey, chad

Reviewed By: chad

Maniphest Tasks: T11098

Differential Revision: https://secure.phabricator.com/D16051
This commit is contained in:
epriestley 2016-06-05 13:52:52 -07:00
parent 4936be0868
commit b4a07d528f
4 changed files with 57 additions and 7 deletions

View file

@ -194,4 +194,43 @@ final class PhabricatorSettingsEditEngine
return $fields;
}
protected function getValidationExceptionShortMessage(
PhabricatorApplicationTransactionValidationException $ex,
PhabricatorEditField $field) {
// Settings fields all have the same transaction type so we need to make
// sure the transaction is changing the same setting before matching an
// error to a given field.
$xaction_type = $field->getTransactionType();
if ($xaction_type == PhabricatorUserPreferencesTransaction::TYPE_SETTING) {
$property = PhabricatorUserPreferencesTransaction::PROPERTY_SETTING;
$field_setting = idx($field->getMetadata(), $property);
foreach ($ex->getErrors() as $error) {
if ($error->getType() !== $xaction_type) {
continue;
}
$xaction = $error->getTransaction();
if (!$xaction) {
continue;
}
$xaction_setting = $xaction->getMetadataValue($property);
if ($xaction_setting != $field_setting) {
continue;
}
$short_message = $error->getShortMessage();
if ($short_message !== null) {
return $short_message;
}
}
return null;
}
return parent::getValidationExceptionShortMessage($ex, $field);
}
}

View file

@ -39,6 +39,10 @@ final class PhabricatorEditorSetting
}
public function validateTransactionValue($value) {
if (!strlen($value)) {
return;
}
$ok = PhabricatorHelpEditorProtocolController::hasAllowedProtocol($value);
if ($ok) {
return;

View file

@ -1004,12 +1004,7 @@ abstract class PhabricatorEditEngine
$validation_exception = $ex;
foreach ($fields as $field) {
$xaction_type = $field->getTransactionType();
if ($xaction_type === null) {
continue;
}
$message = $ex->getShortMessage($xaction_type);
$message = $this->getValidationExceptionShortMessage($ex, $field);
if ($message === null) {
continue;
}
@ -2049,6 +2044,18 @@ abstract class PhabricatorEditEngine
->setHref($item_uri);
}
protected function getValidationExceptionShortMessage(
PhabricatorApplicationTransactionValidationException $ex,
PhabricatorEditField $field) {
$xaction_type = $field->getTransactionType();
if ($xaction_type === null) {
return null;
}
return $ex->getShortMessage($xaction_type);
}
protected function getCreateNewObjectPolicy() {
return PhabricatorPolicies::POLICY_USER;
}

View file

@ -26,7 +26,7 @@ final class PhabricatorApplicationTransactionValidationError
}
public function getTransaction() {
return $this->tranaction;
return $this->transaction;
}
public function getShortMessage() {