Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to the admin settings if the user did not configure it #779

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public function getForm() {

$activityGroups[$groupIdentifier]['activities'][$identifier] = [
'desc' => $setting->getName(),
IExtension::METHOD_MAIL => $this->userSettings->getConfigSetting('email', $identifier),
IExtension::METHOD_NOTIFICATION => $this->userSettings->getConfigSetting('notification', $identifier),
IExtension::METHOD_MAIL => $this->userSettings->getAdminSetting('email', $identifier),
IExtension::METHOD_NOTIFICATION => $this->userSettings->getAdminSetting('notification', $identifier),
'methods' => $methods,
];
}
Expand All @@ -111,7 +111,7 @@ public function getForm() {
}

$settingBatchTime = UserSettings::EMAIL_SEND_HOURLY;
$currentSetting = (int) $this->userSettings->getConfigSetting('setting', 'batchtime');
$currentSetting = (int) $this->userSettings->getAdminSetting('setting', 'batchtime');
if ($currentSetting === 3600 * 24 * 7) {
$settingBatchTime = UserSettings::EMAIL_SEND_WEEKLY;
} elseif ($currentSetting === 3600 * 24) {
Expand Down
20 changes: 12 additions & 8 deletions lib/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public function __construct(IManager $manager, IConfig $config) {
}

/**
* Get a setting for a user
* Get the user setting
* Falling back to the admin default if not set for the user
*
* Falls back to some good default values if the user does not have a preference
*
Expand All @@ -70,7 +71,7 @@ public function getUserSetting($user, $method, $type) {
return false;
}

$defaultSetting = $this->getDefaultFromSetting($method, $type);
$defaultSetting = $this->getAdminSetting($method, $type);
if (!$this->canModifySetting($method, $type)) {
return $defaultSetting;
}
Expand All @@ -93,12 +94,15 @@ public function getUserSetting($user, $method, $type) {
}

/**
* Get the admin configured default for the setting
* Falling back to the implementation default if not set by the admin
*
* @param string $method
* @param string $type
* @return bool|int
*/
public function getConfigSetting($method, $type) {
$defaultSetting = $this->getDefaultFromSetting($method, $type);
public function getAdminSetting($method, $type) {
$defaultSetting = $this->getDefaultSetting($method, $type);
if (is_bool($defaultSetting)) {
return (bool) $this->config->getAppValue(
'activity',
Expand All @@ -115,13 +119,13 @@ public function getConfigSetting($method, $type) {
}

/**
* Get a good default setting for a preference
* Get default setting for a preference from the implementation
*
* @param string $method Should be one of 'stream', 'email' or 'setting'
* @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
* @return bool|int
*/
protected function getDefaultFromSetting($method, $type) {
protected function getDefaultSetting($method, $type) {
if ($method === 'setting') {
if ($type === 'batchtime') {
return 3600;
Expand Down Expand Up @@ -236,12 +240,12 @@ public function filterUsersBySetting($users, $method, $type) {

// If the setting is enabled by default,
// we add all users that didn't set the preference yet.
if ($this->getDefaultFromSetting($method, $type)) {
if ($this->getDefaultSetting($method, $type)) {
foreach ($users as $user) {
if ($method === 'notification') {
$filteredUsers[$user] = true;
} else {
$filteredUsers[$user] = $this->getDefaultFromSetting('setting', 'batchtime');
$filteredUsers[$user] = $this->getDefaultSetting('setting', 'batchtime');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/settings/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<h2><?php p($l->t('Default settings')); ?></h2>

<p class="settings-hint">
<?php p($l->t('Configure the default notification settings for new users.')); ?>
<?php p($l->t('Configure the default notification settings.')); ?>
</p>

<?php print_unescaped($this->inc('settings/form')); ?>
Expand Down
2 changes: 1 addition & 1 deletion tests/UserSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ public function testGetDefaultSetting(string $method, string $type, $expected):
->willReturn($s);
}
}
$this->assertEquals($expected, self::invokePrivate($this->userSettings, 'getDefaultFromSetting', [$method, $type]));
$this->assertEquals($expected, self::invokePrivate($this->userSettings, 'getDefaultSetting', [$method, $type]));
}
}