Completed
Push — master ( a3c203...38961a )
by Morris
99:43 queued 81:59
created

UserManagement   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 93
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 1
A delete() 0 9 1
A change() 0 11 3
A setPassword() 0 13 2
A assign() 0 7 1
A unassign() 0 7 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
5
 *
6
 * @author Bjoern Schiessle <[email protected]>
7
 * @author Joas Schilling <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\AdminAudit\Actions;
28
29
30
use OCP\IUser;
31
32
/**
33
 * Class UserManagement logs all user management related actions.
34
 *
35
 * @package OCA\AdminAudit\Actions
36
 */
37
class UserManagement extends Action {
38
	/**
39
	 * Log creation of users
40
	 *
41
	 * @param array $params
42
	 */
43
	public function create(array $params) {
44
		$this->log(
45
			'User created: "%s"',
46
			$params,
47
			[
48
				'uid',
49
			]
50
		);
51
	}
52
53
	/**
54
	 * Log assignments of users (typically user backends)
55
	 *
56
	 * @param string $uid
57
	 */
58
	public function assign(string $uid) {
59
		$this->log(
60
		'UserID assigned: "%s"',
61
			[ 'uid' => $uid ],
62
			[ 'uid' ]
63
		);
64
	}
65
66
	/**
67
	 * Log deletion of users
68
	 *
69
	 * @param array $params
70
	 */
71
	public function delete(array $params) {
72
		$this->log(
73
			'User deleted: "%s"',
74
			$params,
75
			[
76
				'uid',
77
			]
78
		);
79
	}
80
81
	/**
82
	 * Log unassignments of users (typically user backends, no data removed)
83
	 *
84
	 * @param string $uid
85
	 */
86
	public function unassign(string $uid) {
87
		$this->log(
88
			'UserID unassigned: "%s"',
89
			[ 'uid' => $uid ],
90
			[ 'uid' ]
91
		);
92
	}
93
94
	/**
95
	 * Log enabling of users
96
	 *
97
	 * @param array $params
98
	 */
99
	public function change(array $params) {
100
		if ($params['feature'] === 'enabled') {
101
			$this->log(
102
				$params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"',
103
				['user' => $params['user']->getUID()],
104
				[
105
					'user',
106
				]
107
			);
108
		}
109
	}
110
111
	/**
112
	 * Logs changing of the user scope
113
	 *
114
	 * @param IUser $user
115
	 */
116
	public function setPassword(IUser $user) {
117
		if($user->getBackendClassName() === 'Database') {
118
			$this->log(
119
				'Password of user "%s" has been changed',
120
				[
121
					'user' => $user->getUID(),
122
				],
123
				[
124
					'user',
125
				]
126
			);
127
		}
128
	}
129
}
130