1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nextcloud - passman |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
6
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Passman\Service; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
use OCP\IURLGenerator; |
28
|
|
|
use OCP\Notification\IManager; |
29
|
|
|
|
30
|
|
|
class NotificationService { |
31
|
|
|
|
32
|
|
|
private IManager $manager; |
|
|
|
|
33
|
|
|
private IURLGenerator $urlGenerator; |
34
|
|
|
|
35
|
|
|
public function __construct(IManager $IManager, IURLGenerator $urlGenerator) { |
36
|
|
|
$this->manager = $IManager; |
37
|
|
|
$this->urlGenerator = $urlGenerator; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function credentialExpiredNotification($credential) { |
|
|
|
|
41
|
|
|
$link = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'index.php/apps/passman/#/vault/' . $credential->getVaultId() . '/edit/' . $credential->getId())); |
42
|
|
|
$api = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'index.php/apps/passman')); |
43
|
|
|
$notification = $this->manager->createNotification(); |
44
|
|
|
$remindAction = $notification->createAction(); |
45
|
|
|
$remindAction->setLabel('remind') |
46
|
|
|
->setLink($api . '/api/internal/notifications/remind/' . $credential->getId(), 'POST'); |
47
|
|
|
|
48
|
|
|
$declineAction = $notification->createAction(); |
49
|
|
|
$declineAction->setLabel('ignore') |
50
|
|
|
->setLink($api . '/api/internal/notifications/read/' . $credential->getId(), 'DELETE'); |
51
|
|
|
|
52
|
|
|
$notification->setApp('passman') |
53
|
|
|
->setUser($credential->getUserId()) |
54
|
|
|
->setDateTime(new \DateTime()) |
55
|
|
|
->setObject('credential', $credential->getId()) // Set notification type and id |
56
|
|
|
->setSubject('credential_expired', [$credential->getLabel()]) // set subject and parameters |
57
|
|
|
->setLink($link) |
58
|
|
|
->addAction($declineAction) |
59
|
|
|
->addAction($remindAction); |
60
|
|
|
|
61
|
|
|
$this->manager->notify($notification); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
function credentialSharedNotification($data) { |
|
|
|
|
66
|
|
|
$link = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'index.php/apps/passman/#/')); |
67
|
|
|
$api = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'index.php/apps/passman')); |
68
|
|
|
$notification = $this->manager->createNotification(); |
69
|
|
|
|
70
|
|
|
$declineAction = $notification->createAction(); |
71
|
|
|
$declineAction->setLabel('decline') |
72
|
|
|
->setLink($api . '/api/v2/sharing/decline/' . $data['req_id'], 'DELETE'); |
73
|
|
|
|
74
|
|
|
$notification->setApp('passman') |
75
|
|
|
->setUser($data['target_user']) |
76
|
|
|
->setDateTime(new \DateTime()) |
77
|
|
|
->setObject('passman_share_request', $data['req_id']) // type and id |
78
|
|
|
->setSubject('credential_shared', [$data['from_user'], $data['credential_label']]) // subject and parameters |
79
|
|
|
->setLink($link) |
80
|
|
|
->addAction($declineAction); |
81
|
|
|
|
82
|
|
|
$this->manager->notify($notification); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
function credentialDeclinedSharedNotification($data) { |
|
|
|
|
87
|
|
|
$notification = $this->manager->createNotification(); |
88
|
|
|
$notification->setApp('passman') |
89
|
|
|
->setUser($data['target_user']) |
90
|
|
|
->setDateTime(new \DateTime()) |
91
|
|
|
->setObject('passman_share_request', $data['req_id']) // type and id |
92
|
|
|
->setSubject('credential_share_denied', [$data['from_user'], $data['credential_label']]); // subject and parameters |
93
|
|
|
$this->manager->notify($notification); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
function credentialAcceptedSharedNotification($data) { |
|
|
|
|
98
|
|
|
$notification = $this->manager->createNotification(); |
99
|
|
|
$notification->setApp('passman') |
100
|
|
|
->setUser($data['target_user']) |
101
|
|
|
->setDateTime(new \DateTime()) |
102
|
|
|
->setObject('passman_share_request', $data['req_id']) // type and id |
103
|
|
|
->setSubject('credential_share_accepted', [$data['from_user'], $data['credential_label']]); // subject and parameters |
104
|
|
|
$this->manager->notify($notification); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|