Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2f55914
Accept OCM to groups
michielbdejong Apr 18, 2023
5eeb437
Accept OCM to groups
michielbdejong Apr 18, 2023
0485d0f
fix the broken tests
navid-shokri Apr 20, 2023
c2d3c6b
Fix code style
phil-davis Apr 21, 2023
783fe0c
Update ProviderFactory.php
navid-shokri Jun 26, 2023
049b9a8
Merge pull request #16 from pondersource/Fix#19-ocm
navid-shokri Jun 27, 2023
53b2921
improve logics
shokri-navid Jul 14, 2023
36b625d
adjust code format
shokri-navid Jul 14, 2023
263ceaa
remove extra space
shokri-navid Jul 14, 2023
2bea3c6
remove extra space
shokri-navid Jul 14, 2023
98d1200
Merge pull request #17 from pondersource/fix/review-comments
navid-shokri Jul 14, 2023
ab60172
add logger to RemoteOcsController
shokri-navid Jul 14, 2023
9f59310
resolve RemotOcsControllerTest error
shokri-navid Jul 14, 2023
7331f71
Resolve PR review conversations
shokri-navid Jul 14, 2023
d1d9d5e
Merge remote-tracking branch 'refs/remotes/origin/accept-ocm-to-group…
shokri-navid Jul 14, 2023
2d51f5d
check if shareType is undefined
soltanireza65 Jul 14, 2023
05f14c1
add comment to apps/files_sharing/api/v1 body `shareType`
soltanireza65 Jul 14, 2023
169637c
convert string share type to int
shokri-navid Jul 15, 2023
b2bc981
improve logics
shokri-navid Jul 14, 2023
85bb598
remove extra space
shokri-navid Jul 14, 2023
6ee6aa1
code style fix
shokri-navid Jul 16, 2023
e0fabef
add missing logger parameter in RemoteOcsController
shokri-navid Jul 16, 2023
78fbce0
Merge branch 'master' into accept-to-ocm-group-2
navid-shokri Jul 21, 2023
4964faa
throw share not found exception on wrong share link
shokri-navid Jul 27, 2023
3a99fac
Rename group manager to avoid confusion
MahdiBaghbani Aug 10, 2023
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
Prev Previous commit
Next Next commit
Resolve PR review conversations
  • Loading branch information
