Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add team resource providers capability #1839

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lib/AppInfo/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@

namespace OCA\Circles\AppInfo;

use OC\AppFramework\Bootstrap\Coordinator;
use OC\AppFramework\Bootstrap\ServiceRegistration;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\InterfaceService;
use OCP\App\IAppManager;
use OCP\Capabilities\ICapability;
use OCP\IL10N;
use OCP\Teams\ITeamResourceProvider;
use Psr\Container\ContainerInterface;

class Capabilities implements ICapability {
public function __construct(
private IL10N $l10n,
private IAppManager $appManager,
private InterfaceService $interfaceService,
private ConfigService $configService,
private Coordinator $coordinator,
Pytal marked this conversation as resolved.
Show resolved Hide resolved
private ContainerInterface $container,
) {
}

Expand All @@ -33,7 +39,8 @@ public function getCapabilities(bool $complete = false): array {
'status' => $this->getCapabilitiesStatus($complete),
'settings' => $this->configService->getSettings(),
'circle' => $this->getCapabilitiesCircle(),
'member' => $this->getCapabilitiesMember()
'member' => $this->getCapabilitiesMember(),
'teamResourceProviders' => $this->getCapabilitiesTeamResourceProviders(),
],
];
}
Expand Down Expand Up @@ -143,4 +150,23 @@ private function getCapabilitiesMemberConstants(): array {
]
];
}

/**
* @return string[]
*/
private function getCapabilitiesTeamResourceProviders() {
$providers = $this->coordinator->getRegistrationContext()?->getTeamResourceProviders();
if ($providers === null) {
return [];
}
$providerIds = array_map(
function (ServiceRegistration $registration) {
/** @var ITeamResourceProvider $provider */
$provider = $this->container->get($registration->getService());
return $provider->getId();
},
$providers,
);
return $providerIds;
}
}
31 changes: 31 additions & 0 deletions tests/stub.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -1073,3 +1073,34 @@ namespace OC\Share20 {
public function getHideDownload(): bool;
}
}

namespace OC\AppFramework\Bootstrap {
use OCP\Teams\ITeamResourceProvider;

class Coordinator {
public function getRegistrationContext(): ?RegistrationContext {}
}

class RegistrationContext {
/**
* @return ServiceRegistration<ITeamResourceProvider>[]
*/
public function getTeamResourceProviders(): array {}
}

/**
* @psalm-immutable
* @template T
*/
class ServiceRegistration extends ARegistration {
/**
* @psalm-return class-string<T>
*/
public function getService(): string {}
}

/**
* @psalm-immutable
*/
abstract class ARegistration {}
}
Loading