Skip to content

Commit 3d338f1

Browse files
authored
Merge pull request #1839 from nextcloud/feat/team-resources-capability
feat: Add team resource providers capability
2 parents 58897f8 + fab4260 commit 3d338f1

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

lib/AppInfo/Capabilities.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,26 @@
99

1010
namespace OCA\Circles\AppInfo;
1111

12+
use OC\AppFramework\Bootstrap\Coordinator;
13+
use OC\AppFramework\Bootstrap\ServiceRegistration;
1214
use OCA\Circles\Model\Circle;
1315
use OCA\Circles\Model\Member;
1416
use OCA\Circles\Service\ConfigService;
1517
use OCA\Circles\Service\InterfaceService;
1618
use OCP\App\IAppManager;
1719
use OCP\Capabilities\ICapability;
1820
use OCP\IL10N;
21+
use OCP\Teams\ITeamResourceProvider;
22+
use Psr\Container\ContainerInterface;
1923

2024
class Capabilities implements ICapability {
2125
public function __construct(
2226
private IL10N $l10n,
2327
private IAppManager $appManager,
2428
private InterfaceService $interfaceService,
2529
private ConfigService $configService,
30+
private Coordinator $coordinator,
31+
private ContainerInterface $container,
2632
) {
2733
}
2834

@@ -33,7 +39,8 @@ public function getCapabilities(bool $complete = false): array {
3339
'status' => $this->getCapabilitiesStatus($complete),
3440
'settings' => $this->configService->getSettings(),
3541
'circle' => $this->getCapabilitiesCircle(),
36-
'member' => $this->getCapabilitiesMember()
42+
'member' => $this->getCapabilitiesMember(),
43+
'teamResourceProviders' => $this->getCapabilitiesTeamResourceProviders(),
3744
],
3845
];
3946
}
@@ -143,4 +150,23 @@ private function getCapabilitiesMemberConstants(): array {
143150
]
144151
];
145152
}
153+
154+
/**
155+
* @return string[]
156+
*/
157+
private function getCapabilitiesTeamResourceProviders() {
158+
$providers = $this->coordinator->getRegistrationContext()?->getTeamResourceProviders();
159+
if ($providers === null) {
160+
return [];
161+
}
162+
$providerIds = array_map(
163+
function (ServiceRegistration $registration) {
164+
/** @var ITeamResourceProvider $provider */
165+
$provider = $this->container->get($registration->getService());
166+
return $provider->getId();
167+
},
168+
$providers,
169+
);
170+
return $providerIds;
171+
}
146172
}

tests/stub.phpstub

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,3 +1073,34 @@ namespace OC\Share20 {
10731073
public function getHideDownload(): bool;
10741074
}
10751075
}
1076+
1077+
namespace OC\AppFramework\Bootstrap {
1078+
use OCP\Teams\ITeamResourceProvider;
1079+
1080+
class Coordinator {
1081+
public function getRegistrationContext(): ?RegistrationContext {}
1082+
}
1083+
1084+
class RegistrationContext {
1085+
/**
1086+
* @return ServiceRegistration<ITeamResourceProvider>[]
1087+
*/
1088+
public function getTeamResourceProviders(): array {}
1089+
}
1090+
1091+
/**
1092+
* @psalm-immutable
1093+
* @template T
1094+
*/
1095+
class ServiceRegistration extends ARegistration {
1096+
/**
1097+
* @psalm-return class-string<T>
1098+
*/
1099+
public function getService(): string {}
1100+
}
1101+
1102+
/**
1103+
* @psalm-immutable
1104+
*/
1105+
abstract class ARegistration {}
1106+
}

0 commit comments

Comments
 (0)