Completed
Push — master ( 417bc6...255c7d )
by Morris
36:32 queued 24:52
created

UserManagement::change()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
4
 *
5
 * @author Bjoern Schiessle <[email protected]>
6
 * @author Lukas Reschke <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
namespace OCA\Admin_Audit\Actions;
25
use OCP\IUser;
26
27
/**
28
 * Class UserManagement logs all user management related actions.
29
 *
30
 * @package OCA\Admin_Audit\Actions
31
 */
32
class UserManagement extends Action {
33
	/**
34
	 * Log creation of users
35
	 *
36
	 * @param array $params
37
	 */
38
	public function create(array $params) {
39
		$this->log(
40
			'User created: "%s"',
41
			$params,
42
			[
43
				'uid',
44
			]
45
		);
46
	}
47
48
	/**
49
	 * Log deletion of users
50
	 *
51
	 * @param array $params
52
	 */
53
	public function delete(array $params) {
54
		$this->log(
55
			'User deleted: "%s"',
56
			$params,
57
			[
58
				'uid',
59
			]
60
		);
61
	}
62
63
	/**
64
	 * Log enabling of users
65
	 *
66
	 * @param array $params
67
	 */
68
	public function change(array $params) {
69
		if ($params['feature'] === 'enabled') {
70
			$this->log(
71
				$params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"',
72
				['user' => $params['user']->getUID()],
73
				[
74
					'user',
75
				]
76
			);
77
		}
78
	}
79
80
	/**
81
	 * Logs changing of the user scope
82
	 *
83
	 * @param IUser $user
84
	 */
85
	public function setPassword(IUser $user) {
86
		if($user->getBackendClassName() === 'Database') {
87
			$this->log(
88
				'Password of user "%s" has been changed',
89
				[
90
					'user' => $user->getUID(),
91
				],
92
				[
93
					'user',
94
				]
95
			);
96
		}
97
	}
98
}
99