• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 27849033491

19 Jun 2026 09:22PM UTC coverage: 57.825%. First build
27849033491

Pull #7820

github

web-flow
Merge b9b27e047 into e7d9ccf99
Pull Request #7820: Improve notification preference reliability across environments

51 of 70 new or added lines in 5 files covered. (72.86%)

11136 of 19258 relevant lines covered (57.83%)

7.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.19
/lib/Service/NotificationPreferenceResolver.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Service;
10

11
use OCP\Config\IUserConfig;
12
use OCP\IAppConfig;
13

14
class NotificationPreferenceResolver {
15
        public function __construct(
16
                private IAppConfig $appConfig,
17
                private IUserConfig $userConfig,
18
                private ActivitySettingsStore $activitySettingsStore,
19
        ) {
20
        }
23✔
21

22
        public function isEmailNotificationDisabled(
23
                string $userId,
24
                string $type,
25
                bool $requireKnownActivitySetting = true,
26
        ): bool {
27
                return $this->isNotificationDisabled($userId, 'email', $type, $requireKnownActivitySetting);
15✔
28
        }
29

30
        public function isInAppNotificationDisabled(
31
                string $userId,
32
                string $type,
33
                bool $requireKnownActivitySetting = true,
34
        ): bool {
35
                return $this->isNotificationDisabled($userId, 'notification', $type, $requireKnownActivitySetting);
5✔
36
        }
37

38
        private function isNotificationDisabled(
39
                string $userId,
40
                string $channel,
41
                string $type,
42
                bool $requireKnownActivitySetting,
43
        ): bool {
44
                if ($this->activitySettingsStore->isAvailable()) {
19✔
45
                        if ($requireKnownActivitySetting && !$this->activitySettingsStore->hasSetting($type)) {
3✔
46
                                return false;
1✔
47
                        }
48

49
                        $adminSetting = $this->activitySettingsStore->getAdminSetting($channel, $type);
2✔
50
                        if (!$this->isActivitySettingEnabled($adminSetting)) {
2✔
NEW
51
                                return true;
×
52
                        }
53

54
                        $userSetting = $this->activitySettingsStore->getUserSetting($userId, $channel, $type);
2✔
55
                        if (!$this->isActivitySettingEnabled($userSetting)) {
2✔
56
                                return true;
1✔
57
                        }
58

59
                        return false;
1✔
60
                }
61

62
                $configKey = sprintf('notify_%s_%s', $channel, $type);
16✔
63
                if (!$this->isActivitySettingEnabled($this->appConfig->getValueString('activity', $configKey, '1'))) {
16✔
64
                        return true;
2✔
65
                }
66

67
                return !$this->isActivitySettingEnabled(
14✔
68
                        $this->userConfig->getValueString($userId, 'activity', $configKey, '1')
14✔
69
                );
14✔
70
        }
71

72
        private function isActivitySettingEnabled(mixed $setting): bool {
73
                if (is_bool($setting)) {
18✔
NEW
74
                        return $setting;
×
75
                }
76
                if (is_int($setting)) {
18✔
NEW
77
                        return $setting === 1;
×
78
                }
79
                if ($setting === null) {
18✔
NEW
80
                        return true;
×
81
                }
82

83
                $normalized = strtolower(trim((string)$setting));
18✔
84
                return !in_array($normalized, ['', '0', 'false', 'off', 'no'], true);
18✔
85
        }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc