xref: /dokuwiki/lib/plugins/acl/remote.php (revision 55cc5b999d5e659fe30cd52ddad4a3f0dea44474)
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    {
189f8068d2SMohamed Amine BERGAOUI        return array(
196d2588b6SCyril Duchon-Doris            'listAcls' => array(
206d2588b6SCyril Duchon-Doris                'args' => array(),
216d2588b6SCyril Duchon-Doris                'return' => 'Array of ACLs {scope, user, permission}',
2232b2e368SDharmik                'name' => 'listAcls',
231fa1d6bcSCyril Duchon-Doris                'doc' => 'Get the list of all ACLs',
241fa1d6bcSCyril Duchon-Doris            ),'addAcl' => array(
259f8068d2SMohamed Amine BERGAOUI                'args' => array('string','string','int'),
269f8068d2SMohamed Amine BERGAOUI                'return' => 'int',
279f8068d2SMohamed Amine BERGAOUI                'name' => 'addAcl',
289f8068d2SMohamed Amine BERGAOUI                'doc' => 'Adds a new ACL rule.'
291b7fc214SMohamed Amine BERGAOUI            ), 'delAcl' => array(
309f8068d2SMohamed Amine BERGAOUI                'args' => array('string','string'),
319f8068d2SMohamed Amine BERGAOUI                'return' => 'int',
329f8068d2SMohamed Amine BERGAOUI                'name' => 'delAcl',
339f8068d2SMohamed Amine BERGAOUI                'doc' => 'Delete an existing ACL rule.'
349f8068d2SMohamed Amine BERGAOUI            ),
359f8068d2SMohamed Amine BERGAOUI        );
369f8068d2SMohamed Amine BERGAOUI    }
379f8068d2SMohamed Amine BERGAOUI
3842ea7f44SGerrit Uitslag    /**
396d2588b6SCyril Duchon-Doris     * List all ACL config entries
406d2588b6SCyril Duchon-Doris     *
41dd87735dSAndreas Gohr     * @throws AccessDeniedException
4242f3fd0aSCyril Duchon-Doris     * @return dictionary {Scope: ACL}, where ACL = dictionnary {user/group: permissions_int}
436d2588b6SCyril Duchon-Doris     */
44a4e3d556SAndreas Gohr    public function listAcls()
45a4e3d556SAndreas Gohr    {
4642f3fd0aSCyril Duchon-Doris        if (!auth_isadmin()) {
47dd87735dSAndreas Gohr            throw new AccessDeniedException(
4864159a61SAndreas Gohr                'You are not allowed to access ACLs, superuser permission is required',
4964159a61SAndreas Gohr                114
5064159a61SAndreas Gohr            );
5142f3fd0aSCyril Duchon-Doris        }
526d2588b6SCyril Duchon-Doris        /** @var admin_plugin_acl $apa */
536d2588b6SCyril Duchon-Doris        $apa = plugin_load('admin', 'acl');
54a4e3d556SAndreas Gohr        $apa->initAclConfig();
5542f3fd0aSCyril Duchon-Doris        return $apa->acl;
566d2588b6SCyril Duchon-Doris    }
576d2588b6SCyril Duchon-Doris
586d2588b6SCyril Duchon-Doris    /**
5942ea7f44SGerrit Uitslag     * Add a new entry to ACL config
6042ea7f44SGerrit Uitslag     *
6142ea7f44SGerrit Uitslag     * @param string $scope
6242ea7f44SGerrit Uitslag     * @param string $user
6342ea7f44SGerrit Uitslag     * @param int    $level see also inc/auth.php
64dd87735dSAndreas Gohr     * @throws AccessDeniedException
6542ea7f44SGerrit Uitslag     * @return bool
6642ea7f44SGerrit Uitslag     */
67a4e3d556SAndreas Gohr    public function addAcl($scope, $user, $level)
68a4e3d556SAndreas Gohr    {
699cbf80e6SAndreas Gohr        if (!auth_isadmin()) {
70dd87735dSAndreas Gohr            throw new AccessDeniedException(
7164159a61SAndreas Gohr                'You are not allowed to access ACLs, superuser permission is required',
7264159a61SAndreas Gohr                114
7364159a61SAndreas Gohr            );
749cbf80e6SAndreas Gohr        }
759cbf80e6SAndreas Gohr
7659bc3b48SGerrit Uitslag        /** @var admin_plugin_acl $apa */
771b7fc214SMohamed Amine BERGAOUI        $apa = plugin_load('admin', 'acl');
78*55cc5b99SAndreas Gohr        return $apa->addOrUpdateACL($scope, $user, $level);
799f8068d2SMohamed Amine BERGAOUI    }
809f8068d2SMohamed Amine BERGAOUI
8142ea7f44SGerrit Uitslag    /**
8242ea7f44SGerrit Uitslag     * Remove an entry from ACL config
8342ea7f44SGerrit Uitslag     *
8442ea7f44SGerrit Uitslag     * @param string $scope
8542ea7f44SGerrit Uitslag     * @param string $user
86dd87735dSAndreas Gohr     * @throws AccessDeniedException
8742ea7f44SGerrit Uitslag     * @return bool
8842ea7f44SGerrit Uitslag     */
89a4e3d556SAndreas Gohr    public function delAcl($scope, $user)
90a4e3d556SAndreas Gohr    {
919cbf80e6SAndreas Gohr        if (!auth_isadmin()) {
92dd87735dSAndreas Gohr            throw new AccessDeniedException(
9364159a61SAndreas Gohr                'You are not allowed to access ACLs, superuser permission is required',
9464159a61SAndreas Gohr                114
9564159a61SAndreas Gohr            );
969cbf80e6SAndreas Gohr        }
979cbf80e6SAndreas Gohr
9859bc3b48SGerrit Uitslag        /** @var admin_plugin_acl $apa */
991b7fc214SMohamed Amine BERGAOUI        $apa = plugin_load('admin', 'acl');
100a4e3d556SAndreas Gohr        return $apa->deleteACL($scope, $user);
1019f8068d2SMohamed Amine BERGAOUI    }
1029f8068d2SMohamed Amine BERGAOUI}
103