1010
1111namespace Joomla \Component \Joomlaupdate \Administrator \Model ;
1212
13+ use Joomla \CMS \Access \Access ;
1314use Joomla \CMS \Component \ComponentHelper ;
1415use Joomla \CMS \Factory ;
1516use Joomla \CMS \Mail \MailHelper ;
1617use Joomla \CMS \Mail \MailTemplate ;
1718use Joomla \CMS \MVC \Model \BaseDatabaseModel ;
1819use Joomla \CMS \Uri \Uri ;
20+ use Joomla \CMS \Helper \UserGroupsHelper ;
1921use Joomla \CMS \Version ;
2022use Joomla \Registry \Registry ;
2123use Joomla \Utilities \ArrayHelper ;
@@ -43,22 +45,25 @@ final class NotificationModel extends BaseDatabaseModel
4345 * @since 5.4.0
4446 */
4547 public function sendNotification ($ type , $ oldVersion ): void
46- {
48+ {
4749 $ params = ComponentHelper::getParams ('com_joomlaupdate ' );
4850
49- // User groups to notify. Default is superuser group.
50- $ emailGroups = $ params ->get ('automated_updates_email_groups ' , 8 , ' array ' );
51+ // User groups from input field
52+ $ emailGroups = $ params ->get ('automated_updates_email_groups ' );
5153
52- // If the emailGroups is not an array, convert it to an array
5354 if (!\is_array ($ emailGroups )) {
5455 $ emailGroups = ArrayHelper::toInteger (explode (', ' , $ emailGroups ));
5556 }
5657
58+ // Add Super User Groups
59+ $ emailGroups = array_merge ($ emailGroups , $ this ->getSuperUserGroups ());
60+
5761 // Get all users in these groups who can receive emails
5862 $ emailReceivers = $ this ->getEmailReceivers ($ emailGroups );
5963
6064 // If no email receivers are found, we do not send any notification
6165 if (empty ($ emailReceivers )) {
66+ // Should not happen, as at least one super user must exist in the system
6267 return ;
6368 }
6469
@@ -74,7 +79,7 @@ public function sendNotification($type, $oldVersion): void
7479 'url ' => Uri::root (),
7580 ];
7681
77- // Send the emails to the Super Users
82+ // Send emails to all receivers
7883 foreach ($ emailReceivers as $ receiver ) {
7984 $ params = new Registry ($ receiver ->params );
8085 $ jLanguage ->load ('com_joomlaupdate ' , JPATH_ADMINISTRATOR , 'en-GB ' , true , true );
@@ -140,4 +145,26 @@ private function getEmailReceivers($emailGroups): array
140145
141146 return $ emailReceivers ;
142147 }
143- }
148+
149+ /**
150+ * Returns all Super Users
151+ *
152+ * @return array The list of super user groups.
153+ *
154+ * @since 5.4.0
155+ */
156+ private function getSuperUserGroups (): array
157+ {
158+ $ groups = UserGroupsHelper::getInstance ()->getAll ();
159+ $ ret = [];
160+
161+ // Find groups with core.admin rights (super users)
162+ foreach ($ groups as $ group ) {
163+ if (Access::checkGroup ($ group ->id , 'core.admin ' )) {
164+ $ ret [] = $ group ->id ;
165+ }
166+ }
167+
168+ return $ ret ;
169+ }
170+ }
0 commit comments