Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Accept OCM to groups
Signed-off-by: Michiel de Jong <[email protected]>
  • Loading branch information
michielbdejong authored and phil-davis committed Jul 17, 2023
commit 698031a0c747eeb1975b576cc378909fdd208362
4 changes: 3 additions & 1 deletion apps/dav/lib/Connector/Sabre/SharesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ private function getSharesForNodeIds($nodeIDs) {
\OCP\Share::SHARE_TYPE_USER,
\OCP\Share::SHARE_TYPE_GROUP,
\OCP\Share::SHARE_TYPE_LINK,
\OCP\Share::SHARE_TYPE_REMOTE
\OCP\Share::SHARE_TYPE_REMOTE,
\OCP\Share::SHARE_TYPE_REMOTE_GROUP

];

// Query DB for share types for specified node IDs
Expand Down
3 changes: 2 additions & 1 deletion apps/federatedfilesharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ function ($c) use ($server) {
$server->getUserManager(),
$c->query('AddressHandler'),
$c->query('FederatedShareManager'),
$server->getLogger()
$server->getLogger(),
$server->getConfig()
);
}
);
Expand Down
26 changes: 25 additions & 1 deletion apps/federatedfilesharing/lib/Controller/OcmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IConfig;
use OCP\Share\Exceptions\ShareNotFound;

/**
* Class OcmController
Expand Down Expand Up @@ -75,6 +77,11 @@ class OcmController extends Controller {
*/
protected $logger;

/**
* @var IConfig
*/
protected $config;

