diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index 96541385..9750a512 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -18,6 +18,10 @@ This version hasn't been released yet ### Icinga Configuration * FIX: render Set Services to individual zones where required (#1589, #2356) +### Configuration Branches +* FEATURE: with this release, directorbranches v1.3 supports a "default branch" (#2688) +* FEATURE: users with default branches get warnings in the main branch (#2689) + ### Health Check * FIX: complaint about overdue jobs was not correct (#2680, #2681) diff --git a/library/Director/Dashboard/BranchesDashboard.php b/library/Director/Dashboard/BranchesDashboard.php index fe8b385c..1ba254a7 100644 --- a/library/Director/Dashboard/BranchesDashboard.php +++ b/library/Director/Dashboard/BranchesDashboard.php @@ -6,6 +6,7 @@ use gipfl\Web\Widget\Hint; use Icinga\Application\Hook; use Icinga\Module\Director\Db\Branch\Branch; use Icinga\Module\Director\Db\Branch\BranchStore; +use Icinga\Module\Director\Db\Branch\PreferredBranchSupport; use Icinga\Module\Director\Hook\BranchSupportHook; use ipl\Html\Html; @@ -19,6 +20,12 @@ class BranchesDashboard extends Dashboard $this->translate('You\'re currently working in a Configuration Branch: %s'), Branch::requireHook()->linkToBranch($branch, $this->getAuth(), $branch->getName()) ))); + } else { + if (($implementation = Branch::optionalHook()) && $implementation instanceof PreferredBranchSupport) { + $this->prepend(Hint::warning( + $this->translate('You\'re currently working in the main Configuration Branch'), + )); + } } return $this->translate('Prepare your configuration in a safe Environment'); diff --git a/library/Director/Db/Branch/PreferredBranchSupport.php b/library/Director/Db/Branch/PreferredBranchSupport.php new file mode 100644 index 00000000..3463bfef --- /dev/null +++ b/library/Director/Db/Branch/PreferredBranchSupport.php @@ -0,0 +1,10 @@ +hasPreferredBranch === null) { + $implementation = Branch::optionalHook(); + if ($implementation instanceof PreferredBranchSupport) { + $this->hasPreferredBranch = $implementation->hasPreferredBranch($this->Auth()); + } else { + $this->hasPreferredBranch = false; + } + } + + return $this->hasPreferredBranch; + } } diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index 0c06937d..7302b5aa 100644 --- a/library/Director/Web/Controller/ObjectController.php +++ b/library/Director/Web/Controller/ObjectController.php @@ -10,6 +10,7 @@ use Icinga\Exception\ProgrammingError; use Icinga\Module\Director\Data\Db\DbObjectTypeRegistry; use Icinga\Module\Director\Db\Branch\Branch; use Icinga\Module\Director\Db\Branch\BranchedObject; +use Icinga\Module\Director\Db\Branch\BranchSupport; use Icinga\Module\Director\Db\Branch\UuidLookup; use Icinga\Module\Director\Deployment\DeploymentInfo; use Icinga\Module\Director\DirectorObject\Automation\ExportInterface; @@ -151,8 +152,11 @@ abstract class ObjectController extends ActionController $this->addObject(); } $branch = $this->getBranch(); - if ($branch->isBranch() && ! $this->getRequest()->isApiRequest()) { - $this->content()->add(new BranchedObjectHint($branch, $this->Auth())); + if (! $this->getRequest()->isApiRequest()) { + $hasPreferred = $this->hasPreferredBranch(); + if ($branch->isBranch() || $hasPreferred) { + $this->content()->add(new BranchedObjectHint($branch, $this->Auth(), null, $hasPreferred)); + } } $form->handleRequest(); @@ -558,8 +562,16 @@ abstract class ObjectController extends ActionController if (! $this->allowsObject($object)) { throw new NotFoundError('No such object available'); } - if ($showHint && $branch->isBranch() && $object->isObject() && ! $this->getRequest()->isApiRequest()) { - $this->content()->add(new BranchedObjectHint($branch, $this->Auth(), $branchedObject)); + if ($showHint) { + $hasPreferredBranch = $this->hasPreferredBranch(); + if (($hasPreferredBranch || $branch->isBranch()) + && $object->isObject() + && ! $this->getRequest()->isApiRequest() + ) { + $this->content()->add( + new BranchedObjectHint($branch, $this->Auth(), $branchedObject, $hasPreferredBranch) + ); + } } return $object; diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php index 8c10b442..32f9f43b 100644 --- a/library/Director/Web/Controller/ObjectsController.php +++ b/library/Director/Web/Controller/ObjectsController.php @@ -124,7 +124,7 @@ abstract class ObjectsController extends ActionController ->addTitle($this->translate(ucfirst($this->getPluralType()))) ->actions(new ObjectsActionBar($this->getBaseObjectUrl(), $this->url())); - $this->content()->add(new BranchedObjectsHint($this->getBranch(), $this->Auth())); + $this->content()->add(new BranchedObjectsHint($this->getBranch(), $this->Auth(), $this->hasPreferredBranch())); if ($type === 'command' && $this->params->get('type') === 'external_object') { $this->tabs()->activate('external'); diff --git a/library/Director/Web/Widget/BranchedObjectHint.php b/library/Director/Web/Widget/BranchedObjectHint.php index ec160940..c50f9232 100644 --- a/library/Director/Web/Widget/BranchedObjectHint.php +++ b/library/Director/Web/Widget/BranchedObjectHint.php @@ -15,33 +15,45 @@ class BranchedObjectHint extends HtmlDocument { use TranslationHelper; - public function __construct(Branch $branch, Auth $auth, BranchedObject $object = null) + public function __construct(Branch $branch, Auth $auth, BranchedObject $object = null, $hasPreferredBranch = false) { if (! $branch->isBranch()) { - return; - } - $hook = Branch::requireHook(); - - $name = $branch->getName(); - if (substr($name, 0, 1) === '/') { - $label = $this->translate('this configuration branch'); + if ($hasPreferredBranch) { + $main = true; + $hintMethod = 'warning'; + $link = $this->translate('the main configuration branch'); + $deployHint = ' ' . $this->translate('This will be part of the next deployment'); + } else { + return; + } } else { - $label = $name; + $main = false; + $hintMethod = 'info'; + $deployHint = ' ' . $this->translate('This will not be part of any deployment, unless being merged'); + $hook = Branch::requireHook(); + $name = $branch->getName(); + if (substr($name, 0, 1) === '/') { + $label = $this->translate('this configuration branch'); + } else { + $label = $name; + } + $link = $hook->linkToBranch($branch, $auth, $label); } - $link = $hook->linkToBranch($branch, $auth, $label); + if ($object === null) { - $this->add(Hint::info(Html::sprintf($this->translate( - 'This object will be created in %s. It will not be part of any deployment' - . ' unless being merged' - ), $link))); + $this->add(Hint::$hintMethod(Html::sprintf($this->translate( + 'This object will be created in %s.' + ) . $deployHint, $link))); return; } if (! $object->hasBeenTouchedByBranch()) { - $this->add(Hint::info(Html::sprintf($this->translate( - 'Your changes will be stored in %s. The\'ll not be part of any deployment' - . ' unless being merged' - ), $link))); + $this->add(Hint::$hintMethod(Html::sprintf($this->translate( + 'Your changes are going to be stored in %s.' + ) . $deployHint, $link))); + return; + } + if ($main) { return; } diff --git a/library/Director/Web/Widget/BranchedObjectsHint.php b/library/Director/Web/Widget/BranchedObjectsHint.php index d689178b..3f00f9ea 100644 --- a/library/Director/Web/Widget/BranchedObjectsHint.php +++ b/library/Director/Web/Widget/BranchedObjectsHint.php @@ -13,9 +13,14 @@ class BranchedObjectsHint extends HtmlDocument { use TranslationHelper; - public function __construct(Branch $branch, Auth $auth) + public function __construct(Branch $branch, Auth $auth, $hasPreferredBranch = false) { if (! $branch->isBranch()) { + if ($hasPreferredBranch) { + $this->add(Hint::warning($this->translate( + "You're currently in the master branch, your changes will make part of the next Deployment" + ))); + } return; } $hook = Branch::requireHook();