backend.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. * @author Bart Visscher <bartv@thisnet.nl>
  5. * @author Jakob Sack <mail@jakobsack.de>
  6. * @author Joas Schilling <nickvergessen@owncloud.com>
  7. * @author Lukas Reschke <lukas@owncloud.com>
  8. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <icewind@owncloud.com>
  11. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. *
  14. * @copyright Copyright (c) 2015, ownCloud, Inc.
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  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, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. /**
  31. * error code for functions not provided by the group backend
  32. * @deprecated Use \OC_Group_Backend::NOT_IMPLEMENTED instead
  33. */
  34. define('OC_GROUP_BACKEND_NOT_IMPLEMENTED', -501);
  35. /**
  36. * actions that user backends can define
  37. */
  38. /** @deprecated Use \OC_Group_Backend::CREATE_GROUP instead */
  39. define('OC_GROUP_BACKEND_CREATE_GROUP', 0x00000001);
  40. /** @deprecated Use \OC_Group_Backend::DELETE_GROUP instead */
  41. define('OC_GROUP_BACKEND_DELETE_GROUP', 0x00000010);
  42. /** @deprecated Use \OC_Group_Backend::ADD_TO_GROUP instead */
  43. define('OC_GROUP_BACKEND_ADD_TO_GROUP', 0x00000100);
  44. /** @deprecated Use \OC_Group_Backend::REMOVE_FROM_GOUP instead */
  45. define('OC_GROUP_BACKEND_REMOVE_FROM_GOUP', 0x00001000);
  46. /** @deprecated Obsolete */
  47. define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000); //OBSOLETE
  48. /** @deprecated Use \OC_Group_Backend::COUNT_USERS instead */
  49. define('OC_GROUP_BACKEND_COUNT_USERS', 0x00100000);
  50. /**
  51. * Abstract base class for user management
  52. */
  53. abstract class OC_Group_Backend implements OC_Group_Interface {
  54. /**
  55. * error code for functions not provided by the group backend
  56. */
  57. const NOT_IMPLEMENTED = -501;
  58. /**
  59. * actions that user backends can define
  60. */
  61. const CREATE_GROUP = 0x00000001;
  62. const DELETE_GROUP = 0x00000010;
  63. const ADD_TO_GROUP = 0x00000100;
  64. const REMOVE_FROM_GOUP = 0x00001000;
  65. //OBSOLETE const GET_DISPLAYNAME = 0x00010000;
  66. const COUNT_USERS = 0x00100000;
  67. protected $possibleActions = array(
  68. self::CREATE_GROUP => 'createGroup',
  69. self::DELETE_GROUP => 'deleteGroup',
  70. self::ADD_TO_GROUP => 'addToGroup',
  71. self::REMOVE_FROM_GOUP => 'removeFromGroup',
  72. self::COUNT_USERS => 'countUsersInGroup',
  73. );
  74. /**
  75. * Get all supported actions
  76. * @return int bitwise-or'ed actions
  77. *
  78. * Returns the supported actions as int to be
  79. * compared with OC_USER_BACKEND_CREATE_USER etc.
  80. */
  81. public function getSupportedActions() {
  82. $actions = 0;
  83. foreach($this->possibleActions AS $action => $methodName) {
  84. if(method_exists($this, $methodName)) {
  85. $actions |= $action;
  86. }
  87. }
  88. return $actions;
  89. }
  90. /**
  91. * Check if backend implements actions
  92. * @param int $actions bitwise-or'ed actions
  93. * @return bool
  94. *
  95. * Returns the supported actions as int to be
  96. * compared with OC_GROUP_BACKEND_CREATE_GROUP etc.
  97. */
  98. public function implementsActions($actions) {
  99. return (bool)($this->getSupportedActions() & $actions);
  100. }
  101. /**
  102. * is user in group?
  103. * @param string $uid uid of the user
  104. * @param string $gid gid of the group
  105. * @return bool
  106. *
  107. * Checks whether the user is member of a group or not.
  108. */
  109. public function inGroup($uid, $gid) {
  110. return in_array($gid, $this->getUserGroups($uid));
  111. }
  112. /**
  113. * Get all groups a user belongs to
  114. * @param string $uid Name of the user
  115. * @return array an array of group names
  116. *
  117. * This function fetches all groups a user belongs to. It does not check
  118. * if the user exists at all.
  119. */
  120. public function getUserGroups($uid) {
  121. return array();
  122. }
  123. /**
  124. * get a list of all groups
  125. * @param string $search
  126. * @param int $limit
  127. * @param int $offset
  128. * @return array an array of group names
  129. *
  130. * Returns a list with all groups
  131. */
  132. public function getGroups($search = '', $limit = -1, $offset = 0) {
  133. return array();
  134. }
  135. /**
  136. * check if a group exists
  137. * @param string $gid
  138. * @return bool
  139. */
  140. public function groupExists($gid) {
  141. return in_array($gid, $this->getGroups($gid, 1));
  142. }
  143. /**
  144. * get a list of all users in a group
  145. * @param string $gid
  146. * @param string $search
  147. * @param int $limit
  148. * @param int $offset
  149. * @return array an array of user ids
  150. */
  151. public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
  152. return array();
  153. }
  154. }