shokri-navid authored Jul 14, 2023
commit 7331f71446b965da7f09f92c37b85de2aa34ef7f
7 changes: 2 additions & 5 deletions apps/files_sharing/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,13 @@ OCA.Sharing.App = {
if (state === OC.Share.STATE_REJECTED) {
method = 'DELETE';
}

var endPoint = isRemote === true ? 'remote_shares/pending/' : 'shares/pending/';
var xhr = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + endPoint + encodeURIComponent(fileId) + '?format=json',
contentType: 'application/json',
dataType: 'json',
type: method,
data: JSON.stringify({
...(!!shareType && { shareType }),
}),
data: JSON.stringify((Boolean(shareType) ? { shareType: shareType } : {})),
});
xhr.fail(function(response) {
var message = '';
Expand All @@ -239,7 +236,7 @@ OCA.Sharing.App = {
_shareStateActionHandler: function(context, newState) {
var targetFileData = context.fileList.elementToFile(context.$file);
var isRemote = targetFileData.shareLocationType === 'remote';
const { shareType } = targetFileData;
const shareType = targetFileData.shareType;
function responseCallback(response, status) {
if (status === 'success') {
var meta = response.ocs.meta;
Expand Down
1 change: 0 additions & 1 deletion apps/files_sharing/js/sharedfilelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@
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 Down
1 change: 1 addition & 0 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function __construct(array $urlParams = []) {
$uid
),
$server->getConfig(),
$server->getLogger(),
$uid
);
});
Expand Down
15 changes: 12 additions & 3 deletions apps/files_sharing/lib/Controller/RemoteOcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\Files\StorageNotAvailableException;
use OCP\Files\StorageInvalidException;
use OCP\IConfig;
use OCP\ILogger;

class RemoteOcsController extends OCSController {
/** @var IRequest */
Expand All @@ -46,26 +47,34 @@ class RemoteOcsController extends OCSController {
*/
protected $config;

/**
* @var ILogger
*/
protected $logger;

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

Expand Down Expand Up @@ -156,9 +165,9 @@ public function getShares($includingPending = false) {
try {
$shares[] = $this->extendShareInfo($shareInfo);
} catch (StorageNotAvailableException $e) {
//TODO: Log the exception here? There are several logs already below the stack
$this->logger->logException($e, ['app' => 'files_sharing']);
} catch (StorageInvalidException $e) {
//TODO: Log the exception here? There are several logs already below the stack
$this->logger->logException($e, ['app' => 'files_sharing']);
}
}
}
Expand All @@ -181,7 +190,7 @@ function ($share) {
},
\array_merge(
$this->externalManager->getOpenShares(),
$groupExternalManager == null ? [] : $groupExternalManager->getOpenShares()
$groupExternalManager === null ? [] : $groupExternalManager->getOpenShares()
)
);
$shares = \array_merge($shares, $openShares);
Expand Down
10 changes: 6 additions & 4 deletions apps/files_sharing/lib/Controller/Share20OcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ private function getShareById($id, $recipient = null) {

continue;
} catch (ProviderException $e) {
// We should iterate all provider to find proper provider for given share
continue;
}
}
Expand Down Expand Up @@ -1300,11 +1301,12 @@ private function getSupportedShareTypes() {
$shareTypes = [];

foreach ($providersCapabilities as $capabilities) {
$shareTypes = array_merge($shareTypes, array_keys($capabilities));
foreach ($capabilities as $key => $value) {
$shareTypes[] = $key;
}
}

$shareTypes = array_keys(array_intersect(Share::CONVERT_SHARE_TYPE_TO_STRING, $shareTypes));


$shareTypes = \array_unique($shareTypes);
return $shareTypes;
}
}
31 changes: 17 additions & 14 deletions apps/files_sharing/lib/Controllers/ExternalSharesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ExternalSharesController extends Controller {
/** @var IConfig $config */
private $config;

public const group_share_type = "group";
/**
* ExternalSharesController constructor.
*
Expand All @@ -77,11 +78,6 @@ public function __construct(
$this->clientService = $clientService;
$this->dispatcher = $eventDispatcher;
$this->config = $config;
// Allow other apps to add an external manager for user-to-group shares
$managerClass = $this->config->getSystemValue('sharing.groupExternalManager');
if ($managerClass !== '') {
$this->groupExternalManager = \OC::$server->query($managerClass);
}
}

/**
Expand All @@ -92,8 +88,9 @@ public function __construct(
*/
public function index() {
$federatedGroupResult = [];
if ($this->groupExternalManager !== null) {
$federatedGroupResult = $this->groupExternalManager->getOpenShares();
$groupExternalManager = $this->initGroupManager();
if ($groupExternalManager !== null) {
$federatedGroupResult = $groupExternalManager->getOpenShares();
}
$result = array_merge($federatedGroupResult, $this->externalManager->getOpenShares());
return new JSONResponse($result);
Expand All @@ -108,11 +105,7 @@ public function index() {
* @return JSONResponse
*/
public function create($id, $share_type) {
if ($share_type === "group" && $this->groupExternalManager !== null) {
$manager = $this->groupExternalManager;
} else {
$manager = $this->externalManager;
}
$manager = $this->getManagerForShareType($share_type);
$shareInfo = $manager->getShare($id);

if ($shareInfo !== false) {
Expand Down Expand Up @@ -163,9 +156,19 @@ public function destroy($id, $share_type) {
return new JSONResponse();
}

private function initGroupManager() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should rename this function. There is a "groupManager" which is widely used (https://github.com/owncloud/core/blob/master/lib/public/IGroupManager.php) so it might be confusing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jvillafanez Hi, I've changed the name a bit to "initGroupExternalManager", it should not be confused with simple "groupManager" anymore since it explicitly declares it is external.

If it still counts as confusing name, let me know.

// Allow other apps to add an external manager for user-to-group shares
$managerClass = $this->config->getSystemValue('sharing.groupExternalManager');
if ($managerClass !== '') {
return \OC::$server->query($managerClass);
}
return null;
}

private function getManagerForShareType($share_type) {
if ($share_type === "group" && $this->groupExternalManager !== null) {
$manager = $this->groupExternalManager;
$groupExternalManager = $this->initGroupManager();
if ($share_type === self::group_share_type && $groupExternalManager !== null) {
$manager = $groupExternalManager;
} else {
$manager = $this->externalManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCA\Files_Sharing\Controller\RemoteOcsController;
use OCA\Files_Sharing\External\Manager;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
Expand All @@ -42,19 +43,24 @@ class RemoteOcsControllerTest extends TestCase {
/** @var IConfig */
protected $config;

/** @var ILogger */
protected $logger;

/** @var RemoteOcsController | MockObject */
protected $controller;

protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
$this->externalManager = $this->createMock(Manager::class);
$this->config = $this->createMock(IConfig::class);

$this->logger = $this->createMock(ILogger::class);

$this->controller = new RemoteOcsController(
$this->appName,
$this->request,
$this->externalManager,
$this->config,
$this->logger,
'user'
);
}
Expand Down
25 changes: 15 additions & 10 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1538,19 +1538,24 @@ public function getShareByToken($token) {
"shared file not found by token: $token for federated user share, try to check federated group share.",
['app' => __CLASS__]
);
}
}

if ($share === null) {
try {
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE_GROUP);
if ($provider !== null) {
$share = $provider->getShareByToken($token);
try {
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE_GROUP);
if ($provider !== null) {
$share = $provider->getShareByToken($token);
}
} catch (ShareNotFound $ex) {
$this->logger->error(
"shared file not found by token: $token for federated group share",
['app' => __CLASS__]
);
} catch (ProviderException $ex) {
$this->logger->logException(
$ex,
['app' => __CLASS__]
);
}
} catch (ProviderException $ex) {
}
}

if (self::shareHasExpired($share)) {
$this->activityManager->setAgentAuthor(IEvent::AUTOMATION_AUTHOR);
try {
Expand Down