remote.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. use dokuwiki\Remote\AccessDeniedException;
  3. /**
  4. * Class remote_plugin_acl
  5. */
  6. class remote_plugin_acl extends DokuWiki_Remote_Plugin
  7. {
  8. /**
  9. * Returns details about the remote plugin methods
  10. *
  11. * @return array Information about all provided methods. {@see dokuwiki\Remote\RemoteAPI}
  12. */
  13. public function _getMethods()
  14. {
  15. return array(
  16. 'listAcls' => array(
  17. 'args' => array(),
  18. 'return' => 'Array of ACLs {scope, user, permission}',
  19. 'name' => 'listAcls',
  20. 'doc' => 'Get the list of all ACLs',
  21. ),'addAcl' => array(
  22. 'args' => array('string','string','int'),
  23. 'return' => 'int',
  24. 'name' => 'addAcl',
  25. 'doc' => 'Adds a new ACL rule.'
  26. ), 'delAcl' => array(
  27. 'args' => array('string','string'),
  28. 'return' => 'int',
  29. 'name' => 'delAcl',
  30. 'doc' => 'Delete an existing ACL rule.'
  31. ),
  32. );
  33. }
  34. /**
  35. * List all ACL config entries
  36. *
  37. * @throws AccessDeniedException
  38. * @return dictionary {Scope: ACL}, where ACL = dictionnary {user/group: permissions_int}
  39. */
  40. public function listAcls()
  41. {
  42. if (!auth_isadmin()) {
  43. throw new AccessDeniedException(
  44. 'You are not allowed to access ACLs, superuser permission is required',
  45. 114
  46. );
  47. }
  48. /** @var admin_plugin_acl $apa */
  49. $apa = plugin_load('admin', 'acl');
  50. $apa->initAclConfig();
  51. return $apa->acl;
  52. }
  53. /**
  54. * Add a new entry to ACL config
  55. *
  56. * @param string $scope
  57. * @param string $user
  58. * @param int $level see also inc/auth.php
  59. * @throws AccessDeniedException
  60. * @return bool
  61. */
  62. public function addAcl($scope, $user, $level)
  63. {
  64. if (!auth_isadmin()) {
  65. throw new AccessDeniedException(
  66. 'You are not allowed to access ACLs, superuser permission is required',
  67. 114
  68. );
  69. }
  70. /** @var admin_plugin_acl $apa */
  71. $apa = plugin_load('admin', 'acl');
  72. return $apa->addOrUpdateACL($scope, $user, $level);
  73. }
  74. /**
  75. * Remove an entry from ACL config
  76. *
  77. * @param string $scope
  78. * @param string $user
  79. * @throws AccessDeniedException
  80. * @return bool
  81. */
  82. public function delAcl($scope, $user)
  83. {
  84. if (!auth_isadmin()) {
  85. throw new AccessDeniedException(
  86. 'You are not allowed to access ACLs, superuser permission is required',
  87. 114
  88. );
  89. }
  90. /** @var admin_plugin_acl $apa */
  91. $apa = plugin_load('admin', 'acl');
  92. return $apa->deleteACL($scope, $user);
  93. }
  94. }