Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace tool_dataprivacy\external;
18
 
19
use core_external\external_api;
20
use core_external\external_function_parameters;
21
use core_external\external_single_structure;
22
use core_external\external_value;
23
use core_external\external_warnings;
24
use tool_dataprivacy\api;
25
 
26
/**
27
 * External function for retrieving access (permissions) information for the privacy API.
28
 *
29
 * @package    tool_dataprivacy
30
 * @copyright  2023 Juan Leyva <juan@moodle.com>
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 * @since      Moodle 4.4
33
 */
34
class get_access_information extends external_api {
35
 
36
    /**
37
     * Webservice parameters.
38
     *
39
     * @return external_function_parameters
40
     */
41
    public static function execute_parameters(): external_function_parameters {
42
        return new external_function_parameters([]);
43
    }
44
 
45
    /**
46
     * Main method of the external function.
47
     *
48
     * @return array current user permissions
49
     */
50
    public static function execute(): array {
51
        global $USER;
52
 
53
        $system = \context_system::instance();
54
        external_api::validate_context($system);
55
 
56
        return [
57
            'cancontactdpo' => api::can_contact_dpo(),
58
            'canmanagedatarequests' => api::can_manage_data_requests($USER->id),
59
            'cancreatedatadownloadrequest' => api::can_create_data_download_request_for_self($USER->id),
60
            'cancreatedatadeletionrequest' => api::can_create_data_deletion_request_for_self($USER->id),
61
            'hasongoingdatadownloadrequest' => api::has_ongoing_request($USER->id, api::DATAREQUEST_TYPE_EXPORT),
62
            'hasongoingdatadeletionrequest' => api::has_ongoing_request($USER->id, api::DATAREQUEST_TYPE_DELETE),
63
            'warnings' => [],
64
        ];
65
    }
66
 
67
    /**
68
     * Webservice returns.
69
     *
70
     * @return external_single_structure
71
     */
72
    public static function execute_returns(): external_single_structure {
73
        return new external_single_structure(
74
            [
75
                'cancontactdpo' => new external_value(PARAM_BOOL, 'Can contact dpo.'),
76
                'canmanagedatarequests' => new external_value(PARAM_BOOL, 'Can manage data requests.'),
77
                'cancreatedatadownloadrequest' => new external_value(PARAM_BOOL, 'Can create data download request for self.'),
78
                'cancreatedatadeletionrequest' => new external_value(PARAM_BOOL, 'Can create data deletion request for self.'),
79
                'hasongoingdatadownloadrequest' => new external_value(PARAM_BOOL, 'Has ongoing data download request.'),
80
                'hasongoingdatadeletionrequest' => new external_value(PARAM_BOOL, 'Has ongoing data deletion request.'),
81
                'warnings' => new external_warnings(),
82
            ]
83
        );
84
    }
85
}