Refactor Entra module to remove calendar retrieval and update user endpoint
This commit is contained in:
@@ -23,35 +23,6 @@ class entra
|
||||
$this->config = new entra_c();
|
||||
}
|
||||
|
||||
public function get_calendars(): array|object
|
||||
{
|
||||
// List all the user calendars
|
||||
$graphClient = $this->getGraphClient();
|
||||
$calendars = $graphClient->Calendars()
|
||||
->get()
|
||||
->wait()
|
||||
->getValue();
|
||||
//TODO: This does not work, need to find a way to get the calendars
|
||||
$result = [];
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getGraphClient(): GraphServiceClient
|
||||
{
|
||||
return new GraphServiceClient(
|
||||
$this->getTokenRequestContext(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getTokenRequestContext(): ClientCredentialContext
|
||||
{
|
||||
return new ClientCredentialContext(
|
||||
$this->config->tenant_id->getVariableValue(),
|
||||
$this->config->client_id->getVariableValue(),
|
||||
$this->config->client_secret->getVariableValue()
|
||||
);
|
||||
}
|
||||
|
||||
public function get_users($array = false): array|object
|
||||
{
|
||||
$graphClient = $this->getGraphClient();
|
||||
@@ -74,4 +45,20 @@ class entra
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getGraphClient(): GraphServiceClient
|
||||
{
|
||||
return new GraphServiceClient(
|
||||
$this->getTokenRequestContext(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getTokenRequestContext(): ClientCredentialContext
|
||||
{
|
||||
return new ClientCredentialContext(
|
||||
$this->config->tenant_id->getVariableValue(),
|
||||
$this->config->client_id->getVariableValue(),
|
||||
$this->config->client_secret->getVariableValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,21 +19,21 @@ class moduleEntraRoute
|
||||
$router, $response;
|
||||
|
||||
|
||||
/** Modules > Entra > Calendar groups > GET */
|
||||
$this->get('/modules/entra/calendar-groups', function () {
|
||||
/** Modules > Entra > Users > GET */
|
||||
$this->get('/modules/entra/users', function () {
|
||||
global $response;
|
||||
self::requirePermission('modules_entra_calendar_groups');
|
||||
self::requirePermission('modules_entra_users');
|
||||
$user = (new authentication())->get_user();
|
||||
if ($user) {
|
||||
$result = (new \classes\entra())->get_calendars();
|
||||
$result = (new \classes\entra())->get_users();
|
||||
$response->success($result);
|
||||
} else {
|
||||
(new logs_o())->add('modules_entra_calendar_groups', 'global', 1, 0, 'MODULES_ENTRA_CALENDAR_GROUPS', 'User accessed the calendar groups without being logged in');
|
||||
(new logs_o())->add('modules_entra_users', 'global', 1, 0, 'MODULES_ENTRA_users', 'User attempted to access Entra users without being logged in');
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
},
|
||||
[
|
||||
'modules_entra_calendar_groups' => 'List calendar groups',
|
||||
'modules_entra_users' => 'List entra users',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user