/**
* OcmController constructor.
*
Expand All @@ -86,6 +93,7 @@ class OcmController extends Controller {
* @param AddressHandler $addressHandler
* @param FedShareManager $fedShareManager
* @param ILogger $logger
* @param IConfig $config
*/
public function __construct(
$appName,
Expand All @@ -95,7 +103,8 @@ public function __construct(
IUserManager $userManager,
AddressHandler $addressHandler,
FedShareManager $fedShareManager,
ILogger $logger
ILogger $logger,
IConfig $config
) {
parent::__construct($appName, $request);

Expand All @@ -105,6 +114,7 @@ public function __construct(
$this->addressHandler = $addressHandler;
$this->fedShareManager = $fedShareManager;
$this->logger = $logger;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -177,6 +187,14 @@ public function createShare(
$resourceType,
$protocol
) {
// Allow other apps to overwrite the behaviour of this endpoint
if ($shareType === 'group') {
$controllerClass = $this->config->getSystemValue('sharing.ocmController');
if ($controllerClass !== '') {
$controller = \OC::$server->query($controllerClass);
return $controller->createShare(...\func_get_args());
}
}
try {
$this->ocmMiddleware->assertIncomingSharingEnabled();
$this->ocmMiddleware->assertNotNull(
Expand Down Expand Up @@ -284,6 +302,12 @@ public function processNotification(
$providerId,
$notification
) {
// Allow other apps to overwrite the behaviour of this endpoint
$controllerClass = $this->config->getSystemValue('sharing.ocmController');
if ($controllerClass !== '') {
$controller = \OC::$server->query($controllerClass);
return $controller->processNotification(...\func_get_args());
}
try {
if (!\is_array($notification)) {
throw new BadRequestException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCA\FederatedFileSharing\Tests\TestCase;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -107,6 +108,7 @@ protected function setUp(): void {
$this->addressHandler = $this->createMock(AddressHandler::class);
$this->fedShareManager = $this->createMock(FedShareManager::class);
$this->logger = $this->createMock(ILogger::class);
$this->config = $this->createMock(IConfig::class);

$this->ocmController = new OcmController(
'federatedfilesharing',
Expand All @@ -116,7 +118,8 @@ protected function setUp(): void {
$this->userManager,
$this->addressHandler,
$this->fedShareManager,
$this->logger
$this->logger,
$this->config
);
}

Expand Down
8 changes: 6 additions & 2 deletions apps/files_sharing/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ OCA.Sharing.App = {
fileList.fileSummary.$el.find('.filesize').remove();
},

_setShareState: function(fileId, state, isRemote) {
_setShareState: function(fileId, state, isRemote, shareType) {
var method = 'POST';
if (state === OC.Share.STATE_REJECTED) {
method = 'DELETE';
Expand All @@ -221,6 +221,9 @@ OCA.Sharing.App = {
contentType: 'application/json',
dataType: 'json',
type: method,
data: JSON.stringify({
...(!!shareType && { shareType }),
}),
});
xhr.fail(function(response) {
var message = '';
Expand All @@ -236,6 +239,7 @@ OCA.Sharing.App = {
_shareStateActionHandler: function(context, newState) {
var targetFileData = context.fileList.elementToFile(context.$file);
var isRemote = targetFileData.shareLocationType === 'remote';
const { shareType } = targetFileData;
function responseCallback(response, status) {
if (status === 'success') {
var meta = response.ocs.meta;
Expand All @@ -252,7 +256,7 @@ OCA.Sharing.App = {
}

context.fileList.showFileBusyState(context.$file, true);
this._setShareState(context.fileInfoModel.get('shares')[0].id, newState, isRemote)
this._setShareState(context.fileInfoModel.get('shares')[0].id, newState, isRemote, shareType)
.then(responseCallback);
},

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: 2 additions & 0 deletions apps/files_sharing/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
hasShares = true;
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE) {
hasShares = true;
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE_GROUP) {
hasShares = true;
}
});
OCA.Sharing.Util._updateFileActionIcon($tr, hasShares, hasLink);
Expand Down
8 changes: 6 additions & 2 deletions apps/files_sharing/js/sharedfilelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
$dateColumn.before($tr.children('td:first'));
$tr.find('td.filename input:checkbox').remove();
$tr.attr('data-share-location-type', fileData.shareLocationType);
$tr.attr('data-share-type', fileData.shareType);
$tr.attr('data-share-id', _.pluck(fileData.shares, 'id').join(','));
// add row with expiration date for link only shares - influenced by _createRow of filelist
if (this._linksOnly) {
Expand Down Expand Up @@ -309,7 +310,8 @@
}

fileInfo.shareState = parseInt($el.attr('data-share-state'), 10);
fileInfo.shareLocationType = $el.attr('data-share-location-type');
fileInfo.shareLocationType = $el.attr('data-share-location-type');
fileInfo.shareType = $el.attr('data-share-type') || "";
return fileInfo;
},

Expand Down Expand Up @@ -344,6 +346,7 @@
files = _.chain(files)
// convert share data to file data
.map(function(share) {
const {} = share
var file = {
shareOwner: share.owner + '@' + share.remote.replace(/.*?:\/\//g, ""),
shareState: !!parseInt(share.accepted, 10) ? OC.Share.STATE_ACCEPTED : OC.Share.STATE_PENDING,
Expand All @@ -355,7 +358,8 @@
path: OC.dirname(share.mountpoint),
permissions: share.permissions,
tags: share.tags || [],
shareLocationType: 'remote'
shareLocationType: 'remote',
shareType: share.share_type || ''
};

file.shares = [{
Expand Down
4 changes: 3 additions & 1 deletion apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public function __construct(array $urlParams = []) {
$c->query('Request'),
$c->query('ExternalManager'),
$c->query('HttpClientService'),
$server->getEventDispatcher()
$server->getEventDispatcher(),
$server->getConfig()
);
});

Expand Down Expand Up @@ -119,6 +120,7 @@ public function __construct(array $urlParams = []) {
$server->getEventDispatcher(),
$uid
),
$server->getConfig(),
$uid
);
});
Expand Down
32 changes: 31 additions & 1 deletion apps/files_sharing/lib/Controller/RemoteOcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\Share;
use OCP\Files\StorageNotAvailableException;
use OCP\Files\StorageInvalidException;
use OCP\IConfig;

class RemoteOcsController extends OCSController {
/** @var IRequest */
Expand All @@ -40,23 +41,31 @@ class RemoteOcsController extends OCSController {
/** @var string */
protected $uid;

/**
* @var IConfig
*/
protected $config;

/**
* RemoteOcsController constructor.
*
* @param string $appName
* @param IRequest $request
* @param Manager $externalManager
* @param IConfig config
* @param string $uid
*/
public function __construct(
$appName,
IRequest $request,
Manager $externalManager,
IConfig $config,
$uid
) {
parent::__construct($appName, $request);
$this->request = $request;
$this->externalManager = $externalManager;
$this->config = $config;
$this->uid = $uid;
}

Expand Down Expand Up @@ -126,6 +135,8 @@ public function declineShare($id) {
*/
public function getShares($includingPending = false) {
$shares = [];
$groupExternalManager = null;

foreach ($this->externalManager->getAcceptedShares() as $shareInfo) {
try {
$shares[] = $this->extendShareInfo($shareInfo);
Expand All @@ -136,6 +147,22 @@ public function getShares($includingPending = false) {
}
}

// Allow the Federated Groups app to overwrite the behaviour of this endpoint
$managerClass = $this->config->getSystemValue('sharing.groupExternalManager');
if ($managerClass !== '') {
$groupExternalManager = \OC::$server->query($managerClass);

foreach ($groupExternalManager->getAcceptedShares() as $shareInfo) {
try {
$shares[] = $this->extendShareInfo($shareInfo);
} catch (StorageNotAvailableException $e) {
//TODO: Log the exception here? There are several logs already below the stack
} catch (StorageInvalidException $e) {
//TODO: Log the exception here? There are several logs already below the stack
}
}
}

if ($includingPending === true) {
/**
* pending shares have mountpoint looking like
Expand All @@ -152,7 +179,10 @@ function ($share) {
$share['mountpoint'] = \rtrim($share['mountpoint'], '}');
return $share;
},
$this->externalManager->getOpenShares()
\array_merge(
$this->externalManager->getOpenShares(),
$groupExternalManager == null ? [] : $groupExternalManager->getOpenShares()
)
);
$shares = \array_merge($shares, $openShares);
}
Expand Down
Loading