Passed
Push — master ( 16be14...3c693d )
by Roeland
16:02 queued 12s
created

Sharing::shared()   C

Complexity

Conditions 10
Paths 10

Size

Total Lines 115
Code Lines 89

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 89
nc 10
nop 1
dl 0
loc 115
rs 6.3733
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
7
 *
8
 * @author Daniel Calviño Sánchez <[email protected]>
9
 * @author Joas Schilling <[email protected]>
10
 * @author Lukas Reschke <[email protected]>
11
 * @author Sascha Wiswedel <[email protected]>
12
 *
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
namespace OCA\AdminAudit\Actions;
31
32
use OCP\Share\IShare;
33
34
/**
35
 * Class Sharing logs the sharing actions
36
 *
37
 * @package OCA\AdminAudit\Actions
38
 */
39
class Sharing extends Action {
40
	/**
41
	 * Logs sharing of data
42
	 *
43
	 * @param array $params
44
	 */
45
	public function shared(array $params) {
46
		if ($params['shareType'] === IShare::TYPE_LINK) {
47
			$this->log(
48
				'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)',
49
				$params,
50
				[
51
					'itemType',
52
					'itemTarget',
53
					'itemSource',
54
					'permissions',
55
					'id',
56
				]
57
			);
58
		} elseif ($params['shareType'] === IShare::TYPE_USER) {
59
			$this->log(
60
				'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s"  (Share ID: %s)',
61
				$params,
62
				[
63
					'itemType',
64
					'itemTarget',
65
					'itemSource',
66
					'shareWith',
67
					'permissions',
68
					'id',
69
				]
70
			);
71
		} elseif ($params['shareType'] === IShare::TYPE_GROUP) {
72
			$this->log(
73
				'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s"  (Share ID: %s)',
74
				$params,
75
				[
76
					'itemType',
77
					'itemTarget',
78
					'itemSource',
79
					'shareWith',
80
					'permissions',
81
					'id',
82
				]
83
			);
84
		} elseif ($params['shareType'] === IShare::TYPE_ROOM) {
85
			$this->log(
86
				'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)',
87
				$params,
88
				[
89
					'itemType',
90
					'itemTarget',
91
					'itemSource',
92
					'shareWith',
93
					'permissions',
94
					'id',
95
				]
96
			);
97
		} elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
98
			$this->log(
99
				'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)',
100
				$params,
101
				[
102
					'itemType',
103
					'itemTarget',
104
					'itemSource',
105
					'shareWith',
106
					'permissions',
107
					'id',
108
				]
109
			);
110
		} elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
111
			$this->log(
112
				'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)',
113
				$params,
114
				[
115
					'itemType',
116
					'itemTarget',
117
					'itemSource',
118
					'shareWith',
119
					'permissions',
120
					'id',
121
				]
122
			);
123
		} elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
124
			$this->log(
125
				'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)',
126
				$params,
127
				[
128
					'itemType',
129
					'itemTarget',
130
					'itemSource',
131
					'shareWith',
132
					'permissions',
133
					'id',
134
				]
135
			);
136
		} elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
137
			$this->log(
138
				'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)',
139
				$params,
140
				[
141
					'itemType',
142
					'itemTarget',
143
					'itemSource',
144
					'shareWith',
145
					'permissions',
146
					'id',
147
				]
148
			);
149
		} elseif ($params['shareType'] === IShare::TYPE_DECK) {
150
			$this->log(
151
				'The %s "%s" with ID "%s" has been shared to the deck card "%s" with permissions "%s" (Share ID: %s)',
152
				$params,
153
				[
154
					'itemType',
155
					'itemTarget',
156
					'itemSource',
157
					'shareWith',
158
					'permissions',
159
					'id',
160
				]
161
			);
162
		}
163
	}
164
165
	/**
166
	 * Logs unsharing of data
167
	 *
168
	 * @param array $params
169
	 */
