Completed
Push — master ( 6f68ab...8d6a0a )
by Stefano
15s queued 12s
created

EndpointPermissionsController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2022 Atlas Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
namespace App\Controller\Admin;
14
15
use Cake\Http\Response;
16
use Cake\Utility\Hash;
17
18
/**
19
 * Permissions Controller
20
 *
21
 * @property \App\Controller\Component\PropertiesComponent $Properties
22
 */
23
class EndpointPermissionsController extends AdministrationBaseController
24
{
25
    /**
26
     * Resource type in use
27
     *
28
     * @var string
29
     */
30
    protected $resourceType = 'endpoint_permissions';
31
32
    /**
33
     * @inheritDoc
34
     */
35
    protected $readonly = false;
36
37
    /**
38
     * @inheritDoc
39
     */
40
    protected $properties = [
41
        'endpoint_id' => 'endpoints',
42
        'application_id' => 'applications',
43
        'role_id' => 'roles',
44
        'read' => 'bool',
45
        'write' => 'bool',
46
    ];
47
48
    /**
49
     * Index method
50
     *
51
     * @return \Cake\Http\Response|null
52
     */
53
    public function index(): ?Response
54
    {
55
        parent::index();
56
        $applications = $this->apiClient->get('/admin/applications', []);
57
        $this->set('applications', (array)Hash::combine((array)$applications, 'data.{n}.id', 'data.{n}.attributes.name'));
58
        $endpoints = $this->apiClient->get('/admin/endpoints', []);
59
        $this->set('endpoints', (array)Hash::combine((array)$endpoints, 'data.{n}.id', 'data.{n}.attributes.name'));
60
        $roles = $this->apiClient->get('/roles', []);
61
        $this->set('roles', (array)Hash::combine((array)$roles, 'data.{n}.id', 'data.{n}.attributes.name'));
62
63
        return null;
64
    }
65
}
66