Skip to content

Commit a28c52d

Browse files
committed
contact-groups: Prevent new groups without a channel
Without channels, most of the configuration is not possible. Technically, channels are not required for groups, but we want to guide new users to the channel configuration because of its importance. Once there is a channel, groups can be created but we still hint that there are no contacts yet.
1 parent 8c842ac commit a28c52d

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

application/controllers/ContactGroupsController.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Icinga\Module\Notifications\Common\Database;
88
use Icinga\Module\Notifications\Common\Links;
99
use Icinga\Module\Notifications\Forms\ContactGroupForm;
10+
use Icinga\Module\Notifications\Model\Channel;
1011
use Icinga\Module\Notifications\Model\Contact;
1112
use Icinga\Module\Notifications\Model\Contactgroup;
1213
use Icinga\Module\Notifications\View\ContactgroupRenderer;
@@ -15,6 +16,7 @@
1516
use Icinga\Module\Notifications\Widget\MemberSuggestions;
1617
use Icinga\Web\Notification;
1718
use ipl\Html\Form;
19+
use ipl\Html\HtmlString;
1820
use ipl\Html\TemplateString;
1921
use ipl\Stdlib\Filter;
2022
use ipl\Web\Compat\CompatController;
@@ -90,15 +92,27 @@ public function indexAction(): void
9092

9193
$emptyStateMessage = null;
9294
if (Contact::on(Database::get())->columns('1')->limit(1)->first() === null) {
93-
$addButton->disable($this->translate('A contact is required to add a contact group'));
94-
95-
$emptyStateMessage = TemplateString::create(
96-
$this->translate(
97-
'No contact groups found. To add a new contact group,'
98-
. ' please {{#link}}add a contact{{/link}} first.'
99-
),
100-
['link' => (new ActionLink(null, Links::contactAdd()))->setBaseTarget('_next')]
101-
);
95+
if (Channel::on(Database::get())->columns('1')->limit(1)->first() === null) {
96+
$addButton->disable($this->translate('A channel is required to add a contact group'));
97+
98+
$emptyStateMessage = TemplateString::create(
99+
// translators: %1$s will be replaced by a line break
100+
'No contact groups found.%1$sTo add new contact group, please {{#link}}configure a Channel{{/link}}'
101+
. ' first.%1$sOnce done, you should proceed by creating your first contact.',
102+
['link' => (new ActionLink(null, Links::channelAdd()))->setBaseTarget('_next')],
103+
[HtmlString::create('<br>')]
104+
);
105+
} else {
106+
$emptyStateMessage = TemplateString::create(
107+
$this->translate(
108+
'No contact groups found. Do not forget to also'
109+
. ' {{#link}}create your first contact!{{/link}}'
110+
),
111+
['link' => (new ActionLink(null, Links::contactAdd()))->setBaseTarget('_next')]
112+
);
113+
114+
$addButton->openInModal();
115+
}
102116
} else {
103117
$addButton->openInModal();
104118
}

0 commit comments

Comments
 (0)