Skip to content

Commit 26c56bb

Browse files
authoredNov 16, 2022
Merge pull request #1266 from natoponen/master
Add admin setting page with users defaults
2 parents e515cfd + cff4eaf commit 26c56bb

17 files changed

+567
-2
lines changed
 

‎appinfo/info.xml

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
</commands>
4747

4848
<settings>
49+
<admin>OCA\Notifications\Settings\Admin</admin>
50+
<admin-section>OCA\Notifications\Settings\AdminSection</admin-section>
4951
<personal>OCA\Notifications\Settings\Personal</personal>
5052
<personal-section>OCA\Notifications\Settings\PersonalSection</personal-section>
5153
</settings>

‎appinfo/routes.php

+1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@
3434
['name' => 'API#generateNotification', 'url' => '/api/{apiVersion}/admin_notifications/{userId}', 'verb' => 'POST', 'requirements' => ['apiVersion' => 'v(1|2)']],
3535

3636
['name' => 'Settings#personal', 'url' => '/api/{apiVersion}/settings', 'verb' => 'POST', 'requirements' => ['apiVersion' => 'v2']],
37+
['name' => 'Settings#admin', 'url' => '/api/{apiVersion}/settings/admin', 'verb' => 'POST', 'requirements' => ['apiVersion' => 'v2']],
3738
],
3839
];

‎js/notifications-admin-settings.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*!
2+
* The buffer module from node.js, for the browser.
3+
*
4+
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
5+
* @license MIT
6+
*/
7+
8+
/*!
9+
* The buffer module from node.js, for the browser.
10+
*
11+
* @author Feross Aboukhadijeh <https://feross.org>
12+
* @license MIT
13+
*/
14+
15+
/*!
16+
* Vue.js v2.7.10
17+
* (c) 2014-2022 Evan You
18+
* Released under the MIT License.
19+
*/
20+
21+
/*! For license information please see NcCheckboxRadioSwitch.js.LICENSE.txt */
22+
23+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
24+
25+
/**
26+
* @copyright Copyright (c) 2022 Nikita Toponen <natoponen@gmail.com>
27+
*
28+
* @license AGPL-3.0-or-later
29+
*
30+
* This program is free software: you can redistribute it and/or modify
31+
* it under the terms of the GNU Affero General Public License as
32+
* published by the Free Software Foundation, either version 3 of the
33+
* License, or (at your option) any later version.
34+
*
35+
* This program is distributed in the hope that it will be useful,
36+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
37+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38+
* GNU Affero General Public License for more details.
39+
*
40+
* You should have received a copy of the GNU Affero General Public License
41+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
42+
*
43+
*/

‎js/notifications-admin-settings.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎js/notifications-settings.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/AppInfo/Application.php

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use OCA\Notifications\App;
2828
use OCA\Notifications\Capabilities;
2929
use OCA\Notifications\Listener\BeforeTemplateRenderedListener;
30+
use OCA\Notifications\Listener\PostLoginListener;
31+
use OCA\Notifications\Listener\UserCreatedListener;
3032
use OCA\Notifications\Listener\UserDeletedListener;
3133
use OCA\Notifications\Notifier\AdminNotifications;
3234
use OCP\AppFramework\Bootstrap\IBootContext;
@@ -36,6 +38,8 @@
3638
use OCP\AppFramework\IAppContainer;
3739
use OCP\Notification\IManager;
3840
use OCP\User\Events\UserDeletedEvent;
41+
use OCP\User\Events\UserCreatedEvent;
42+
use OCP\User\Events\PostLoginEvent;
3943

