Completed
Push — master ( 7d58bb...687957 )
by Morris
17:49
created

Sharing::shared()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 41
Code Lines 30

Duplication

Lines 14
Ratio 34.15 %

Importance

Changes 0
Metric Value
cc 4
eloc 30
nc 4
nop 1
dl 14
loc 41
rs 8.5806
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
4
 *
5
 * @author Lukas Reschke <[email protected]>
6
 *
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\AdminAudit\Actions;
25
26
27
use OCP\Share;
28
29
/**
30
 * Class Sharing logs the sharing actions
31
 *
32
 * @package OCA\AdminAudit\Actions
33
 */
34
class Sharing extends Action {
35
	/**
36
	 * Logs sharing of data
37
	 *
38
	 * @param array $params
39
	 */
40
	public function shared(array $params) {
41
		if($params['shareType'] === Share::SHARE_TYPE_LINK) {
42
			$this->log(
43
				'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)',
44
				$params,
45
				[
46
					'itemType',
47
					'itemTarget',
48
					'itemSource',
49
					'permissions',
50
					'id',
51
				]
52
			);
53 View Code Duplication
		} elseif($params['shareType'] === Share::SHARE_TYPE_USER) {
54
			$this->log(
55
				'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s"  (Share ID: %s)',
56
				$params,
57
				[
58
					'itemType',
59
					'itemTarget',
60
					'itemSource',
61
					'shareWith',
62
					'permissions',
63
					'id',
64
				]
65
			);
66
		} elseif($params['shareType'] === Share::SHARE_TYPE_GROUP) {
67
			$this->log(
68
				'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s"  (Share ID: %s)',
69
				$params,
70
				[
71
					'itemType',
72
					'itemTarget',
73
					'itemSource',
74
					'shareWith',
75
					'permissions',
76
					'id',
77
				]
78
			);
79
		}
80
	}
81
82
	/**
83
	 * Logs unsharing of data
84
	 *
85
	 * @param array $params
86
	 */
87
	public function unshare(array $params) {
88
		if($params['shareType'] === Share::SHARE_TYPE_LINK) {
89
			$this->log(
90
				'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
91
				$params,
92
				[
93
					'itemType',
94
					'fileTarget',
95
					'itemSource',
96
					'id',
97
				]
98
			);
99 View Code Duplication
		} elseif($params['shareType'] === Share::SHARE_TYPE_USER) {
100
			$this->log(
101
				'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
102
				$params,
103
				[
104
					'itemType',
105
					'fileTarget',
106
					'itemSource',
107
					'shareWith',
108
					'id',
109
				]
110
			);
111
		} elseif($params['shareType'] === Share::SHARE_TYPE_GROUP) {
112
			$this->log(
113
				'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
114
				$params,
115
				[
116
					'itemType',
117
					'fileTarget',
118
					'itemSource',
119
					'shareWith',
120
					'id',
121
				]
122
			);
123
		}
124
	}
125
126
	/**
127
	 * Logs the updating of permission changes for shares
128
	 *
129
	 * @param array $params
130
	 */
131
	public function updatePermissions(array $params) {
132
		$this->log(
133
			'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
134
			$params,
135
			[
136
				'itemType',
137
				'path',
138
				'itemSource',
139
				'permissions',
140
			]
141
		);
142
	}
143
144
	/**
145
	 * Logs the password changes for a share
146
	 *
147
	 * @param array $params
148
	 */
149
	public function updatePassword(array $params) {
150
		$this->log(
151
			'The password of the publicly shared %s "%s" with ID "%s" has been changed',
152
			$params,
153
			[
154
				'itemType',
155
				'token',
156
				'itemSource',
157
			]
158
		);
159
	}
160
161
	/**
162
	 * Logs the expiration date changes for a share
163
	 *
164
	 * @param array $params
165
	 */
166
	public function updateExpirationDate(array $params) {
167
		$this->log(
168
			'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
169
			$params,
170
			[
171
				'itemType',
172
				'itemSource',
173
				'date',
174
			]
175
		);
176
	}
177
178
	/**
179
	 * Logs access of shared files
180
	 *
181
	 * @param array $params
182
	 */
183
	public function shareAccessed(array $params) {
184
		$this->log(
185
			'The shared %s with the token "%s" by "%s" has been accessed.',
186
			$params,
187
			[
188
				'itemType',
189
				'token',
190
				'uidOwner',
191
			]
192
		);
193
	}
194
}
195