Skip to content

Commit

Permalink
Accept OCM to groups
Browse files Browse the repository at this point in the history
Signed-off-by: Michiel de Jong <[email protected]>
  • Loading branch information
michielbdejong committed Jan 20, 2023
1 parent 2c1e9d1 commit a1e761e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
28 changes: 28 additions & 0 deletions apps/federatedfilesharing/lib/Controller/OcmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ public function createShare(
$resourceType,
$protocol
) {
// Allow the Federated Groups app to overwrite the behaviour of this endpoint (but only for group shares)
if (\OC::$server->getAppManager()->isEnabledForUser('federatedgroups') && ($shareType === 'group')) {
$controller = \OCA\FederatedGroups\Application::getOcmController($this->request);
return $controller->createShare(
$shareWith,
$name,
$description,
$providerId,
$owner,
$ownerDisplayName,
$sender,
$senderDisplayName,
$shareType,
$resourceType,
$protocol
);
}
try {
$this->ocmMiddleware->assertIncomingSharingEnabled();
$this->ocmMiddleware->assertNotNull(
Expand Down Expand Up @@ -284,6 +301,17 @@ public function processNotification(
$providerId,
$notification
) {
// Allow the Federated Groups app to overwrite the behaviour of this endpoint
if (\OC::$server->getAppManager()->isEnabledForUser('federatedgroups')) {
$controller = \OCA\FederatedGroups\Application::getOcmController($this->request);
return $controller->processNotification(
$notificationType,
$resourceType,
$providerId,
$notification
);
}

try {
if (!\is_array($notification)) {
throw new BadRequestException(
Expand Down
8 changes: 6 additions & 2 deletions apps/files_sharing/js/external.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,20 @@
shares[index],
false,
function(result, share) {
let shareType = "user";
if (share.hasOwnProperty('share_type') ){
shareType = share.share_type;
}
if (result) {
// Accept
$.post(OC.generateUrl('/apps/files_sharing/api/externalShares'), {id: share.id})
$.post(OC.generateUrl('/apps/files_sharing/api/externalShares'), {id: share.id, share_type: shareType })
.then(function() {
fileList.reload();
});
} else {
// Delete
$.ajax({
url: OC.generateUrl('/apps/files_sharing/api/externalShares/'+share.id),
url: OC.generateUrl('/apps/files_sharing/api/externalShares/'+share.id+"?share_type="+shareType),
type: 'DELETE'
});
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/Controller/Share20OcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public function createShare() {
if ($password !== '') {
$share->setPassword($password);
}
} elseif ($shareType === Share::SHARE_TYPE_REMOTE) {
} elseif ($shareType === Share::SHARE_TYPE_REMOTE || $shareType === Share::SHARE_TYPE_REMOTE_GROUP) {
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new Result(null, 403, $this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType]));
Expand Down
29 changes: 23 additions & 6 deletions apps/files_sharing/lib/Controllers/ExternalSharesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@
* @package OCA\Files_Sharing\Controllers
*/
class ExternalSharesController extends Controller {

/** @var \OCA\Files_Sharing\External\Manager */
private $externalManager;
/** @var \OCA\Files_Sharing\External\Manager */
private $groupExternalManager = null;
/** @var IClientService */
private $clientService;
/**
Expand Down Expand Up @@ -68,6 +71,9 @@ public function __construct(
$this->externalManager = $externalManager;
$this->clientService = $clientService;
$this->dispatcher = $eventDispatcher;
if (\OC::$server->getAppManager()->isEnabledForUser('federatedgroups')) {
$this->groupExternalManager = \OCA\FederatedGroups\Application::getExternalManager();
}
}

/**
Expand All @@ -77,7 +83,12 @@ public function __construct(
* @return JSONResponse
*/
public function index() {
return new JSONResponse($this->externalManager->getOpenShares());
$federatedGroupResult = [];
if ($this->groupExternalManager !== null) {
$federatedGroupResult = $this->groupExternalManager->getOpenShares();
}
$result = array_merge($federatedGroupResult, $this->externalManager->getOpenShares());
return new JSONResponse($result);
}

/**
Expand All @@ -87,11 +98,17 @@ public function index() {
* @param int $id
* @return JSONResponse
*/
public function create($id) {
$shareInfo = $this->externalManager->getShare($id);
public function create($id, $share_type) {
if($share_type === "group" && $this->groupExternalManager !== null) {
$manager = $this->groupExternalManager;
} else {
$manager = $this->externalManager;
}
$shareInfo = $manager->getShare($id);

if ($shareInfo !== false) {
$mountPoint = $this->externalManager->getShareRecipientMountPoint($shareInfo);
$fileId = $this->externalManager->getShareFileId($shareInfo, $mountPoint);
$mountPoint = $manager->getShareRecipientMountPoint($shareInfo);
$fileId = $manager->getShareFileId($shareInfo, $mountPoint);

$event = new GenericEvent(
null,
Expand All @@ -105,7 +122,7 @@ public function create($id) {
'shareRecipient' => $shareInfo['user'],
]
);
$this->dispatcher->dispatch($event, 'remoteshare.accepted');
$this->dispatcher->dispatch($event, 'remoteshare.accepted', $event);
$this->externalManager->acceptShare($id);
}
return new JSONResponse();
Expand Down
2 changes: 2 additions & 0 deletions lib/private/Share/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Constants {
public const SHARE_TYPE_GUEST = 4;
public const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it
public const SHARE_TYPE_REMOTE = 6;
public const SHARE_TYPE_REMOTE_GROUP = 7;

public const CONVERT_SHARE_TYPE_TO_STRING = [
self::SHARE_TYPE_USER => 'user',
Expand All @@ -39,6 +40,7 @@ class Constants {
self::SHARE_TYPE_GUEST => 'guest',
self::SHARE_TYPE_CONTACT => 'contact',
self::SHARE_TYPE_REMOTE => 'remote',
self::SHARE_TYPE_REMOTE_GROUP => 'remote_group',
];

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected function generalChecks(\OCP\Share\IShare $share) {
if ($share->getSharedWith() !== null) {
throw new \InvalidArgumentException('SharedWith should be empty');
}
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE || $share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) {
if ($share->getSharedWith() === null) {
throw new \InvalidArgumentException('SharedWith should not be empty');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getProviderForType($shareType) {
$shareType === \OCP\Share::SHARE_TYPE_GROUP ||
$shareType === \OCP\Share::SHARE_TYPE_LINK) {
$provider = $this->defaultShareProvider();
} elseif ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
} elseif ($shareType === \OCP\Share::SHARE_TYPE_REMOTE || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) {
$provider = $this->federatedShareProvider();
}

Expand Down

0 comments on commit a1e761e

Please sign in to comment.