4044
class Application extends \OCP\AppFramework\App implements IBootstrap {
4145
public const APP_ID = 'notifications';
@@ -55,6 +59,8 @@ public function register(IRegistrationContext $context): void {
5559

5660
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
5761
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
62+
$context->registerEventListener(UserCreatedEvent::class, UserCreatedListener::class);
63+
$context->registerEventListener(PostLoginEvent::class, PostLoginListener::class);
5864
}
5965

6066
public function boot(IBootContext $context): void {

‎lib/Controller/SettingsController.php

+11
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,15 @@ public function personal(int $batchSetting, string $soundNotification, string $s
5858

5959
return new DataResponse();
6060
}
61+
62+
/**
63+
* @AuthorizedAdminSetting(settings=OCA\Notifications\Settings\Admin)
64+
*/
65+
public function admin(int $batchSetting, string $soundNotification, string $soundTalk): DataResponse {
66+
$this->config->setAppValue(Application::APP_ID, 'setting_batchtime', $batchSetting);
67+
$this->config->setAppValue(Application::APP_ID, 'sound_notification', $soundNotification !== 'no' ? 'yes' : 'no');
68+
$this->config->setAppValue(Application::APP_ID, 'sound_talk', $soundTalk !== 'no' ? 'yes' : 'no');
69+
70+
return new DataResponse();
71+
}
6172
}

‎lib/Listener/PostLoginListener.php

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2022 Nikita Toponen <natoponen@gmail.com>
7+
*
8+
* @author Nikita Toponen <natoponen@gmail.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\Notifications\Listener;
28+
29+
use OCA\Notifications\AppInfo\Application;
30+
use OCA\Notifications\Model\Settings;
31+
use OCA\Notifications\Model\SettingsMapper;
32+
use OCP\AppFramework\Db\DoesNotExistException;
33+
use OCP\User\Events\PostLoginEvent;
34+
use OCP\EventDispatcher\IEventListener;
35+
use OCP\EventDispatcher\Event;
36+
use OCP\IUserManager;
37+
use OCP\IConfig;
38+
39+
class PostLoginListener implements IEventListener {
40+
private IUserManager $userManager;
41+
private SettingsMapper $settingsMapper;
42+
private IConfig $config;
43+
44+
public function __construct(IUserManager $userManager, SettingsMapper $settingsMapper, IConfig $config) {
45+
$this->userManager = $userManager;
46+
$this->settingsMapper = $settingsMapper;
47+
$this->config = $config;
48+
}
49+
50+
public function handle(Event $event): void {
51+
if (!($event instanceof PostLoginEvent)) {
52+
// Unrelated
53+
return;
54+
}
55+
56+
$userId = $event->getUser()->getUID();
57+
58+
try {
59+
$this->settingsMapper->getSettingsByUser($userId);
60+
} catch (DoesNotExistException $e) {
61+
$defaultSoundNotification = $this->config->getAppValue(Application::APP_ID, 'sound_notification') === 'yes' ? 'yes' : 'no';
62+
$defaultSoundTalk = $this->config->getAppValue(Application::APP_ID, 'sound_talk') === 'yes' ? 'yes' : 'no';
63+
$defaultBatchtime = $this->config->getAppValue(Application::APP_ID, 'setting_batchtime');
64+
65+
if ($defaultBatchtime !== Settings::EMAIL_SEND_WEEKLY
66+
&& $defaultBatchtime !== Settings::EMAIL_SEND_DAILY
67+
&& $defaultBatchtime !== Settings::EMAIL_SEND_3HOURLY
68+
&& $defaultBatchtime !== Settings::EMAIL_SEND_HOURLY
69+
&& $defaultBatchtime !== Settings::EMAIL_SEND_OFF) {
70+
$defaultBatchtime = Settings::EMAIL_SEND_3HOURLY;
71+
}
72+
73+
$this->config->setUserValue($userId, Application::APP_ID, 'sound_notification', $defaultSoundNotification);
74+
$this->config->setUserValue($userId, Application::APP_ID, 'sound_talk', $defaultSoundTalk);
75+
$this->settingsMapper->setBatchSettingForUser($userId, $defaultBatchtime);
76+
}
77+
}
78+
}

‎lib/Listener/UserCreatedListener.php

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (c) 2022 Nikita Toponen <natoponen@gmail.com>
5+
*
6+
* @author Nikita Toponen <natoponen@gmail.com>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
namespace OCA\Notifications\Listener;
26+
27+
use OCA\Notifications\AppInfo\Application;
28+
use OCA\Notifications\Model\Settings;
29+
use OCA\Notifications\Model\SettingsMapper;
30+
use OCP\IUserManager;
31+
use OCP\User\Events\UserCreatedEvent;
32+
use OCP\EventDispatcher\IEventListener;
33+
use OCP\EventDispatcher\Event;
34+
use OCP\IConfig;
35+
36+
class UserCreatedListener implements IEventListener {
37+
private IUserManager $userManager;
38+
private SettingsMapper $settingsMapper;
39+
private IConfig $config;
40+
41+
42+
public function __construct(IUserManager $userManager, SettingsMapper $settingsMapper, IConfig $config) {
43+
$this->userManager = $userManager;
44+
$this->settingsMapper = $settingsMapper;
45+
$this->config = $config;
46+
}
47+
48+
public function handle(Event $event): void {
49+
if (!($event instanceof UserCreatedEvent)) {
50+
// Unrelated
51+
return;
52+
}
53+
54+
$userId = $event->getUser()->getUID();
55+
56+
$defaultSoundNotification = $this->config->getAppValue(Application::APP_ID, 'sound_notification') === 'yes' ? 'yes' : 'no';
57+
$defaultSoundTalk = $this->config->getAppValue(Application::APP_ID, 'sound_talk') === 'yes' ? 'yes' : 'no';
58+
$defaultBatchtime = $this->config->getAppValue(Application::APP_ID, 'setting_batchtime');
59+
60+
if ($defaultBatchtime !== Settings::EMAIL_SEND_WEEKLY
61+
&& $defaultBatchtime !== Settings::EMAIL_SEND_DAILY
62+
&& $defaultBatchtime !== Settings::EMAIL_SEND_3HOURLY
63+
&& $defaultBatchtime !== Settings::EMAIL_SEND_HOURLY
64+
&& $defaultBatchtime !== Settings::EMAIL_SEND_OFF) {
65+
$defaultBatchtime = Settings::EMAIL_SEND_3HOURLY;
66+
}
67+
68+
$this->config->setUserValue($userId, Application::APP_ID, 'sound_notification', $defaultSoundNotification);
69+
$this->config->setUserValue($userId, Application::APP_ID, 'sound_talk', $defaultSoundTalk);
70+
$this->settingsMapper->setBatchSettingForUser($userId, $defaultBatchtime);
71+
}
72+
}

‎lib/Settings/Admin.php

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2022 Nikita Toponen <natoponen@gmail.com>
7+
*
8+
* @author Nikita Toponen <natoponen@gmail.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\Notifications\Settings;
28+
29+
use OCA\Notifications\AppInfo\Application;
30+
use OCA\Notifications\Model\Settings;
31+
use OCA\Notifications\Model\SettingsMapper;
32+
use OCP\AppFramework\Http\TemplateResponse;
33+
use OCP\AppFramework\Services\IInitialState;
34+
use OCP\IConfig;
35+
use OCP\IL10N;
36+
use OCP\Settings\ISettings;
37+
use OCP\IUserSession;
38+
use OCP\Util;
39+
40+
class Admin implements ISettings {
41+
protected IConfig $config;
42+
protected IL10N $l10n;
43+
private SettingsMapper$settingsMapper;
44+
private IUserSession $session;
45+
private IInitialState $initialState;
46+
47+
public function __construct(IConfig $config,
48+
IL10N $l10n,
49+
IUserSession $session,
50+
SettingsMapper $settingsMapper,
51+
IInitialState $initialState) {
52+
$this->config = $config;
53+
$this->l10n = $l10n;
54+
$this->settingsMapper = $settingsMapper;
55+
$this->session = $session;
56+
$this->initialState = $initialState;
57+
}
58+
59+
public function getForm(): TemplateResponse {
60+
Util::addScript('notifications', 'notifications-admin-settings');
61+
62+
$defaultSoundNotification = $this->config->getAppValue(Application::APP_ID, 'sound_notification') === 'yes' ? 'yes' : 'no';
63+
$defaultSoundTalk = $this->config->getAppValue(Application::APP_ID, 'sound_talk') === 'yes' ? 'yes' : 'no';
64+
$defaultBatchtime = $this->config->getAppValue(Application::APP_ID, 'setting_batchtime');
65+
66+
if ($defaultBatchtime != Settings::EMAIL_SEND_WEEKLY
67+
&& $defaultBatchtime != Settings::EMAIL_SEND_DAILY
68+
&& $defaultBatchtime != Settings::EMAIL_SEND_3HOURLY
69+
&& $defaultBatchtime != Settings::EMAIL_SEND_HOURLY
70+
&& $defaultBatchtime != Settings::EMAIL_SEND_OFF) {
71+
$defaultBatchtime = Settings::EMAIL_SEND_3HOURLY;
72+
}
73+
74+
$this->initialState->provideInitialState('config', [
75+
'setting' => 'admin',
76+
'setting_batchtime' => $defaultBatchtime,
77+
'sound_notification' => $defaultSoundNotification === 'yes',
78+
'sound_talk' => $defaultSoundTalk === 'yes',
79+
]);
80+
81+
return new TemplateResponse('notifications', 'settings/admin');
82+
}
83+
84+
/**
85+
* @return string the section ID, e.g. 'sharing'
86+
*/
87+
public function getSection(): string {
88+
return 'notifications';
89+
}
90+
91+
/**
92+
* @return int whether the form should be rather on the top or bottom of
93+
* the admin section. The forms are arranged in ascending order of the
94+
* priority values. It is required to return a value between 0 and 100.
95+
*
96+
* E.g.: 70
97+
*/
98+
public function getPriority(): int {
99+
return 20;
100+
}
101+
}

‎lib/Settings/AdminSection.php

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2022 Nikita Toponen <natoponen@gmail.com>
7+
*
8+
* @author Nikita Toponen <natoponen@gmail.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\Notifications\Settings;
28+
29+
use OCP\IL10N;
30+
use OCP\IURLGenerator;
31+
use OCP\Settings\IIconSection;
32+
33+
class AdminSection implements IIconSection {
34+
private IL10N $l;
35+
private IURLGenerator $url;
36+
37+
public function __construct(IURLGenerator $url, IL10N $l) {
38+
$this->url = $url;
39+
$this->l = $l;
40+
}
41+
42+
/**
43+
* returns the relative path to an 16*16 icon describing the section.
44+
* e.g. '/core/img/places/files.svg'
45+
*
46+
* @returns string
47+
* @since 12
48+
*/
49+
public function getIcon(): string {
50+
return $this->url->imagePath('notifications', 'notifications-dark.svg');
51+
}
52+
53+
/**
54+
* returns the ID of the section. It is supposed to be a lower case string,
55+
* e.g. 'ldap'
56+
*
57+
* @returns string
58+
* @since 9.1
59+
*/
60+
public function getID(): string {
61+
return 'notifications';
62+
}
63+
64+
/**
65+
* returns the translated name as it should be displayed, e.g. 'LDAP / AD
66+
* integration'. Use the L10N service to translate it.
67+
*
68+
* @return string
69+
* @since 9.1
70+
*/
71+
public function getName(): string {
72+
return $this->l->t('Notifications');
73+
}
74+
75+
/**
76+
* @return int whether the form should be rather on the top or bottom of
77+
* the settings navigation. The sections are arranged in ascending order of
78+
* the priority values. It is required to return a value between 0 and 99.
79+
*
80+
* E.g.: 70
81+
* @since 9.1
82+
*/
83+
public function getPriority(): int {
84+
return 55;
85+
}
86+
}

‎src/adminSettings.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @copyright Copyright (c) 2022 Nikita Toponen <natoponen@gmail.com>
3+
*
4+
* @license AGPL-3.0-or-later
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
*/
20+
21+
import Vue from 'vue'
22+
import AdminSettings from './views/AdminSettings.vue'
23+
24+
Vue.prototype.t = t
25+
Vue.prototype.n = n
26+
27+
export default new Vue({
28+
el: '#notifications-admin-settings',
29+
render: h => h(AdminSettings),
30+
})

‎src/views/AdminSettings.vue

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<!--
2+
- @copyright Copyright (c) 2022 Nikita Toponen <natoponen@gmail.com>
3+
-
4+
- @license GNU AGPL version 3 or any later version
5+
-
6+
- This program is free software: you can redistribute it and/or modify
7+
- it under the terms of the GNU Affero General Public License as
8+
- published by the Free Software Foundation, either version 3 of the
9+
- License, or (at your option) any later version.
10+
-
11+
- This program is distributed in the hope that it will be useful,
12+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
- GNU Affero General Public License for more details.
15+
-
16+
- You should have received a copy of the GNU Affero General Public License
17+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
-
19+
-->
20+
21+
<template>
22+
<NcSettingsSection :title="t('notifications', 'Notifications defaults')"
23+
:description="t('notifications', 'Configure the default notification settings for new users')">
24+
<p>
25+
<label for="notify_setting_batchtime" class="notification-frequency__label">
26+
{{ t('notifications', 'Send email reminders about unhandled notifications after:') }}
27+
</label>
28+
<select id="notify_setting_batchtime"
29+
v-model="config.setting_batchtime"
30+
class="notification-frequency__select"
31+
@change="updateSettings()">
32+
<option v-for="option in batchtime_options" :key="option.value" :value="option.value">
33+
{{ option.text }}
34+
</option>
35+
</select>
36+
</p>
37+
38+
<NcCheckboxRadioSwitch :checked.sync="config.sound_notification"
39+
@update:checked="updateSettings">
40+
{{ t('notifications', 'Play sound when a new notification arrives') }}
41+
</NcCheckboxRadioSwitch>
42+
<NcCheckboxRadioSwitch :checked.sync="config.sound_talk"
43+
@update:checked="updateSettings">
44+
{{ t('notifications', 'Play sound when a call started (requires Nextcloud Talk)') }}
45+
</NcCheckboxRadioSwitch>
46+
</NcSettingsSection>
47+
</template>
48+
49+
<script>
50+
import axios from '@nextcloud/axios'
51+
import { generateOcsUrl } from '@nextcloud/router'
52+
import { loadState } from '@nextcloud/initial-state'
53+
import { showSuccess, showError } from '@nextcloud/dialogs'
54+
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
55+
import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
56+
57+
const EmailFrequency = {
58+
EMAIL_SEND_OFF: 0,
59+
EMAIL_SEND_HOURLY: 1,
60+
EMAIL_SEND_3HOURLY: 2,
61+
EMAIL_SEND_DAILY: 3,
62+
EMAIL_SEND_WEEKLY: 4,
63+
}
64+
65+
export default {
66+
name: 'AdminSettings',
67+
components: {
68+
NcCheckboxRadioSwitch,
69+
NcSettingsSection,
70+
},
71+
72+
data() {
73+
return {
74+
batchtime_options: [
75+
{ text: t('notifications', 'Never'), value: EmailFrequency.EMAIL_SEND_OFF },
76+
{ text: t('notifications', '1 hour'), value: EmailFrequency.EMAIL_SEND_HOURLY },
77+
{ text: t('notifications', '3 hours'), value: EmailFrequency.EMAIL_SEND_3HOURLY },
78+
{ text: t('notifications', '1 day'), value: EmailFrequency.EMAIL_SEND_DAILY },
79+
{ text: t('notifications', '1 week'), value: EmailFrequency.EMAIL_SEND_WEEKLY },
80+
],
81+
config: loadState('notifications', 'config'),
82+
}
83+
},
84+
85+
methods: {
86+
async updateSettings() {
87+
try {
88+
const form = new FormData()
89+
form.append('batchSetting', this.config.setting_batchtime)
90+
form.append('soundNotification', this.config.sound_notification ? 'yes' : 'no')
91+
form.append('soundTalk', this.config.sound_talk ? 'yes' : 'no')
92+
await axios.post(generateOcsUrl('apps/notifications/api/v2/settings/admin'), form)
93+
showSuccess(t('notifications', 'Your settings have been updated.'))
94+
} catch (error) {
95+
showError(t('notifications', 'An error occurred while updating your settings.'))
96+
console.error(error)
97+
}
98+
},
99+
},
100+
}
101+
102+
</script>

‎src/views/UserSettings.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
{{ t('notifications', 'Send email reminders about unhandled notifications after:') }}
2929
</label>
3030
<select id="notification_reminder_batchtime"
31-
name="notification_reminder_batchtime"
3231
v-model="config.setting_batchtime"
32+
name="notification_reminder_batchtime"
3333
class="notification-frequency__select"
3434
@change="updateSettings()">
3535
<option v-for="option in batchtime_options" :key="option.value" :value="option.value">

‎templates/settings/admin.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2022 Nikita Toponen <natoponen@gmail.com>
7+
*
8+
* @author Nikita Toponen <natoponen@gmail.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
?>
27+
28+
<div id="notifications-admin-settings"></div>

‎webpack.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ webpackConfig.module.rules = Object.values(webpackRules)
1717
webpackConfig.entry = {
1818
main: path.resolve(path.join('src', 'main.js')),
1919
settings: path.resolve(path.join('src', 'settings.js')),
20+
'admin-settings': path.resolve(path.join('src', 'adminSettings.js')),
2021
}
2122

2223
module.exports = webpackConfig

0 commit comments

Comments
 (0)
Please sign in to comment.