2022-05-02 12:44:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-05-18 16:51:34 +00:00
|
|
|
namespace OCA\SCIMServiceProvider\Service;
|
2022-05-02 12:44:40 +00:00
|
|
|
|
|
|
|
use OC\Group\Manager;
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
|
2022-05-18 16:51:34 +00:00
|
|
|
class SCIMGroup {
|
2022-05-02 12:44:40 +00:00
|
|
|
/** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface
|
|
|
|
protected $groupManager;
|
|
|
|
|
2022-05-18 16:51:34 +00:00
|
|
|
public function __construct(IGroupManager $groupManager) {
|
2022-05-02 12:44:40 +00:00
|
|
|
$this->groupManager = $groupManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* creates an object with all group data
|
|
|
|
*
|
|
|
|
* @param string $groupId
|
|
|
|
* @param bool $includeScopes
|
|
|
|
* @return array
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2022-05-18 16:51:34 +00:00
|
|
|
public function get(string $groupId): array {
|
2022-05-02 12:44:40 +00:00
|
|
|
$groupId = urldecode($groupId);
|
|
|
|
|
|
|
|
// Check the group exists
|
|
|
|
$group = $this->groupManager->get($groupId);
|
|
|
|
if ($group === null) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$members = array();
|
|
|
|
foreach ($this->groupManager->get($groupId)->getUsers() as $member) {
|
|
|
|
$members[] = [
|
|
|
|
'value' => $member->getUID(),
|
|
|
|
'$ref' => '/Users/' . $member->getUID(),
|
|
|
|
'display' => $member->getDisplayName()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
2022-05-18 14:28:05 +00:00
|
|
|
'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:Group'],
|
|
|
|
'id' => $groupId,
|
2022-05-02 12:44:40 +00:00
|
|
|
'displayName' => $group->getDisplayName(),
|
|
|
|
'externalId' => '1234', // todo
|
|
|
|
'meta' => [
|
|
|
|
'resourceType' => 'Group',
|
|
|
|
'location' => '/Groups/' . $groupId,
|
|
|
|
'created' => '2022-04-28T18:27:17.783Z', // todo
|
|
|
|
'lastModified' => '2022-04-28T18:27:17.783Z' // todo
|
|
|
|
],
|
2022-05-18 14:28:05 +00:00
|
|
|
'members' => $members
|
|
|
|
];
|
2022-05-02 12:44:40 +00:00
|
|
|
}
|
|
|
|
}
|