UserManagement.php 3.0 KB

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