Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ private function confirmSignedOrigin(?IIncomingSignedRequest $signedRequest, str
*
* @param IIncomingSignedRequest|null $signedRequest
* @param string $resourceType
* @param string $sharedSecret
*
* @throws IncomingRequestException
* @throws BadRequestException
Expand All @@ -524,7 +523,7 @@ private function confirmNotificationIdentity(
return;
}
} catch (\Exception $e) {
throw new IncomingRequestException($e->getMessage());
throw new IncomingRequestException($e->getMessage(), previous: $e);
}

$this->confirmNotificationEntry($signedRequest, $identity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
*/
namespace OCA\FederatedFileSharing\Controller;

use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
Expand All @@ -29,7 +27,6 @@
use OCP\HintException;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Log\Audit\CriticalActionPerformedEvent;
use OCP\Server;
use OCP\Share;
Expand All @@ -44,10 +41,6 @@ public function __construct(
IRequest $request,
private FederatedShareProvider $federatedShareProvider,
private IDBConnection $connection,
private Share\IManager $shareManager,
private Notifications $notifications,
private AddressHandler $addressHandler,
private IUserManager $userManager,
private ICloudIdManager $cloudIdManager,
private LoggerInterface $logger,
private ICloudFederationFactory $cloudFederationFactory,
Expand All @@ -66,10 +59,10 @@ public function __construct(
* @param string|null $owner Display name of the receiver
* @param string|null $sharedBy Display name of the sender
* @param string|null $shareWith ID of the user that receives the share
* @param int|null $remoteId ID of the remote
* @param string|null $remoteId ID of the remote
* @param string|null $sharedByFederatedId Federated ID of the sender
* @param string|null $ownerFederatedId Federated ID of the receiver
* @return Http\DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @throws OCSException
*
* 200: Share created successfully
Expand All @@ -83,10 +76,10 @@ public function createShare(
?string $owner = null,
?string $sharedBy = null,
?string $shareWith = null,
?int $remoteId = null,
?string $remoteId = null,
?string $sharedByFederatedId = null,
?string $ownerFederatedId = null,
) {
): DataResponse {
if ($ownerFederatedId === null) {
$ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId();
}
Expand Down Expand Up @@ -132,19 +125,19 @@ public function createShare(
/**
* create re-share on behalf of another user
*
* @param int $id ID of the share
* @param string $id ID of the share
* @param string|null $token Shared secret between servers
* @param string|null $shareWith ID of the user that receives the share
* @param int|null $remoteId ID of the remote
* @return Http\DataResponse<Http::STATUS_OK, array{token: string, remoteId: string}, array{}>
* @return DataResponse<Http::STATUS_OK, array{token: string, remoteId: string}, array{}>
* @throws OCSBadRequestException Re-sharing is not possible
* @throws OCSException
*
* 200: Remote share returned
*/
#[NoCSRFRequired]
#[PublicPage]
public function reShare(int $id, ?string $token = null, ?string $shareWith = null, ?int $remoteId = 0) {
public function reShare(string $id, ?string $token = null, ?string $shareWith = null, ?int $remoteId = 0): DataResponse {
if ($token === null
|| $shareWith === null
|| $remoteId === null
Expand Down Expand Up @@ -181,9 +174,9 @@ public function reShare(int $id, ?string $token = null, ?string $shareWith = nul
/**
* accept server-to-server share
*
* @param int $id ID of the remote share
* @param string $id ID of the remote share
* @param string|null $token Shared secret between servers
* @return Http\DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @throws OCSException
* @throws ShareNotFound
* @throws HintException
Expand All @@ -192,7 +185,7 @@ public function reShare(int $id, ?string $token = null, ?string $shareWith = nul
*/
#[NoCSRFRequired]
#[PublicPage]
public function acceptShare(int $id, ?string $token = null) {
public function acceptShare(string $id, ?string $token = null): DataResponse {
$notification = [
'sharedSecret' => $token,
'message' => 'Recipient accept the share'
Expand All @@ -216,16 +209,16 @@ public function acceptShare(int $id, ?string $token = null) {
/**
* decline server-to-server share
*
* @param int $id ID of the remote share
* @param string $id ID of the remote share
* @param string|null $token Shared secret between servers
* @return Http\DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @throws OCSException
*
* 200: Share declined successfully
*/
#[NoCSRFRequired]
#[PublicPage]
public function declineShare(int $id, ?string $token = null) {
public function declineShare(string $id, ?string $token = null) {
$notification = [
'sharedSecret' => $token,
'message' => 'Recipient declined the share'
Expand All @@ -249,16 +242,16 @@ public function declineShare(int $id, ?string $token = null) {
/**
* remove server-to-server share if it was unshared by the owner
*
* @param int $id ID of the share
* @param string $id ID of the share
* @param string|null $token Shared secret between servers
* @return Http\DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @throws OCSException
*
* 200: Share unshared successfully
*/
#[NoCSRFRequired]
#[PublicPage]
public function unshare(int $id, ?string $token = null) {
public function unshare(string $id, ?string $token = null) {
if (!$this->isS2SEnabled()) {
throw new OCSException('Server does not support federated cloud sharing', 503);
}
Expand All @@ -275,7 +268,7 @@ public function unshare(int $id, ?string $token = null) {
return new DataResponse();
}

private function cleanupRemote($remote) {
private function cleanupRemote(string $remote): string {
$remote = substr($remote, strpos($remote, '://') + 3);

return rtrim($remote, '/');
Expand All @@ -285,16 +278,16 @@ private function cleanupRemote($remote) {
/**
* federated share was revoked, either by the owner or the re-sharer
*
* @param int $id ID of the share
* @param string $id ID of the share
* @param string|null $token Shared secret between servers
* @return Http\DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @throws OCSBadRequestException Revoking the share is not possible
*
* 200: Share revoked successfully
*/
#[NoCSRFRequired]
#[PublicPage]
public function revoke(int $id, ?string $token = null) {
public function revoke(string $id, ?string $token = null) {
try {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file');
$notification = ['sharedSecret' => $token];
Expand Down Expand Up @@ -324,19 +317,19 @@ private function isS2SEnabled($incoming = false) {
}

/**
* update share information to keep federated re-shares in sync
* Update share information to keep federated re-shares in sync.
*
* @param int $id ID of the share
* @param string $id ID of the share
* @param string|null $token Shared secret between servers
* @param int|null $permissions New permissions
* @return Http\DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @throws OCSBadRequestException Updating permissions is not possible
*
* 200: Permissions updated successfully
*/
#[NoCSRFRequired]
#[PublicPage]
public function updatePermissions(int $id, ?string $token = null, ?int $permissions = null) {
public function updatePermissions(string $id, ?string $token = null, ?int $permissions = null) {
$ncPermissions = $permissions;

try {
Expand Down Expand Up @@ -385,7 +378,7 @@ protected function ncPermissions2ocmPermissions($ncPermissions) {
* @param string|null $token Shared secret between servers
* @param string|null $remote Address of the remote
* @param string|null $remote_id ID of the remote
* @return Http\DataResponse<Http::STATUS_OK, array{remote: string, owner: string}, array{}>
* @return DataResponse<Http::STATUS_OK, array{remote: string, owner: string}, array{}>
* @throws OCSBadRequestException Moving share is not possible
*
* 200: Share moved successfully
Expand Down
Loading