Make the group selectable

This commit is contained in:
Joas Schilling 2016-05-09 09:43:06 +02:00
parent d2553a4f6e
commit c34788918d
No known key found for this signature in database
GPG key ID: 70A0B324C41C0946
4 changed files with 37 additions and 2 deletions

View file

@ -39,8 +39,16 @@ $(document).ready(function(){
});
});
});
$('#release-channel').change(function() {
var newChannel = $('#release-channel').find(":selected").val();
if (newChannel === 'git' || newChannel === 'daily') {
$('#oca_updatenotification_groups').addClass('hidden');
} else {
$('#oca_updatenotification_groups').removeClass('hidden');
}
$.post(
OC.generateUrl('/apps/updatenotification/channel'),
{
@ -51,4 +59,12 @@ $(document).ready(function(){
}
);
});
var $notificationTargetGroups = $('#oca_updatenotification_groups_list');
OC.Settings.setupGroupsSelect($notificationTargetGroups);
$notificationTargetGroups.change(function(ev) {
var groups = ev.val || [];
groups = JSON.stringify(groups);
OC.AppConfig.setValue('updatenotification', 'notify_groups', groups);
});
});

View file

@ -100,12 +100,17 @@ class AdminController extends Controller {
unset($channels[$key]);
}
$updateState = $this->updateChecker->getUpdateState();
$notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'));
$params = [
'isNewVersionAvailable' => ($updateState === []) ? false : true,
'lastChecked' => $lastUpdateCheck,
'currentChannel' => $currentChannel,
'channels' => $channels,
'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'],
'notify_groups' => implode('|', $notifyGroups),
];
return new TemplateResponse($this->appName, 'admin', $params, '');

View file

@ -28,6 +28,7 @@ use OC\Updater\VersionCheck;
use OCP\App\IAppManager;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\Notification\IManager;
@ -149,8 +150,14 @@ class BackgroundJob extends TimedJob {
return $this->users;
}
$groupToNotify = $this->groupManager->get('admin');
$this->users = $groupToNotify->getUsers();
$notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'));
foreach ($notifyGroups as $group) {
$groupToNotify = $this->groupManager->get($group);
if ($groupToNotify instanceof IGroup) {
$this->users = array_merge($this->users, $groupToNotify->getUsers());
}
}
return $this->users;
}

View file

@ -39,4 +39,11 @@
<p>
<em><?php p($l->t('You can always update to a newer version / experimental channel. But you can never downgrade to a more stable channel.')); ?></em>
</p>
<p id="oca_updatenotification_groups" class="<?php if (in_array($currentChannel, ['daily', 'git'])) p('hidden'); ?>">
<br />
<?php p($l->t('Notify members of the following groups about available updates:')); ?>
<input name="oca_updatenotification_groups_list" type="hidden" id="oca_updatenotification_groups_list" value="<?php p($_['notify_groups']) ?>" style="width: 400px">
</p>
</form>