You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserManagement.php 2.9KB

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