xref: /dokuwiki/lib/plugins/acl/remote.php (revision 42f3fd0a1f28a8efb7f4f490312d58ddc2b1b8f5)
19f8068d2SMohamed Amine BERGAOUI<?php
29f8068d2SMohamed Amine BERGAOUI
342ea7f44SGerrit Uitslag/**
442ea7f44SGerrit Uitslag * Class remote_plugin_acl
542ea7f44SGerrit Uitslag */
69f8068d2SMohamed Amine BERGAOUIclass remote_plugin_acl extends DokuWiki_Remote_Plugin {
742ea7f44SGerrit Uitslag
842ea7f44SGerrit Uitslag    /**
942ea7f44SGerrit Uitslag     * Returns details about the remote plugin methods
1042ea7f44SGerrit Uitslag     *
1142ea7f44SGerrit Uitslag     * @return array
1242ea7f44SGerrit Uitslag     */
1342ea7f44SGerrit Uitslag    public function _getMethods() {
149f8068d2SMohamed Amine BERGAOUI        return array(
156d2588b6SCyril Duchon-Doris            'listAcls' => array(
166d2588b6SCyril Duchon-Doris                'args' => array(),
176d2588b6SCyril Duchon-Doris                'return' => 'Array of ACLs {scope, user, permission}',
186d2588b6SCyril Duchon-Doris                'name' => 'listAcl',
191fa1d6bcSCyril Duchon-Doris                'doc' => 'Get the list of all ACLs',
201fa1d6bcSCyril Duchon-Doris            ),'addAcl' => array(
219f8068d2SMohamed Amine BERGAOUI                'args' => array('string','string','int'),
229f8068d2SMohamed Amine BERGAOUI                'return' => 'int',
239f8068d2SMohamed Amine BERGAOUI                'name' => 'addAcl',
249f8068d2SMohamed Amine BERGAOUI                'doc' => 'Adds a new ACL rule.'
251b7fc214SMohamed Amine BERGAOUI            ), 'delAcl' => array(
269f8068d2SMohamed Amine BERGAOUI                'args' => array('string','string'),
279f8068d2SMohamed Amine BERGAOUI                'return' => 'int',
289f8068d2SMohamed Amine BERGAOUI                'name' => 'delAcl',
299f8068d2SMohamed Amine BERGAOUI                'doc' => 'Delete an existing ACL rule.'
309f8068d2SMohamed Amine BERGAOUI            ),
319f8068d2SMohamed Amine BERGAOUI        );
329f8068d2SMohamed Amine BERGAOUI    }
339f8068d2SMohamed Amine BERGAOUI
3442ea7f44SGerrit Uitslag    /**
356d2588b6SCyril Duchon-Doris     * List all ACL config entries
366d2588b6SCyril Duchon-Doris     *
37*42f3fd0aSCyril Duchon-Doris     * @throws RemoteAccessDeniedException
38*42f3fd0aSCyril Duchon-Doris     * @return dictionary {Scope: ACL}, where ACL = dictionnary {user/group: permissions_int}
396d2588b6SCyril Duchon-Doris     */
406d2588b6SCyril Duchon-Doris    public function listAcls(){
41*42f3fd0aSCyril Duchon-Doris        if(!auth_isadmin()) {
42*42f3fd0aSCyril Duchon-Doris         throw new RemoteAccessDeniedException('You are not allowed to access ACLs, superuser permission is required', 114);
43*42f3fd0aSCyril Duchon-Doris        }
446d2588b6SCyril Duchon-Doris        /** @var admin_plugin_acl $apa */
456d2588b6SCyril Duchon-Doris        $apa = plugin_load('admin', 'acl');
46*42f3fd0aSCyril Duchon-Doris        $apa->_init_acl_config();
47*42f3fd0aSCyril Duchon-Doris        return $apa->acl;
486d2588b6SCyril Duchon-Doris    }
496d2588b6SCyril Duchon-Doris
506d2588b6SCyril Duchon-Doris    /**
5142ea7f44SGerrit Uitslag     * Add a new entry to ACL config
5242ea7f44SGerrit Uitslag     *
5342ea7f44SGerrit Uitslag     * @param string $scope
5442ea7f44SGerrit Uitslag     * @param string $user
5542ea7f44SGerrit Uitslag     * @param int    $level see also inc/auth.php
5642ea7f44SGerrit Uitslag     * @return bool
5742ea7f44SGerrit Uitslag     */
5842ea7f44SGerrit Uitslag    public function addAcl($scope, $user, $level){
5959bc3b48SGerrit Uitslag        /** @var admin_plugin_acl $apa */
601b7fc214SMohamed Amine BERGAOUI        $apa = plugin_load('admin', 'acl');
619f8068d2SMohamed Amine BERGAOUI        return $apa->_acl_add($scope, $user, $level);
629f8068d2SMohamed Amine BERGAOUI    }
639f8068d2SMohamed Amine BERGAOUI
6442ea7f44SGerrit Uitslag    /**
6542ea7f44SGerrit Uitslag     * Remove an entry from ACL config
6642ea7f44SGerrit Uitslag     *
6742ea7f44SGerrit Uitslag     * @param string $scope
6842ea7f44SGerrit Uitslag     * @param string $user
6942ea7f44SGerrit Uitslag     * @return bool
7042ea7f44SGerrit Uitslag     */
7142ea7f44SGerrit Uitslag    public function delAcl($scope, $user){
7259bc3b48SGerrit Uitslag        /** @var admin_plugin_acl $apa */
731b7fc214SMohamed Amine BERGAOUI        $apa = plugin_load('admin', 'acl');
749f8068d2SMohamed Amine BERGAOUI        return $apa->_acl_del($scope, $user);
759f8068d2SMohamed Amine BERGAOUI    }
769f8068d2SMohamed Amine BERGAOUI}
779f8068d2SMohamed Amine BERGAOUI
78