1
0

Backend.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Group;
  8. /**
  9. * Abstract base class for user management
  10. */
  11. abstract class Backend implements \OCP\GroupInterface {
  12. /**
  13. * error code for functions not provided by the group backend
  14. */
  15. public const NOT_IMPLEMENTED = -501;
  16. protected $possibleActions = [
  17. self::CREATE_GROUP => 'createGroup',
  18. self::DELETE_GROUP => 'deleteGroup',
  19. self::ADD_TO_GROUP => 'addToGroup',
  20. self::REMOVE_FROM_GOUP => 'removeFromGroup',
  21. self::COUNT_USERS => 'countUsersInGroup',
  22. self::GROUP_DETAILS => 'getGroupDetails',
  23. self::IS_ADMIN => 'isAdmin',
  24. ];
  25. /**
  26. * Get all supported actions
  27. * @return int bitwise-or'ed actions
  28. *
  29. * Returns the supported actions as int to be
  30. * compared with \OC\Group\Backend::CREATE_GROUP etc.
  31. */
  32. public function getSupportedActions() {
  33. $actions = 0;
  34. foreach ($this->possibleActions as $action => $methodName) {
  35. if (method_exists($this, $methodName)) {
  36. $actions |= $action;
  37. }
  38. }
  39. return $actions;
  40. }
  41. /**
  42. * Check if backend implements actions
  43. * @param int $actions bitwise-or'ed actions
  44. * @return bool
  45. *
  46. * Returns the supported actions as int to be
  47. * compared with \OC\Group\Backend::CREATE_GROUP etc.
  48. */
  49. public function implementsActions($actions) {
  50. return (bool)($this->getSupportedActions() & $actions);
  51. }
  52. /**
  53. * is user in group?
  54. * @param string $uid uid of the user
  55. * @param string $gid gid of the group
  56. * @return bool
  57. *
  58. * Checks whether the user is member of a group or not.
  59. */
  60. public function inGroup($uid, $gid) {
  61. return in_array($gid, $this->getUserGroups($uid));
  62. }
  63. /**
  64. * Get all groups a user belongs to
  65. * @param string $uid Name of the user
  66. * @return array an array of group names
  67. *
  68. * This function fetches all groups a user belongs to. It does not check
  69. * if the user exists at all.
  70. */
  71. public function getUserGroups($uid) {
  72. return [];
  73. }
  74. /**
  75. * get a list of all groups
  76. * @param string $search
  77. * @param int $limit
  78. * @param int $offset
  79. * @return array an array of group names
  80. *
  81. * Returns a list with all groups
  82. */
  83. public function getGroups($search = '', $limit = -1, $offset = 0) {
  84. return [];
  85. }
  86. /**
  87. * check if a group exists
  88. * @param string $gid
  89. * @return bool
  90. */
  91. public function groupExists($gid) {
  92. return in_array($gid, $this->getGroups($gid, 1));
  93. }
  94. /**
  95. * get a list of all users in a group
  96. * @param string $gid
  97. * @param string $search
  98. * @param int $limit
  99. * @param int $offset
  100. * @return array<int,string> an array of user ids
  101. */
  102. public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
  103. return [];
  104. }
  105. }