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