19f8068d2SMohamed Amine BERGAOUI<?php 29f8068d2SMohamed Amine BERGAOUI 3dd87735dSAndreas Gohruse dokuwiki\Remote\AccessDeniedException; 4dd87735dSAndreas Gohr 542ea7f44SGerrit Uitslag/** 642ea7f44SGerrit Uitslag * Class remote_plugin_acl 742ea7f44SGerrit Uitslag */ 8a4e3d556SAndreas Gohrclass remote_plugin_acl extends DokuWiki_Remote_Plugin 9a4e3d556SAndreas Gohr{ 1042ea7f44SGerrit Uitslag 1142ea7f44SGerrit Uitslag /** 1242ea7f44SGerrit Uitslag * Returns details about the remote plugin methods 1342ea7f44SGerrit Uitslag * 14dd87735dSAndreas Gohr * @return array Information about all provided methods. {@see dokuwiki\Remote\RemoteAPI} 1542ea7f44SGerrit Uitslag */ 16a4e3d556SAndreas Gohr public function _getMethods() 17a4e3d556SAndreas Gohr { 18*bff2c9d2SAndreas Gohr return [ 19*bff2c9d2SAndreas Gohr 'listAcls' => [ 20*bff2c9d2SAndreas Gohr 'args' => [], 216d2588b6SCyril Duchon-Doris 'return' => 'Array of ACLs {scope, user, permission}', 2232b2e368SDharmik 'name' => 'listAcls', 23*bff2c9d2SAndreas Gohr 'doc' => 'Get the list of all ACLs' 24*bff2c9d2SAndreas Gohr ], 25*bff2c9d2SAndreas Gohr 'addAcl' => [ 26*bff2c9d2SAndreas Gohr 'args' => ['string', 'string', 'int'], 279f8068d2SMohamed Amine BERGAOUI 'return' => 'int', 289f8068d2SMohamed Amine BERGAOUI 'name' => 'addAcl', 299f8068d2SMohamed Amine BERGAOUI 'doc' => 'Adds a new ACL rule.' 30*bff2c9d2SAndreas Gohr ], 31*bff2c9d2SAndreas Gohr 'delAcl' => [ 32*bff2c9d2SAndreas Gohr 'args' => ['string', 'string'], 339f8068d2SMohamed Amine BERGAOUI 'return' => 'int', 349f8068d2SMohamed Amine BERGAOUI 'name' => 'delAcl', 359f8068d2SMohamed Amine BERGAOUI 'doc' => 'Delete an existing ACL rule.' 36*bff2c9d2SAndreas Gohr ] 37*bff2c9d2SAndreas Gohr ]; 389f8068d2SMohamed Amine BERGAOUI } 399f8068d2SMohamed Amine BERGAOUI 4042ea7f44SGerrit Uitslag /** 416d2588b6SCyril Duchon-Doris * List all ACL config entries 426d2588b6SCyril Duchon-Doris * 43dd87735dSAndreas Gohr * @throws AccessDeniedException 4442f3fd0aSCyril Duchon-Doris * @return dictionary {Scope: ACL}, where ACL = dictionnary {user/group: permissions_int} 456d2588b6SCyril Duchon-Doris */ 46a4e3d556SAndreas Gohr public function listAcls() 47a4e3d556SAndreas Gohr { 4842f3fd0aSCyril Duchon-Doris if (!auth_isadmin()) { 49dd87735dSAndreas Gohr throw new AccessDeniedException( 5064159a61SAndreas Gohr 'You are not allowed to access ACLs, superuser permission is required', 5164159a61SAndreas Gohr 114 5264159a61SAndreas Gohr ); 5342f3fd0aSCyril Duchon-Doris } 546d2588b6SCyril Duchon-Doris /** @var admin_plugin_acl $apa */ 556d2588b6SCyril Duchon-Doris $apa = plugin_load('admin', 'acl'); 56a4e3d556SAndreas Gohr $apa->initAclConfig(); 5742f3fd0aSCyril Duchon-Doris return $apa->acl; 586d2588b6SCyril Duchon-Doris } 596d2588b6SCyril Duchon-Doris 606d2588b6SCyril Duchon-Doris /** 6142ea7f44SGerrit Uitslag * Add a new entry to ACL config 6242ea7f44SGerrit Uitslag * 6342ea7f44SGerrit Uitslag * @param string $scope 6442ea7f44SGerrit Uitslag * @param string $user 6542ea7f44SGerrit Uitslag * @param int $level see also inc/auth.php 66dd87735dSAndreas Gohr * @throws AccessDeniedException 6742ea7f44SGerrit Uitslag * @return bool 6842ea7f44SGerrit Uitslag */ 69a4e3d556SAndreas Gohr public function addAcl($scope, $user, $level) 70a4e3d556SAndreas Gohr { 719cbf80e6SAndreas Gohr if (!auth_isadmin()) { 72dd87735dSAndreas Gohr throw new AccessDeniedException( 7364159a61SAndreas Gohr 'You are not allowed to access ACLs, superuser permission is required', 7464159a61SAndreas Gohr 114 7564159a61SAndreas Gohr ); 769cbf80e6SAndreas Gohr } 779cbf80e6SAndreas Gohr 7859bc3b48SGerrit Uitslag /** @var admin_plugin_acl $apa */ 791b7fc214SMohamed Amine BERGAOUI $apa = plugin_load('admin', 'acl'); 8055cc5b99SAndreas Gohr return $apa->addOrUpdateACL($scope, $user, $level); 819f8068d2SMohamed Amine BERGAOUI } 829f8068d2SMohamed Amine BERGAOUI 8342ea7f44SGerrit Uitslag /** 8442ea7f44SGerrit Uitslag * Remove an entry from ACL config 8542ea7f44SGerrit Uitslag * 8642ea7f44SGerrit Uitslag * @param string $scope 8742ea7f44SGerrit Uitslag * @param string $user 88dd87735dSAndreas Gohr * @throws AccessDeniedException 8942ea7f44SGerrit Uitslag * @return bool 9042ea7f44SGerrit Uitslag */ 91a4e3d556SAndreas Gohr public function delAcl($scope, $user) 92a4e3d556SAndreas Gohr { 939cbf80e6SAndreas Gohr if (!auth_isadmin()) { 94dd87735dSAndreas Gohr throw new AccessDeniedException( 9564159a61SAndreas Gohr 'You are not allowed to access ACLs, superuser permission is required', 9664159a61SAndreas Gohr 114 9764159a61SAndreas Gohr ); 989cbf80e6SAndreas Gohr } 999cbf80e6SAndreas Gohr 10059bc3b48SGerrit Uitslag /** @var admin_plugin_acl $apa */ 1011b7fc214SMohamed Amine BERGAOUI $apa = plugin_load('admin', 'acl'); 102a4e3d556SAndreas Gohr return $apa->deleteACL($scope, $user); 1039f8068d2SMohamed Amine BERGAOUI } 1049f8068d2SMohamed Amine BERGAOUI} 105