Allow configuration options to be locked

Summary: Some config shouldn't reasonably be edited from the web interface because it immediately torpedoes the install if you make a mistake. Block edits to "locked" config.

Test Plan: Tried to edit locked config, got denied. Viewed locked config on edit and list screens.

Reviewers: codeblock, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2255

Differential Revision: https://secure.phabricator.com/D4320
This commit is contained in:
epriestley
2013-01-02 14:02:43 -08:00
parent db21319b39
commit 9cef013def
4 changed files with 40 additions and 8 deletions

View File

@@ -59,7 +59,7 @@ final class PhabricatorConfigEditController
$e_value = null; $e_value = null;
$errors = array(); $errors = array();
if ($request->isFormPost()) { if ($request->isFormPost() && !$option->getLocked()) {
$result = $this->readRequest( $result = $this->readRequest(
$option, $option,
@@ -100,6 +100,15 @@ final class PhabricatorConfigEditController
$error_view = id(new AphrontErrorView()) $error_view = id(new AphrontErrorView())
->setTitle(pht('You broke everything!')) ->setTitle(pht('You broke everything!'))
->setErrors($errors); ->setErrors($errors);
} else if ($option->getLocked()) {
$msg = pht(
"This configuration is locked and can not be edited from the web ".
"interface.");
$error_view = id(new AphrontErrorView())
->setTitle(pht('Configuration Locked'))
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
->appendChild('<p>'.phutil_escape_html($msg).'</p>');
} }
$control = $this->renderControl( $control = $this->renderControl(
@@ -124,11 +133,15 @@ final class PhabricatorConfigEditController
id(new AphrontFormMarkupControl()) id(new AphrontFormMarkupControl())
->setLabel(pht('Description')) ->setLabel(pht('Description'))
->setValue($description)) ->setValue($description))
->appendChild($control) ->appendChild($control);
if (!$option->getLocked()) {
$form
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->addCancelButton($done_uri) ->addCancelButton($done_uri)
->setValue(pht('Save Config Entry'))); ->setValue(pht('Save Config Entry')));
}
$examples = $this->renderExamples($option); $examples = $this->renderExamples($option);
if ($examples) { if ($examples) {
@@ -329,6 +342,10 @@ final class PhabricatorConfigEditController
->setValue($display_value) ->setValue($display_value)
->setName('value'); ->setName('value');
if ($option->getLocked()) {
$control->setDisabled(true);
}
return $control; return $control;
} }

View File

@@ -91,6 +91,10 @@ final class PhabricatorConfigGroupController
$item->addIcon('edit-grey', pht('Default')); $item->addIcon('edit-grey', pht('Default'));
} }
if ($option->getLocked()) {
$item->addIcon('lock', pht('Locked'));
}
$list->addItem($item); $list->addItem($item);
} }

View File

@@ -12,6 +12,16 @@ final class PhabricatorConfigOption
private $options; private $options;
private $group; private $group;
private $examples; private $examples;
private $locked;
public function setLocked($locked) {
$this->locked = $locked;
return $this;
}
public function getLocked() {
return $this->locked;
}
public function addExample($value, $description) { public function addExample($value, $description) {
$this->examples[] = array($value, $description); $this->examples[] = array($value, $description);

View File

@@ -66,6 +66,8 @@ final class PhabricatorCoreConfigOptions
"traditional UI strings like 'Submit', you can set this flag to ". "traditional UI strings like 'Submit', you can set this flag to ".
"disable most of the jokes and easter eggs.")), "disable most of the jokes and easter eggs.")),
$this->newOption('storage.default-namespace', 'string', 'phabricator') $this->newOption('storage.default-namespace', 'string', 'phabricator')
// NOTE: Lock this, since editing it from the web torpedoes an install.
->setLocked(true)
->setSummary( ->setSummary(
pht("The namespace that Phabricator databases should use.")) pht("The namespace that Phabricator databases should use."))
->setDescription( ->setDescription(
@@ -75,8 +77,7 @@ final class PhabricatorCoreConfigOptions
"named 'phabricator_differential' by default. You can change ". "named 'phabricator_differential' by default. You can change ".
"this namespace if you want. Normally, you should not do this ". "this namespace if you want. Normally, you should not do this ".
"unless you are developing Phabricator and using namespaces to ". "unless you are developing Phabricator and using namespaces to ".
"separate multiple sandbox datasets.")) "separate multiple sandbox datasets.")),
->addExample('phabricator', 'Valid Setting'),
$this->newOption('environment.append-paths', 'list<string>', null) $this->newOption('environment.append-paths', 'list<string>', null)
->setSummary( ->setSummary(
pht("These paths get appended to your \$PATH envrionment variable.")) pht("These paths get appended to your \$PATH envrionment variable."))