-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.php
More file actions
89 lines (73 loc) · 2.47 KB
/
Controller.php
File metadata and controls
89 lines (73 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
declare(strict_types=1);
namespace Piwik\Plugins\McpServer;
use Piwik\Access;
use Piwik\Piwik;
use Piwik\SettingsPiwik;
use Piwik\Url;
use Piwik\View;
class Controller extends \Piwik\Plugin\ControllerAdmin
{
public function __construct(private SystemSettings $systemSettings)
{
}
public function connect(): string
{
Piwik::checkUserIsNotAnonymous();
Piwik::checkUserHasSomeViewAccess();
$view = new View('@McpServer/connect');
$this->setBasicVariablesView($view);
$hasSuperUserAccess = Access::getInstance()->hasSuperUserAccess();
$view->assign('isMcpEnabled', $this->systemSettings->isMcpEnabled());
$view->assign('isOAuth2Enabled', $this->systemSettings->isOAuth2PluginEnabled());
$view->assign('canAccessMcpSettings', $hasSuperUserAccess);
$view->assign('canManageOAuth2Clients', $hasSuperUserAccess);
$view->assign('mcpApiEndpoint', $this->getMcpApiEndpointUrl());
$view->assign('mcpSettingsUrl', $this->getMcpSettingsUrl());
$view->assign('oauth2ClientManagementUrl', $this->getOAuth2ClientManagementUrl());
$view->assign('userSecurityUrl', $this->getUserSecurityUrl());
return $view->render();
}
private function getMcpApiEndpointUrl(): string
{
return $this->getBaseUrl() . '/index.php?module=API&method=McpServer.mcp&format=mcp';
}
private function getUserSecurityUrl(): string
{
return $this->buildAdminUrl([
'module' => 'UsersManager',
'action' => 'userSecurity',
]) . '#authtokens';
}
private function getMcpSettingsUrl(): string
{
return $this->buildAdminUrl([
'module' => 'CoreAdminHome',
'action' => 'generalSettings',
]) . '#/McpServer';
}
private function getOAuth2ClientManagementUrl(): string
{
return $this->buildAdminUrl([
'module' => 'OAuth2',
'action' => 'index',
]);
}
/**
* @param array<string, mixed> $parameters
*/
private function buildAdminUrl(array $parameters): string
{
return 'index.php' . Url::getCurrentQueryStringWithParametersModified($parameters);
}
private function getBaseUrl(): string
{
return rtrim((string) SettingsPiwik::getPiwikUrl(), '/');
}
}