-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add admin setting page with users defaults
Signed-off-by: Топонен Никита <[email protected]>
- Loading branch information
Showing
15 changed files
with
427 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/*! | ||
* The buffer module from node.js, for the browser. | ||
* | ||
* @author Feross Aboukhadijeh <[email protected]> <http://feross.org> | ||
* @license MIT | ||
*/ | ||
|
||
/*! | ||
* The buffer module from node.js, for the browser. | ||
* | ||
* @author Feross Aboukhadijeh <https://feross.org> | ||
* @license MIT | ||
*/ | ||
|
||
/*! | ||
* Vue.js v2.7.4 | ||
* (c) 2014-2022 Evan You | ||
* Released under the MIT License. | ||
*/ | ||
|
||
/*! For license information please see CheckboxRadioSwitch.js.LICENSE.txt */ | ||
|
||
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace OCA\Notifications\Listener; | ||
|
||
use OCA\Notifications\AppInfo\Application; | ||
use OCA\Notifications\Model\Settings; | ||
use OCA\Notifications\Model\SettingsMapper; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\User\Events\PostLoginEvent; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\IUserManager; | ||
use OCP\IConfig; | ||
|
||
class PostLoginListener implements IEventListener { | ||
/** @var IUserManager */ | ||
private $userManager; | ||
/** @var SettingsMapper */ | ||
private $settingsMapper; | ||
/** @var IConfig */ | ||
private $config; | ||
|
||
public function __construct(IUserManager $userManager, SettingsMapper $settingsMapper, IConfig $config) { | ||
$this->userManager = $userManager; | ||
$this->settingsMapper = $settingsMapper; | ||
$this->config = $config; | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof PostLoginEvent)) { | ||
// Unrelated | ||
return; | ||
} | ||
|
||
$userId = $event->getUser()->getUID(); | ||
|
||
$default_sound_notification = $this->config->getAppValue(Application::APP_ID, 'sound_notification') === 'yes' ? 'yes' : 'no'; | ||
$default_sound_talk = $this->config->getAppValue(Application::APP_ID, 'sound_talk') === 'yes' ? 'yes' : 'no'; | ||
$default_batchtime = $this->config->getAppValue(Application::APP_ID, 'setting_batchtime'); | ||
|
||
if ($default_batchtime != Settings::EMAIL_SEND_WEEKLY | ||
&& $default_batchtime != Settings::EMAIL_SEND_DAILY | ||
&& $default_batchtime != Settings::EMAIL_SEND_3HOURLY | ||
&& $default_batchtime != Settings::EMAIL_SEND_HOURLY | ||
&& $default_batchtime != Settings::EMAIL_SEND_OFF) { | ||
$default_batchtime = Settings::EMAIL_SEND_3HOURLY; | ||
} | ||
|
||
try { | ||
$this->settingsMapper->getSettingsByUser($userId); | ||
} catch (DoesNotExistException $e) { | ||
$this->config->setUserValue($userId, Application::APP_ID, 'sound_notification', $default_sound_notification); | ||
$this->config->setUserValue($userId, Application::APP_ID, 'sound_talk', $default_sound_talk); | ||
$this->settingsMapper->setBatchSettingForUser($userId, $default_batchtime); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace OCA\Notifications\Listener; | ||
|
||
use OCA\Notifications\AppInfo\Application; | ||
use OCA\Notifications\Model\Settings; | ||
use OCA\Notifications\Model\SettingsMapper; | ||
use OCP\IUserManager; | ||
use OCP\User\Events\UserCreatedEvent; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\IConfig; | ||
|
||
class UserCreatedListener implements IEventListener { | ||
/** @var IUserManager */ | ||
private $userManager; | ||
/** @var SettingsMapper */ | ||
private $settingsMapper; | ||
/** @var IConfig */ | ||
private $config; | ||
|
||
|
||
public function __construct(IUserManager $userManager, SettingsMapper $settingsMapper, IConfig $config) { | ||
$this->userManager = $userManager; | ||
$this->settingsMapper = $settingsMapper; | ||
$this->config = $config; | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof UserCreatedEvent)) { | ||
// Unrelated | ||
return; | ||
} | ||
|
||
$userId = $event->getUser()->getUID(); | ||
|
||
$default_sound_notification = $this->config->getAppValue(Application::APP_ID, 'sound_notification') === 'yes' ? 'yes' : 'no'; | ||
$default_sound_talk = $this->config->getAppValue(Application::APP_ID, 'sound_talk') === 'yes' ? 'yes' : 'no'; | ||
$default_batchtime = $this->config->getAppValue(Application::APP_ID, 'setting_batchtime'); | ||
|
||
if ($default_batchtime != Settings::EMAIL_SEND_WEEKLY | ||
&& $default_batchtime != Settings::EMAIL_SEND_DAILY | ||
&& $default_batchtime != Settings::EMAIL_SEND_3HOURLY | ||
&& $default_batchtime != Settings::EMAIL_SEND_HOURLY | ||
&& $default_batchtime != Settings::EMAIL_SEND_OFF) { | ||
$default_batchtime = Settings::EMAIL_SEND_3HOURLY; | ||
} | ||
|
||
$this->config->setUserValue($userId, Application::APP_ID, 'sound_notification', $default_sound_notification); | ||
$this->config->setUserValue($userId, Application::APP_ID, 'sound_talk', $default_sound_talk); | ||
$this->settingsMapper->setBatchSettingForUser($userId, $default_batchtime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Notifications\Settings; | ||
|
||
use OCA\Notifications\AppInfo\Application; | ||
use OCA\Notifications\Model\Settings; | ||
use OCA\Notifications\Model\SettingsMapper; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\AppFramework\Http\TemplateResponse; | ||
use OCP\AppFramework\Services\IInitialState; | ||
use OCP\IConfig; | ||
use OCP\IL10N; | ||
use OCP\IUser; | ||
use OCP\Settings\ISettings; | ||
use OCP\IUserSession; | ||
use OCP\Util; | ||
|
||
class Admin implements ISettings | ||
{ | ||
/** @var \OCP\IConfig */ | ||
protected $config; | ||
|
||
/** @var \OCP\IL10N */ | ||
protected $l10n; | ||
|
||
/** @var SettingsMapper */ | ||
private $settingsMapper; | ||
|
||
/** @var IUserSession */ | ||
private $session; | ||
|
||
/** @var IInitialState */ | ||
private $initialState; | ||
|
||
public function __construct(IConfig $config, | ||
IL10N $l10n, | ||
IUserSession $session, | ||
SettingsMapper $settingsMapper, | ||
IInitialState $initialState) | ||
{ | ||
$this->config = $config; | ||
$this->l10n = $l10n; | ||
$this->settingsMapper = $settingsMapper; | ||
$this->session = $session; | ||
$this->initialState = $initialState; | ||
} | ||
|
||
/** | ||
* @return TemplateResponse | ||
*/ | ||
public function getForm(): TemplateResponse | ||
{ | ||
Util::addScript('notifications', 'notifications-adminSettings'); | ||
|
||
$default_sound_notification = $this->config->getAppValue(Application::APP_ID, 'sound_notification') === 'yes' ? 'yes' : 'no'; | ||
$default_sound_talk = $this->config->getAppValue(Application::APP_ID, 'sound_talk') === 'yes' ? 'yes' : 'no'; | ||
$default_batchtime = $this->config->getAppValue(Application::APP_ID, 'setting_batchtime'); | ||
|
||
if ($default_batchtime != Settings::EMAIL_SEND_WEEKLY | ||
&& $default_batchtime != Settings::EMAIL_SEND_DAILY | ||
&& $default_batchtime != Settings::EMAIL_SEND_3HOURLY | ||
&& $default_batchtime != Settings::EMAIL_SEND_HOURLY | ||
&& $default_batchtime != Settings::EMAIL_SEND_OFF) { | ||
$default_batchtime = Settings::EMAIL_SEND_3HOURLY; | ||
} | ||
|
||
$this->initialState->provideInitialState('config', [ | ||
'setting' => 'admin', | ||
'setting_batchtime' => $default_batchtime, | ||
'sound_notification' => $default_sound_notification === 'yes', | ||
'sound_talk' => $default_sound_talk === 'yes', | ||
]); | ||
|
||
return new TemplateResponse('notifications', 'settings/admin'); | ||
} | ||
|
||
/** | ||
* @return string the section ID, e.g. 'sharing' | ||
*/ | ||
public function getSection(): string | ||
{ | ||
return 'notifications'; | ||
} | ||
|
||
/** | ||
* @return int whether the form should be rather on the top or bottom of | ||
* the admin section. The forms are arranged in ascending order of the | ||
* priority values. It is required to return a value between 0 and 100. | ||
* | ||
* E.g.: 70 | ||
*/ | ||
public function getPriority(): int | ||
{ | ||
return 20; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Notifications\Settings; | ||
|
||
use OCP\IL10N; | ||
use OCP\IURLGenerator; | ||
use OCP\Settings\IIconSection; | ||
|
||
class AdminSection implements IIconSection { | ||
/** @var IL10N */ | ||
private $l; | ||
|
||
/** @var IURLGenerator */ | ||
private $url; | ||
|
||
public function __construct(IURLGenerator $url, IL10N $l) { | ||
$this->url = $url; | ||
$this->l = $l; | ||
} | ||
|
||
/** | ||
* returns the relative path to an 16*16 icon describing the section. | ||
* e.g. '/core/img/places/files.svg' | ||
* | ||
* @returns string | ||
* @since 12 | ||
*/ | ||
public function getIcon(): string { | ||
return $this->url->imagePath('notifications', 'notifications-dark.svg'); | ||
} | ||
|
||
/** | ||
* returns the ID of the section. It is supposed to be a lower case string, | ||
* e.g. 'ldap' | ||
* | ||
* @returns string | ||
* @since 9.1 | ||
*/ | ||
public function getID(): string { | ||
return 'notifications'; | ||
} | ||
|
||
/** | ||
* returns the translated name as it should be displayed, e.g. 'LDAP / AD | ||
* integration'. Use the L10N service to translate it. | ||
* | ||
* @return string | ||
* @since 9.1 | ||
*/ | ||
public function getName(): string { | ||
return $this->l->t('Notifications'); | ||
} | ||
|
||
/** | ||
* @return int whether the form should be rather on the top or bottom of | ||
* the settings navigation. The sections are arranged in ascending order of | ||
* the priority values. It is required to return a value between 0 and 99. | ||
* | ||
* E.g.: 70 | ||
* @since 9.1 | ||
*/ | ||
public function getPriority(): int { | ||
return 10; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Vue from 'vue' | ||
import AdminSettings from './views/AdminSettings' | ||
|
||
Vue.prototype.t = t | ||
Vue.prototype.n = n | ||
|
||
export default new Vue({ | ||
el: '#notifications-admin-settings', | ||
render: h => h(AdminSettings), | ||
}) |
Oops, something went wrong.