backend.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * error code for functions not provided by the group backend
  24. */
  25. define('OC_GROUP_BACKEND_NOT_IMPLEMENTED', -501);
  26. /**
  27. * actions that user backends can define
  28. */
  29. define('OC_GROUP_BACKEND_CREATE_GROUP', 0x00000001);
  30. define('OC_GROUP_BACKEND_DELETE_GROUP', 0x00000010);
  31. define('OC_GROUP_BACKEND_ADD_TO_GROUP', 0x00000100);
  32. define('OC_GROUP_BACKEND_REMOVE_FROM_GOUP', 0x00001000);
  33. /**
  34. * Abstract base class for user management
  35. */
  36. abstract class OC_Group_Backend implements OC_Group_Interface {
  37. protected $possibleActions = array(
  38. OC_GROUP_BACKEND_CREATE_GROUP => 'createGroup',
  39. OC_GROUP_BACKEND_DELETE_GROUP => 'deleteGroup',
  40. OC_GROUP_BACKEND_ADD_TO_GROUP => 'addToGroup',
  41. OC_GROUP_BACKEND_REMOVE_FROM_GOUP => 'removeFromGroup',
  42. );
  43. /**
  44. * @brief 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_USER_BACKEND_CREATE_USER 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. * @brief Check if backend implements actions
  61. * @param int $actions bitwise-or'ed actions
  62. * @return boolean
  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. * @brief 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. * @brief Get all groups a user belongs to
  83. * @param string $uid Name of the user
  84. * @return array with 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 array();
  91. }
  92. /**
  93. * @brief get a list of all groups
  94. * @param string $search
  95. * @param int $limit
  96. * @param int $offset
  97. * @return array with group names
  98. *
  99. * Returns a list with all groups
  100. */
  101. public function getGroups($search = '', $limit = -1, $offset = 0) {
  102. return array();
  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. * @brief 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 with user ids
  119. */
  120. public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
  121. return array();
  122. }
  123. }