Skip to content

Commit

Permalink
Refactor cloud_federation_api app
Browse files Browse the repository at this point in the history
Signed-off-by: Hamid Dehnavi <[email protected]>
  • Loading branch information
shdehnavi committed Jul 7, 2023
1 parent 9bf6911 commit 5f6b9d7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 64 deletions.
11 changes: 4 additions & 7 deletions apps/cloud_federation_api/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@
use OCP\IURLGenerator;

class Capabilities implements ICapability {

/** @var IURLGenerator */
private $urlGenerator;

public function __construct(IURLGenerator $urlGenerator) {
$this->urlGenerator = $urlGenerator;
public function __construct(
private IURLGenerator $urlGenerator,
) {
}

/**
* Function an app uses to return the capabilities
*/
public function getCapabilities() {
public function getCapabilities(): array {
$url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
$capabilities = ['ocm' =>
[
Expand Down
11 changes: 4 additions & 7 deletions apps/cloud_federation_api/lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@
* @package OCA\CloudFederationAPI
*/
class Config {

/** @var ICloudFederationProviderManager */
private $cloudFederationProviderManager;

public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager) {
$this->cloudFederationProviderManager = $cloudFederationProviderManager;
public function __construct(
private ICloudFederationProviderManager $cloudFederationProviderManager,
) {
}

/**
Expand All @@ -47,7 +44,7 @@ public function __construct(ICloudFederationProviderManager $cloudFederationProv
* @param string $resourceType
* @return array
*/
public function getSupportedShareTypes($resourceType) {
public function getSupportedShareTypes(string $resourceType): array {
try {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
return $provider->getSupportedShareTypes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,52 +51,19 @@
* @package OCA\CloudFederationAPI\Controller
*/
class RequestHandlerController extends Controller {

/** @var LoggerInterface */
private $logger;

/** @var IUserManager */
private $userManager;

/** @var IGroupManager */
private $groupManager;

/** @var IURLGenerator */
private $urlGenerator;

/** @var ICloudFederationProviderManager */
private $cloudFederationProviderManager;

/** @var Config */
private $config;

/** @var ICloudFederationFactory */
private $factory;

/** @var ICloudIdManager */
private $cloudIdManager;

public function __construct($appName,
IRequest $request,
LoggerInterface $logger,
IUserManager $userManager,
IGroupManager $groupManager,
IURLGenerator $urlGenerator,
ICloudFederationProviderManager $cloudFederationProviderManager,
Config $config,
ICloudFederationFactory $factory,
ICloudIdManager $cloudIdManager
public function __construct(
$appName,
IRequest $request,
private LoggerInterface $logger,
private IUserManager $userManager,
private IGroupManager $groupManager,
private IURLGenerator $urlGenerator,
private ICloudFederationProviderManager $cloudFederationProviderManager,
private Config $config,
private ICloudFederationFactory $factory,
private ICloudIdManager $cloudIdManager
) {
parent::__construct($appName, $request);

$this->logger = $logger;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->urlGenerator = $urlGenerator;
$this->cloudFederationProviderManager = $cloudFederationProviderManager;
$this->config = $config;
$this->factory = $factory;
$this->cloudIdManager = $cloudIdManager;
}

/**
Expand All @@ -121,8 +88,7 @@ public function __construct($appName,
*
* Example: curl -H "Content-Type: application/json" -X POST -d '{"shareWith":"admin1@serve1","name":"welcome server2.txt","description":"desc","providerId":"2","owner":"admin2@http://localhost/server2","ownerDisplayName":"admin2 display","shareType":"user","resourceType":"file","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://localhost/server/index.php/ocm/shares
*/
public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) {

public function addShare(string $shareWith, string $name, string $description, string $providerId, string $owner, string $ownerDisplayName, string $sharedBy, string $sharedByDisplayName, array $protocol, string $shareType, $resourceType): Http\DataResponse|JSONResponse {
// check if all required parameters are set
if ($shareWith === null ||
$name === null ||
Expand Down Expand Up @@ -234,8 +200,7 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $
* @param array $notification the actual payload of the notification
* @return JSONResponse
*/
public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) {

public function receiveNotification(string $notificationType, string $resourceType, string $providerId, array $notification): JSONResponse {
// check if all required parameters are set
if ($notificationType === null ||
$resourceType === null ||
Expand Down Expand Up @@ -281,7 +246,7 @@ public function receiveNotification($notificationType, $resourceType, $providerI
);
}

return new JSONResponse($result,Http::STATUS_CREATED);
return new JSONResponse($result, Http::STATUS_CREATED);
}

/**
Expand All @@ -290,7 +255,7 @@ public function receiveNotification($notificationType, $resourceType, $providerI
* @param string $uid
* @return string mixed
*/
private function mapUid($uid) {
private function mapUid(string $uid): string {
// FIXME this should be a method in the user management instead
$this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]);
\OCP\Util::emitHook(
Expand Down

0 comments on commit 5f6b9d7

Please sign in to comment.