Skip to content

Commit

Permalink
Fix OCM notification provider selection
Browse files Browse the repository at this point in the history
  • Loading branch information
smesterheide committed Jan 11, 2023
1 parent 77ad56f commit 016ff53
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,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($notificationType, $resourceType, $providerId, array $notification) {

// check if all required parameters are set
if ($notificationType === null ||
Expand All @@ -254,7 +254,11 @@ public function receiveNotification($notificationType, $resourceType, $providerI
}

try {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
if ($notification['shareType']) {
$provider = $this->cloudFederationProviderManager->getCloudFederationProviderForShareType($resourceType, $notification['shareType']);
} else {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
}
$result = $provider->notificationReceived($notificationType, $providerId, $notification);
} catch (ProviderDoesNotExistsException $e) {
return new JSONResponse(
Expand Down
22 changes: 17 additions & 5 deletions lib/private/Federation/CloudFederationProviderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,22 @@ public function getCloudFederationProvider($resourceType) {
}

/**
* get a specific cloud federation provider for a given federation share
*
* @param ICloudFederationShare $share
* @return ICloudFederationProvider
* @throws ProviderDoesNotExistsException
* @inheritdoc
*/
public function getCloudFederationProviderForShareType($resourceType, $shareType) {
foreach ($this->cloudFederationProvider as $provider) {
if ($provider['resourceType'] === $resourceType &&
isset($provider['supportedShareTypes']) &&
in_array($shareType, $provider['supportedShareTypes'])) {
return call_user_func($provider['callback']);
}
}

return $this->getCloudFederationProvider($resourceType);
}

/**
* @inheritdoc
*/
public function getCloudFederationProviderForFederationShare(ICloudFederationShare $share) {
$shareType = $share->getShareType();
Expand All @@ -174,6 +185,7 @@ public function getCloudFederationProviderForFederationShare(ICloudFederationSha

return $this->getCloudFederationProvider($resourceType);
}

public function sendShare(ICloudFederationShare $share) {
if ($share->getShareType() === 'federated_group') {
$isUserHint = false;
Expand Down
12 changes: 12 additions & 0 deletions lib/public/Federation/ICloudFederationProviderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public function getAllCloudFederationProviders();
*/
public function getCloudFederationProvider($resourceType);

/**
* get a specific cloud federation provider for share type
*
* @param string $resourceType
* @param string $shareType
* @return ICloudFederationProvider
* @throws Exceptions\ProviderDoesNotExistsException
*
* @since 26.0.0
*/
public function getCloudFederationProviderForShareType($resourceType, $shareType);

/**
* get a specific cloud federation provider for a given federation share
*
Expand Down

0 comments on commit 016ff53

Please sign in to comment.