|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Viktar Dubiniuk <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
|
6
|
|
|
* @license AGPL-3.0 |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\FederatedFileSharing\Ocm; |
|
23
|
|
|
|
|
24
|
|
|
use OCA\FederatedFileSharing\Ocm\Notification\FileNotification; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class NotificationManager |
|
28
|
|
|
* |
|
29
|
|
|
* @package OCA\FederatedFileSharing\Ocm |
|
30
|
|
|
*/ |
|
31
|
|
|
class NotificationManager { |
|
32
|
|
|
/** |
|
33
|
|
|
* @var Permissions |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $permissions; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* NotificationManager constructor. |
|
39
|
|
|
* |
|
40
|
|
|
* @param Permissions $permissions |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(Permissions $permissions) { |
|
43
|
|
|
$this->permissions = $permissions; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string $type |
|
48
|
|
|
* |
|
49
|
|
|
* @return FileNotification |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getFileNotification($type) { |
|
52
|
|
|
$notification = new FileNotification(); |
|
53
|
|
|
$notification->setNotificationType($type); |
|
54
|
|
|
return $notification; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param string $remoteId |
|
59
|
|
|
* @param string $token |
|
60
|
|
|
* @param string $action |
|
61
|
|
|
* @param array $data |
|
62
|
|
|
* |
|
63
|
|
|
* @return FileNotification |
|
64
|
|
|
*/ |
|
65
|
|
|
public function convertToOcmFileNotification($remoteId, $token, $action, $data = []) { |
|
66
|
|
|
$notification = new FileNotification(); |
|
67
|
|
|
$map = [ |
|
68
|
|
|
'accept' => FileNotification::NOTIFICATION_TYPE_SHARE_ACCEPTED, |
|
69
|
|
|
'decline' => FileNotification::NOTIFICATION_TYPE_SHARE_DECLINED, |
|
70
|
|
|
'unshare' => FileNotification::NOTIFICATION_TYPE_SHARE_UNSHARED, |
|
71
|
|
|
'revoke' => FileNotification::NOTIFICATION_TYPE_RESHARE_UNDO, |
|
72
|
|
|
'permissions' => FileNotification::NOTIFICATION_TYPE_RESHARE_CHANGE_PERMISSION, |
|
73
|
|
|
'reshare' => FileNotification::NOTIFICATION_TYPE_REQUEST_RESHARE |
|
74
|
|
|
]; |
|
75
|
|
|
$messages = [ |
|
76
|
|
|
'accept' => "Recipient accepted the share", |
|
77
|
|
|
'decline' => "Recipient declined the share or unshared it from themself", |
|
78
|
|
|
'unshare' => "File was unshared", |
|
79
|
|
|
'revoke' => "Tell the owner (or the sender of a reshare) that the reshare was unshared", |
|
80
|
|
|
'permissions' => "Tell the owner (or the sender of the reshare) that the permissions changed", |
|
81
|
|
|
'reshare' => "Recipient of a share ask the owner to reshare the file with another user" |
|
82
|
|
|
]; |
|
83
|
|
|
|
|
84
|
|
|
$notification->setNotificationType($map[$action]); |
|
85
|
|
|
$notification->setProviderId($remoteId); |
|
86
|
|
|
$notification->addNotificationData('sharedSecret', $token); |
|
87
|
|
|
$notification->addNotificationData('message', $messages[$action]); |
|
88
|
|
|
|
|
89
|
|
|
if ($action === 'permissions') { |
|
90
|
|
|
$ocmPermissions = $this->permissions->toOcmPermissions($data['permissions']); |
|
91
|
|
|
$notification->addNotificationData('permission', $ocmPermissions); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if ($action === 'reshare') { |
|
95
|
|
|
$ocmPermissions = $this->toOcmPermissions($data['permissions']); |
|
96
|
|
|
$notification->addNotificationData('permission', $ocmPermissions); |
|
97
|
|
|
$notification->addNotificationData('senderId', $data['senderId']); |
|
98
|
|
|
$notification->addNotificationData('shareWith', $data['shareWith']); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $notification; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|