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

LibreSign / libresign / 20194411358

13 Dec 2025 03:57PM UTC coverage: 43.893%. First build
20194411358

Pull #5030

github

web-flow
Merge b1f46c3a5 into 25e6961df
Pull Request #5030: feat: send notification to admins after LibreSign upgrade

0 of 31 new or added lines in 1 file covered. (0.0%)

5818 of 13255 relevant lines covered (43.89%)

5.12 hits per line

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

0.0
/lib/Notification/Notifier.php
1
<?php
2

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

9
namespace OCA\Libresign\Notification;
10

11
use OCA\Libresign\AppInfo\Application;
12
use OCA\Libresign\Db\FileMapper;
13
use OCA\Libresign\Db\SignRequestMapper;
14
use OCP\IL10N;
15
use OCP\IURLGenerator;
16
use OCP\L10N\IFactory;
17
use OCP\Notification\IAction;
18
use OCP\Notification\INotification;
19
use OCP\Notification\INotifier;
20
use OCP\Notification\UnknownNotificationException;
21
use OCP\RichObjectStrings\Definitions;
22

23
class Notifier implements INotifier {
24
        public function __construct(
25
                private IFactory $factory,
26
                private IURLGenerator $url,
27
                private Definitions $definitions,
28
                private FileMapper $fileMapper,
29
                private SignRequestMapper $signRequestMapper,
30
        ) {
31
        }
×
32

33
        #[\Override]
34
        public function getID(): string {
35
                return Application::APP_ID;
×
36
        }
37

38
        #[\Override]
39
        public function getName(): string {
40
                return $this->factory->get(Application::APP_ID)->t('File sharing');
×
41
        }
42

43
        #[\Override]
44
        public function prepare(INotification $notification, string $languageCode): INotification {
45
                if ($notification->getApp() !== Application::APP_ID) {
×
46
                        throw new UnknownNotificationException();
×
47
                }
48

49
                $l = $this->factory->get(Application::APP_ID, $languageCode);
×
50

51
                return match ($notification->getSubject()) {
×
52
                        'new_sign_request' => $this->parseSignRequest($notification, $l, false),
×
53
                        'update_sign_request' => $this->parseSignRequest($notification, $l, true),
×
54
                        'file_signed' => $this->parseSigned($notification, $l),
×
NEW
55
                        'libresign_upgrade' => $this->parseUpgrade($notification, $l),
×
56
                        default => throw new UnknownNotificationException(),
×
57
                };
×
58
        }
59

60
        private function parseSignRequest(
61
                INotification $notification,
62
                IL10N $l,
63
                bool $update,
64
        ): INotification {
65

66
                $this->definitions->definitions['sign-request'] = [
×
67
                        'author' => 'LibreSign',
×
68
                        'since' => '28.0.0',
×
69
                        'parameters' => [
×
70
                                'id' => [
×
71
                                        'since' => '28.0.0',
×
72
                                        'required' => true,
×
73
                                        'description' => 'The id of SignRequest object',
×
74
                                        'example' => '12345',
×
75
                                ],
×
76
                                'name' => [
×
77
                                        'since' => '28.0.0',
×
78
                                        'required' => true,
×
79
                                        'description' => 'The display name of signer',
×
80
                                        'example' => 'John Doe',
×
81
                                ],
×
82
                        ],
×
83
                ];
×
84

85
                $parameters = $notification->getSubjectParameters();
×
86
                $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')));
×
87
                if (isset($parameters['file'])) {
×
88
                        $notification->setLink($parameters['file']['link']);
×
89
                        $signAction = $notification->createAction()
×
90
                                ->setParsedLabel($l->t('View'))
×
91
                                ->setPrimary(true)
×
92
                                ->setLink(
×
93
                                        $parameters['file']['link'],
×
94
                                        IAction::TYPE_WEB
×
95
                                );
×
96
                        $notification->addParsedAction($signAction);
×
97
                        if (isset($parameters['from'])) {
×
98
                                $subject = $l->t('{from} requested your signature on {file}');
×
99
                                $notification->setParsedSubject(
×
100
                                        str_replace(
×
101
                                                ['{from}', '{file}'],
×
102
                                                [
×
103
                                                        $parameters['from']['name'],
×
104
                                                        $parameters['file']['name'],
×
105
                                                ],
×
106
                                                $subject
×
107
                                        ))
×
108
                                        ->setRichSubject($subject, $parameters);
×
109
                        }
110
                }
111
                if ($update) {
×
112
                        $notification->setParsedMessage($l->t('Changes have been made in a file that you have to sign.'));
×
113
                }
114

115
                if (isset($parameters['signRequest']) && isset($parameters['signRequest']['id'])) {
×
116
                        $dismissAction = $notification->createAction()
×
117
                                ->setParsedLabel($l->t('Dismiss notification'))
×
118
                                ->setLink(
×
119
                                        $this->url->linkToOCSRouteAbsolute(
×
120
                                                'libresign.notify.notificationDismiss',
×
121
                                                [
×
122
                                                        'apiVersion' => 'v1',
×
123
                                                        'timestamp' => $notification->getDateTime()->getTimestamp(),
×
124
                                                        'objectType' => 'signRequest',
×
125
                                                        'objectId' => $parameters['signRequest']['id'],
×
126
                                                        'subject' => 'new_sign_request',
×
127
                                                ],
×
128
                                        ),
×
129
                                        IAction::TYPE_DELETE
×
130
                                );
×
131
                        $notification->addParsedAction($dismissAction);
×
132
                }
133

134
                return $notification;
×
135
        }
136

137
        private function parseSigned(
138
                INotification $notification,
139
                IL10N $l,
140
        ): INotification {
141

142
                $this->definitions->definitions['signer'] = [
×
143
                        'author' => 'LibreSign',
×
144
                        'since' => '30.0.0',
×
145
                        'parameters' => [
×
146
                                'id' => [
×
147
                                        'since' => '30.0.0',
×
148
                                        'required' => true,
×
149
                                        'description' => 'The identify method id',
×
150
                                        'example' => '12345',
×
151
                                ],
×
152
                                'name' => [
×
153
                                        'since' => '30.0.0',
×
154
                                        'required' => true,
×
155
                                        'description' => 'The display name of signer',
×
156
                                        'example' => 'John Doe',
×
157
                                ],
×
158
                        ],
×
159
                ];
×
160

161
                $parameters = $notification->getSubjectParameters();
×
162
                $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')));
×
163
                if (isset($parameters['file'])) {
×
164
                        $notification->setLink($parameters['file']['link']);
×
165
                        $signAction = $notification->createAction()
×
166
                                ->setParsedLabel($l->t('View'))
×
167
                                ->setPrimary(true)
×
168
                                ->setLink(
×
169
                                        $parameters['file']['link'],
×
170
                                        IAction::TYPE_WEB
×
171
                                );
×
172
                        $notification->addParsedAction($signAction);
×
173
                        if (isset($parameters['from'])) {
×
174
                                $subject = $l->t('{from} signed {file}');
×
175
                                $notification->setParsedSubject(
×
176
                                        str_replace(
×
177
                                                ['{from}', '{file}'],
×
178
                                                [
×
179
                                                        $parameters['from']['name'],
×
180
                                                        $parameters['file']['name'],
×
181
                                                ],
×
182
                                                $subject
×
183
                                        ))
×
184
                                        ->setRichSubject($subject, $parameters);
×
185
                        }
186
                }
187

188
                if (isset($parameters['signedFile']) && isset($parameters['signedFile']['id'])) {
×
189
                        $dismissAction = $notification->createAction()
×
190
                                ->setParsedLabel($l->t('Dismiss notification'))
×
191
                                ->setLink(
×
192
                                        $this->url->linkToOCSRouteAbsolute(
×
193
                                                'libresign.notify.notificationDismiss',
×
194
                                                [
×
195
                                                        'apiVersion' => 'v1',
×
196
                                                        'timestamp' => $notification->getDateTime()->getTimestamp(),
×
197
                                                        'objectType' => 'signedFile',
×
198
                                                        'objectId' => $parameters['signedFile']['id'],
×
199
                                                        'subject' => 'file_signed',
×
200
                                                ],
×
201
                                        ),
×
202
                                        IAction::TYPE_DELETE
×
203
                                );
×
204
                        $notification->addParsedAction($dismissAction);
×
205
                }
206

207
                return $notification;
×
208

209
        }
210

211
        private function parseUpgrade(
212
                INotification $notification,
213
                IL10N $l,
214
        ): INotification {
215

NEW
216
                $parameters = $notification->getSubjectParameters();
×
NEW
217
                $version = $parameters['version'] ?? '';
×
NEW
218
                $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')));
×
NEW
219
                $subject = $l->t('LibreSign has been updated to version %s!', [$version]);
×
NEW
220
                $message = $parameters['message'] ?? '';
×
NEW
221
                $notification->setParsedSubject($subject)
×
NEW
222
                        ->setParsedMessage($message);
×
223

NEW
224
                $donateAction = $notification->createAction()
×
NEW
225
                        ->setParsedLabel($l->t('Donate'))
×
NEW
226
                        ->setPrimary(true)
×
NEW
227
                        ->setLink('https://github.com/sponsors/LibreSign', \OCP\Notification\IAction::TYPE_WEB);
×
228

NEW
229
                $notification->addParsedAction($donateAction);
×
230

NEW
231
                $dismissAction = $notification->createAction()
×
NEW
232
                        ->setParsedLabel($l->t('Dismiss notification'))
×
NEW
233
                        ->setPrimary(false)
×
NEW
234
                        ->setLink(
×
NEW
235
                                $this->url->linkToOCSRouteAbsolute(
×
NEW
236
                                        'libresign.notify.notificationDismiss',
×
NEW
237
                                        [
×
NEW
238
                                                'apiVersion' => 'v1',
×
NEW
239
                                                'timestamp' => $notification->getDateTime()->getTimestamp(),
×
NEW
240
                                                'objectType' => 'upgrade',
×
NEW
241
                                                'objectId' => '1',
×
NEW
242
                                                'subject' => 'libresign_upgrade',
×
NEW
243
                                        ],
×
NEW
244
                                ),
×
NEW
245
                                IAction::TYPE_DELETE
×
NEW
246
                        );
×
247

NEW
248
                $notification->addParsedAction($dismissAction);
×
249

NEW
250
                return $notification;
×
251
        }
252
}
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