backend.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2010 Frank Karlitschek karlitschek@kde.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_IN_GROUP', 0x00000100);
  32. define('OC_GROUP_BACKEND_ADD_TO_GROUP', 0x00001000);
  33. define('OC_GROUP_BACKEND_REMOVE_FROM_GOUP', 0x00010000);
  34. define('OC_GROUP_BACKEND_GET_USER_GROUPS', 0x00100000);
  35. define('OC_GROUP_BACKEND_GET_USERS', 0x01000000);
  36. define('OC_GROUP_BACKEND_GET_GROUPS', 0x10000000);
  37. /**
  38. * Abstract base class for user management
  39. */
  40. abstract class OC_Group_Backend {
  41. protected $possibleActions = array(
  42. OC_GROUP_BACKEND_CREATE_GROUP => 'createGroup',
  43. OC_GROUP_BACKEND_DELETE_GROUP => 'deleteGroup',
  44. OC_GROUP_BACKEND_IN_GROUP => 'inGroup',
  45. OC_GROUP_BACKEND_ADD_TO_GROUP => 'addToGroup',
  46. OC_GROUP_BACKEND_REMOVE_FROM_GOUP => 'removeFromGroup',
  47. OC_GROUP_BACKEND_GET_USER_GROUPS => 'getUserGroups',
  48. OC_GROUP_BACKEND_GET_USERS => 'usersInGroup',
  49. OC_GROUP_BACKEND_GET_GROUPS => 'getGroups'
  50. );
  51. /**
  52. * @brief Get all supported actions
  53. * @returns bitwise-or'ed actions
  54. *
  55. * Returns the supported actions as int to be
  56. * compared with OC_USER_BACKEND_CREATE_USER etc.
  57. */
  58. public function getSupportedActions(){
  59. $actions = 0;
  60. foreach($this->possibleActions AS $action => $methodName){
  61. if(method_exists($this, $methodName)) {
  62. $actions |= $action;
  63. }
  64. }
  65. return $actions;
  66. }
  67. /**
  68. * @brief Check if backend implements actions
  69. * @param $actions bitwise-or'ed actions
  70. * @returns boolean
  71. *
  72. * Returns the supported actions as int to be
  73. * compared with OC_GROUP_BACKEND_CREATE_GROUP etc.
  74. */
  75. public function implementsActions($actions){
  76. return (bool)($this->getSupportedActions() & $actions);
  77. }
  78. /**
  79. * check if a group exists
  80. * @param string $gid
  81. * @return bool
  82. */
  83. public function groupExists($gid){
  84. if(!$this->implementsActions(OC_GROUP_BACKEND_GET_GROUPS)){
  85. return false;
  86. }
  87. return in_array($gid, $this->getGroups());
  88. }
  89. }