xref: /dokuwiki/lib/plugins/acl/remote.php (revision dd87735d917b53fa3e3ac66675834419ed24f832)
19f8068d2SMohamed Amine BERGAOUI<?php
29f8068d2SMohamed Amine BERGAOUI
3*dd87735dSAndreas Gohruse dokuwiki\Remote\AccessDeniedException;
4*dd87735dSAndreas Gohr
542ea7f44SGerrit Uitslag/**
642ea7f44SGerrit Uitslag * Class remote_plugin_acl
742ea7f44SGerrit Uitslag */
89f8068d2SMohamed Amine BERGAOUIclass remote_plugin_acl extends DokuWiki_Remote_Plugin {
942ea7f44SGerrit Uitslag
1042ea7f44SGerrit Uitslag    /**
1142ea7f44SGerrit Uitslag     * Returns details about the remote plugin methods
1242ea7f44SGerrit Uitslag     *
13*dd87735dSAndreas Gohr     * @return array Information about all provided methods. {@see dokuwiki\Remote\RemoteAPI}
1442ea7f44SGerrit Uitslag     */
1542ea7f44SGerrit Uitslag    public function _getMethods() {
169f8068d2SMohamed Amine BERGAOUI        return array(
176d2588b6SCyril Duchon-Doris            'listAcls' => array(
186d2588b6SCyril Duchon-Doris                'args' => array(),
196d2588b6SCyril Duchon-Doris                'return' => 'Array of ACLs {scope, user, permission}',
2032b2e368SDharmik                'name' => 'listAcls',
211fa1d6bcSCyril Duchon-Doris                'doc' => 'Get the list of all ACLs',
221fa1d6bcSCyril Duchon-Doris            ),'addAcl' => array(
239f8068d2SMohamed Amine BERGAOUI                'args' => array('string','string','int'),
249f8068d2SMohamed Amine BERGAOUI                'return' => 'int',
259f8068d2SMohamed Amine BERGAOUI                'name' => 'addAcl',
269f8068d2SMohamed Amine BERGAOUI                'doc' => 'Adds a new ACL rule.'
271b7fc214SMohamed Amine BERGAOUI            ), 'delAcl' => array(
289f8068d2SMohamed Amine BERGAOUI                'args' => array('string','string'),
299f8068d2SMohamed Amine BERGAOUI                'return' => 'int',
309f8068d2SMohamed Amine BERGAOUI                'name' => 'delAcl',
319f8068d2SMohamed Amine BERGAOUI                'doc' => 'Delete an existing ACL rule.'
329f8068d2SMohamed Amine BERGAOUI            ),
339f8068d2SMohamed Amine BERGAOUI        );
349f8068d2SMohamed Amine BERGAOUI    }
359f8068d2SMohamed Amine BERGAOUI
3642ea7f44SGerrit Uitslag    /**
376d2588b6SCyril Duchon-Doris     * List all ACL config entries
386d2588b6SCyril Duchon-Doris     *
39*dd87735dSAndreas Gohr     * @throws AccessDeniedException
4042f3fd0aSCyril Duchon-Doris     * @return dictionary {Scope: ACL}, where ACL = dictionnary {user/group: permissions_int}
416d2588b6SCyril Duchon-Doris     */
426d2588b6SCyril Duchon-Doris    public function listAcls(){
4342f3fd0aSCyril Duchon-Doris        if(!auth_isadmin()) {
44*dd87735dSAndreas Gohr         throw new AccessDeniedException(
4564159a61SAndreas Gohr             'You are not allowed to access ACLs, superuser permission is required',
4664159a61SAndreas Gohr             114
4764159a61SAndreas Gohr         );
4842f3fd0aSCyril Duchon-Doris        }
496d2588b6SCyril Duchon-Doris        /** @var admin_plugin_acl $apa */
506d2588b6SCyril Duchon-Doris        $apa = plugin_load('admin', 'acl');
5142f3fd0aSCyril Duchon-Doris        $apa->_init_acl_config();
5242f3fd0aSCyril Duchon-Doris        return $apa->acl;
536d2588b6SCyril Duchon-Doris    }
546d2588b6SCyril Duchon-Doris
556d2588b6SCyril Duchon-Doris    /**
5642ea7f44SGerrit Uitslag     * Add a new entry to ACL config
5742ea7f44SGerrit Uitslag     *
5842ea7f44SGerrit Uitslag     * @param string $scope
5942ea7f44SGerrit Uitslag     * @param string $user
6042ea7f44SGerrit Uitslag     * @param int    $level see also inc/auth.php
61*dd87735dSAndreas Gohr     * @throws AccessDeniedException
6242ea7f44SGerrit Uitslag     * @return bool
6342ea7f44SGerrit Uitslag     */
6442ea7f44SGerrit Uitslag    public function addAcl($scope, $user, $level){
659cbf80e6SAndreas Gohr        if(!auth_isadmin()) {
66*dd87735dSAndreas Gohr            throw new AccessDeniedException(
6764159a61SAndreas Gohr                'You are not allowed to access ACLs, superuser permission is required',
6864159a61SAndreas Gohr                114
6964159a61SAndreas Gohr            );
709cbf80e6SAndreas Gohr        }
719cbf80e6SAndreas Gohr
7259bc3b48SGerrit Uitslag        /** @var admin_plugin_acl $apa */
731b7fc214SMohamed Amine BERGAOUI        $apa = plugin_load('admin', 'acl');
749f8068d2SMohamed Amine BERGAOUI        return $apa->_acl_add($scope, $user, $level);
759f8068d2SMohamed Amine BERGAOUI    }
769f8068d2SMohamed Amine BERGAOUI
7742ea7f44SGerrit Uitslag    /**
7842ea7f44SGerrit Uitslag     * Remove an entry from ACL config
7942ea7f44SGerrit Uitslag     *
8042ea7f44SGerrit Uitslag     * @param string $scope
8142ea7f44SGerrit Uitslag     * @param string $user
82*dd87735dSAndreas Gohr     * @throws AccessDeniedException
8342ea7f44SGerrit Uitslag     * @return bool
8442ea7f44SGerrit Uitslag     */
8542ea7f44SGerrit Uitslag    public function delAcl($scope, $user){
869cbf80e6SAndreas Gohr        if(!auth_isadmin()) {
87*dd87735dSAndreas Gohr            throw new AccessDeniedException(
8864159a61SAndreas Gohr                'You are not allowed to access ACLs, superuser permission is required',
8964159a61SAndreas Gohr                114
9064159a61SAndreas Gohr            );
919cbf80e6SAndreas Gohr        }
929cbf80e6SAndreas Gohr
9359bc3b48SGerrit Uitslag        /** @var admin_plugin_acl $apa */
941b7fc214SMohamed Amine BERGAOUI        $apa = plugin_load('admin', 'acl');
959f8068d2SMohamed Amine BERGAOUI        return $apa->_acl_del($scope, $user);
969f8068d2SMohamed Amine BERGAOUI    }
979f8068d2SMohamed Amine BERGAOUI}
989f8068d2SMohamed Amine BERGAOUI
99