UserManagement.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\AdminAudit\Actions;
  8. use OCP\IUser;
  9. /**
  10. * Class UserManagement logs all user management related actions.
  11. *
  12. * @package OCA\AdminAudit\Actions
  13. */
  14. class UserManagement extends Action {
  15. /**
  16. * Log creation of users
  17. *
  18. * @param array $params
  19. */
  20. public function create(array $params): void {
  21. $this->log(
  22. 'User created: "%s"',
  23. $params,
  24. [
  25. 'uid',
  26. ]
  27. );
  28. }
  29. /**
  30. * Log assignments of users (typically user backends)
  31. *
  32. * @param string $uid
  33. */
  34. public function assign(string $uid): void {
  35. $this->log(
  36. 'UserID assigned: "%s"',
  37. [ 'uid' => $uid ],
  38. [ 'uid' ]
  39. );
  40. }
  41. /**
  42. * Log deletion of users
  43. *
  44. * @param array $params
  45. */
  46. public function delete(array $params): void {
  47. $this->log(
  48. 'User deleted: "%s"',
  49. $params,
  50. [
  51. 'uid',
  52. ]
  53. );
  54. }
  55. /**
  56. * Log unassignments of users (typically user backends, no data removed)
  57. *
  58. * @param string $uid
  59. */
  60. public function unassign(string $uid): void {
  61. $this->log(
  62. 'UserID unassigned: "%s"',
  63. [ 'uid' => $uid ],
  64. [ 'uid' ]
  65. );
  66. }
  67. /**
  68. * Log enabling of users
  69. *
  70. * @param array $params
  71. */
  72. public function change(array $params): void {
  73. switch ($params['feature']) {
  74. case 'enabled':
  75. $this->log(
  76. $params['value'] === true
  77. ? 'User enabled: "%s"'
  78. : 'User disabled: "%s"',
  79. ['user' => $params['user']->getUID()],
  80. [
  81. 'user',
  82. ]
  83. );
  84. break;
  85. case 'eMailAddress':
  86. $this->log(
  87. 'Email address changed for user %s',
  88. ['user' => $params['user']->getUID()],
  89. [
  90. 'user',
  91. ]
  92. );
  93. break;
  94. }
  95. }
  96. /**
  97. * Logs changing of the user scope
  98. *
  99. * @param IUser $user
  100. */
  101. public function setPassword(IUser $user): void {
  102. if ($user->getBackendClassName() === 'Database') {
  103. $this->log(
  104. 'Password of user "%s" has been changed',
  105. [
  106. 'user' => $user->getUID(),
  107. ],
  108. [
  109. 'user',
  110. ]
  111. );
  112. }
  113. }
  114. }