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
|
|
|
use OCP\IConfig; |
27
|
|
|
use OCP\AppFramework\Db\DoesNotExistException; |
28
|
|
|
|
29
|
|
|
use OCA\Passman\Db\FileMapper; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class NotificationService { |
33
|
|
|
|
34
|
|
|
private $manager; |
35
|
|
|
|
36
|
|
|
public function __construct() { |
37
|
|
|
$this->manager = \OC::$server->getNotificationManager(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function credentialExpiredNotification($credential){ |
|
|
|
|
41
|
|
|
$urlGenerator = \OC::$server->getURLGenerator(); |
42
|
|
|
$link = $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('','index.php/apps/passman/#/vault/'. $credential->getVaultId() .'/edit/'. $credential->getId())); |
43
|
|
|
$api = $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'index.php/apps/passman')); |
44
|
|
|
$notification = $this->manager->createNotification(); |
45
|
|
|
$remindAction = $notification->createAction(); |
46
|
|
|
$remindAction->setLabel('remind') |
47
|
|
|
->setLink($api. '/api/internal/notifications/remind/'. $credential->getId() , 'POST'); |
48
|
|
|
|
49
|
|
|
$declineAction = $notification->createAction(); |
50
|
|
|
$declineAction->setLabel('ignore') |
51
|
|
|
->setLink($api . '/api/internal/notifications/read/'. $credential->getId(), 'DELETE'); |
52
|
|
|
|
53
|
|
|
$notification->setApp('passman') |
54
|
|
|
->setUser($credential->getUserId()) |
55
|
|
|
->setDateTime(new \DateTime()) |
56
|
|
|
->setObject('credential', $credential->getId()) // Set notification type and id |
57
|
|
|
->setSubject('credential_expired', [$credential->getLabel()]) // set subject and parameters |
58
|
|
|
->setLink($link) |
59
|
|
|
->addAction($declineAction) |
60
|
|
|
->addAction($remindAction); |
61
|
|
|
|
62
|
|
|
$this->manager->notify($notification); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
function credentialSharedNotification($data){ |
|
|
|
|
67
|
|
|
$urlGenerator = \OC::$server->getURLGenerator(); |
68
|
|
|
$link = $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('','index.php/apps/passman/#/')); |
69
|
|
|
$api = $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'index.php/apps/passman')); |
70
|
|
|
$notification = $this->manager->createNotification(); |
71
|
|
|
|
72
|
|
|
$declineAction = $notification->createAction(); |
73
|
|
|
$declineAction->setLabel('decline') |
74
|
|
|
->setLink($api . '/api/v2/sharing/decline/'. $data['req_id'], 'DELETE'); |
75
|
|
|
|
76
|
|
|
$notification->setApp('passman') |
77
|
|
|
->setUser($data['target_user']) |
78
|
|
|
->setDateTime(new \DateTime()) |
79
|
|
|
->setObject('passman_share_request', $data['req_id']) // type and id |
80
|
|
|
->setSubject('credential_shared', [$data['from_user'], $data['credential_label']]) // subject and parameters |
81
|
|
|
->setLink($link) |
82
|
|
|
->addAction($declineAction); |
83
|
|
|
|
84
|
|
|
$this->manager->notify($notification); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
View Code Duplication |
function credentialDeclinedSharedNotification($data){ |
|
|
|
|
89
|
|
|
$notification = $this->manager->createNotification(); |
90
|
|
|
$notification->setApp('passman') |
91
|
|
|
->setUser($data['target_user']) |
92
|
|
|
->setDateTime(new \DateTime()) |
93
|
|
|
->setObject('passman_share_request', $data['req_id']) // type and id |
94
|
|
|
->setSubject('credential_share_denied', [$data['from_user'], $data['credential_label']]); // subject and parameters |
95
|
|
|
$this->manager->notify($notification); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
View Code Duplication |
function credentialAcceptedSharedNotification($data){ |
|
|
|
|
100
|
|
|
$notification = $this->manager->createNotification(); |
101
|
|
|
$notification->setApp('passman') |
102
|
|
|
->setUser($data['target_user']) |
103
|
|
|
->setDateTime(new \DateTime()) |
104
|
|
|
->setObject('passman_share_request', $data['req_id']) // type and id |
105
|
|
|
->setSubject('credential_share_accepted', [$data['from_user'], $data['credential_label']]); // subject and parameters |
106
|
|
|
$this->manager->notify($notification); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
} |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.