Backend.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Knut Ahlers <knut@ahlers.me>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Vincent Petry <vincent@nextcloud.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Group;
  26. /**
  27. * Abstract base class for user management
  28. */
  29. abstract class Backend implements \OCP\GroupInterface {
  30. /**
  31. * error code for functions not provided by the group backend
  32. */
  33. public const NOT_IMPLEMENTED = -501;
  34. protected $possibleActions = [
  35. self::CREATE_GROUP => 'createGroup',
  36. self::DELETE_GROUP => 'deleteGroup',
  37. self::ADD_TO_GROUP => 'addToGroup',
  38. self::REMOVE_FROM_GOUP => 'removeFromGroup',
  39. self::COUNT_USERS => 'countUsersInGroup',
  40. self::GROUP_DETAILS => 'getGroupDetails',
  41. self::IS_ADMIN => 'isAdmin',
  42. ];
  43. /**
  44. * Get all supported actions
  45. * @return int bitwise-or'ed actions
  46. *
  47. * Returns the supported actions as int to be
  48. * compared with \OC\Group\Backend::CREATE_GROUP etc.
  49. */
  50. public function getSupportedActions() {
  51. $actions = 0;
  52. foreach ($this->possibleActions as $action => $methodName) {
  53. if (method_exists($this, $methodName)) {
  54. $actions |= $action;
  55. }
  56. }
  57. return $actions;
  58. }
  59. /**
  60. * Check if backend implements actions
  61. * @param int $actions bitwise-or'ed actions
  62. * @return bool
  63. *
  64. * Returns the supported actions as int to be
  65. * compared with \OC\Group\Backend::CREATE_GROUP etc.
  66. */
  67. public function implementsActions($actions) {
  68. return (bool)($this->getSupportedActions() & $actions);
  69. }
  70. /**
  71. * is user in group?
  72. * @param string $uid uid of the user
  73. * @param string $gid gid of the group
  74. * @return bool
  75. *
  76. * Checks whether the user is member of a group or not.
  77. */
  78. public function inGroup($uid, $gid) {
  79. return in_array($gid, $this->getUserGroups($uid));
  80. }
  81. /**
  82. * Get all groups a user belongs to
  83. * @param string $uid Name of the user
  84. * @return array an array of group names
  85. *
  86. * This function fetches all groups a user belongs to. It does not check
  87. * if the user exists at all.
  88. */
  89. public function getUserGroups($uid) {
  90. return [];
  91. }
  92. /**
  93. * get a list of all groups
  94. * @param string $search
  95. * @param int $limit
  96. * @param int $offset
  97. * @return array an array of group names
  98. *
  99. * Returns a list with all groups
  100. */
  101. public function getGroups($search = '', $limit = -1, $offset = 0) {
  102. return [];
  103. }
  104. /**
  105. * check if a group exists
  106. * @param string $gid
  107. * @return bool
  108. */
  109. public function groupExists($gid) {
  110. return in_array($gid, $this->getGroups($gid, 1));
  111. }
  112. /**
  113. * get a list of all users in a group
  114. * @param string $gid
  115. * @param string $search
  116. * @param int $limit
  117. * @param int $offset
  118. * @return array an array of user ids
  119. */
  120. public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
  121. return [];
  122. }
  123. }