170
	public function unshare(array $params) {
171
		if ($params['shareType'] === IShare::TYPE_LINK) {
172
			$this->log(
173
				'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
174
				$params,
175
				[
176
					'itemType',
177
					'fileTarget',
178
					'itemSource',
179
					'id',
180
				]
181
			);
182
		} elseif ($params['shareType'] === IShare::TYPE_USER) {
183
			$this->log(
184
				'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
185
				$params,
186
				[
187
					'itemType',
188
					'fileTarget',
189
					'itemSource',
190
					'shareWith',
191
					'id',
192
				]
193
			);
194
		} elseif ($params['shareType'] === IShare::TYPE_GROUP) {
195
			$this->log(
196
				'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
197
				$params,
198
				[
199
					'itemType',
200
					'fileTarget',
201
					'itemSource',
202
					'shareWith',
203
					'id',
204
				]
205
			);
206
		} elseif ($params['shareType'] === IShare::TYPE_ROOM) {
207
			$this->log(
208
				'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
209
				$params,
210
				[
211
					'itemType',
212
					'fileTarget',
213
					'itemSource',
214
					'shareWith',
215
					'id',
216
				]
217
			);
218
		} elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
219
			$this->log(
220
				'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)',
221
				$params,
222
				[
223
					'itemType',
224
					'fileTarget',
225
					'itemSource',
226
					'shareWith',
227
					'id',
228
				]
229
			);
230
		} elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
231
			$this->log(
232
				'The %s "%s" with ID "%s" has been unshared from the circle "%s" (Share ID: %s)',
233
				$params,
234
				[
235
					'itemType',
236
					'fileTarget',
237
					'itemSource',
238
					'shareWith',
239
					'id',
240
				]
241
			);
242
		} elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
243
			$this->log(
244
				'The %s "%s" with ID "%s" has been unshared from the remote user "%s" (Share ID: %s)',
245
				$params,
246
				[
247
					'itemType',
248
					'fileTarget',
249
					'itemSource',
250
					'shareWith',
251
					'id',
252
				]
253
			);
254
		} elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
255
			$this->log(
256
				'The %s "%s" with ID "%s" has been unshared from the remote group "%s" (Share ID: %s)',
257
				$params,
258
				[
259
					'itemType',
260
					'fileTarget',
261
					'itemSource',
262
					'shareWith',
263
					'id',
264
				]
265
			);
266
		} elseif ($params['shareType'] === IShare::TYPE_DECK) {
267
			$this->log(
268
				'The %s "%s" with ID "%s" has been unshared from the deck card "%s" (Share ID: %s)',
269
				$params,
270
				[
271
					'itemType',
272
					'fileTarget',
273
					'itemSource',
274
					'shareWith',
275
					'id',
276
				]
277
			);
278
		}
279
	}
280
281
	/**
282
	 * Logs the updating of permission changes for shares
283
	 *
284
	 * @param array $params
285
	 */
286
	public function updatePermissions(array $params) {
287
		$this->log(
288
			'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
289
			$params,
290
			[
291
				'itemType',
292
				'path',
293
				'itemSource',
294
				'permissions',
295
			]
296
		);
297
	}
298
299
	/**
300
	 * Logs the password changes for a share
301
	 *
302
	 * @param array $params
303
	 */
304
	public function updatePassword(array $params) {
305
		$this->log(
306
			'The password of the publicly shared %s "%s" with ID "%s" has been changed',
307
			$params,
308
			[
309
				'itemType',
310
				'token',
311
				'itemSource',
312
			]
313
		);
314
	}
315
316
	/**
317
	 * Logs the expiration date changes for a share
318
	 *
319
	 * @param array $params
320
	 */
321
	public function updateExpirationDate(array $params) {
322
		$this->log(
323
			'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
324
			$params,
325
			[
326
				'itemType',
327
				'itemSource',
328
				'date',
329
			]
330
		);
331
	}
332
333
	/**
334
	 * Logs access of shared files
335
	 *
336
	 * @param array $params
337
	 */
338
	public function shareAccessed(array $params) {
339
		$this->log(
340
			'The shared %s with the token "%s" by "%s" has been accessed.',
341
			$params,
342
			[
343
				'itemType',
344
				'token',
345
				'uidOwner',
346
			]
347
		);
348
	}
349
}
350