diff options
author | Joas Schilling <coding@schilljs.com> | 2022-04-06 15:23:19 +0300 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2022-04-07 13:55:57 +0300 |
commit | 7ea4f0ddb259b47fae8bda5842253053429e7caf (patch) | |
tree | 5985933422bf9e80a1525542be3e5c1800a1558d | |
parent | 7c7bb37ae959dd8e7c1041229e510e242899c10e (diff) |
Fallback to the admin settings if the user did not configure itbackport/779/stable22
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/Settings/Admin.php | 6 | ||||
-rw-r--r-- | lib/UserSettings.php | 18 | ||||
-rw-r--r-- | templates/settings/admin.php | 2 | ||||
-rw-r--r-- | tests/UserSettingsTest.php | 2 |
4 files changed, 16 insertions, 12 deletions
diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index f7cc9045..14107fe7 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -98,8 +98,8 @@ class Admin implements ISettings { $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, ]; } @@ -111,7 +111,7 @@ class Admin implements ISettings { } $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) { diff --git a/lib/UserSettings.php b/lib/UserSettings.php index d0c078d1..4da0118e 100644 --- a/lib/UserSettings.php +++ b/lib/UserSettings.php @@ -56,7 +56,8 @@ class UserSettings { } /** - * 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 * @@ -89,12 +90,15 @@ class UserSettings { } /** + * 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', @@ -111,13 +115,13 @@ class UserSettings { } /** - * 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; @@ -205,12 +209,12 @@ class UserSettings { // 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'); } } } diff --git a/templates/settings/admin.php b/templates/settings/admin.php index 4829cd37..c69e6670 100644 --- a/templates/settings/admin.php +++ b/templates/settings/admin.php @@ -41,7 +41,7 @@ style('activity', 'settings'); <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')); ?> diff --git a/tests/UserSettingsTest.php b/tests/UserSettingsTest.php index 5d4c5c74..37f8dc9d 100644 --- a/tests/UserSettingsTest.php +++ b/tests/UserSettingsTest.php @@ -77,6 +77,6 @@ class UserSettingsTest extends TestCase { ->willReturn($s); } } - $this->assertEquals($expected, self::invokePrivate($this->userSettings, 'getDefaultFromSetting', [$method, $type])); + $this->assertEquals($expected, self::invokePrivate($this->userSettings, 'getDefaultSetting', [$method, $type])); } } |