some minor fixes and clode cleanup

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
Bjoern Schiessle 2018-06-07 16:36:26 +02:00
parent 957b27f282
commit 84fc188dfc
No known key found for this signature in database
GPG Key ID: 2378A753E2BF04F6
15 changed files with 109 additions and 22 deletions

View File

@ -108,7 +108,6 @@ class RequestHandlerController extends Controller {
* @param string $ownerDisplayName display name of the user who shared the item
* @param string $sharedBy provider specific UID of the user who shared the resource
* @param string $sharedByDisplayName display name of the user who shared the resource
* @param string $sharedSecret use to authenticate accross servers
* @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]])
* @param string $shareType ('group' or 'user' share)
* @param $resourceType ('file', 'calendar',...)

View File

@ -506,13 +506,13 @@ class FederatedShareProvider implements IShareProvider {
* Delete a share (owner unShares the file)
*
* @param IShare $share
* @throws ShareNotFound
* @throws \OC\HintException
*/
public function delete(IShare $share) {
list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith());
$isOwner = false;
// if the local user is the owner we can send the unShare request directly...
if ($this->userManager->userExists($share->getShareOwner())) {
$this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken());

View File

@ -162,7 +162,6 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner());
$remote = $remote;
$token = $share->getShareSecret();
$name = $share->getResourceName();
$owner = $share->getOwnerDisplayName();
@ -247,7 +246,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
} catch (\Exception $e) {
$this->logger->logException($e, [
'message' => 'Server can not add remote share.',
'level' => Util::ERROR,
'level' => ILogger::ERROR,
'app' => 'files_sharing'
]);
throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR);
@ -304,7 +303,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
* @throws BadRequestException
* @throws \OC\HintException
*/
private function shareAccepted($id, $notification) {
private function shareAccepted($id, array $notification) {
if (!$this->isS2SEnabled()) {
throw new ActionNotSupportedException('Server does not support federated cloud sharing');
@ -376,7 +375,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
* @throws \OC\HintException
*
*/
protected function shareDeclined($id, $notification) {
protected function shareDeclined($id, array $notification) {
if (!$this->isS2SEnabled()) {
throw new ActionNotSupportedException('Server does not support federated cloud sharing');
@ -446,12 +445,12 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
* received the notification that the owner unshared a file from you
*
* @param string $id
* @param string $notification
* @param array $notification
* @return array
* @throws AuthenticationFailedException
* @throws BadRequestException
*/
private function undoReshare($id, $notification) {
private function undoReshare($id, array $notification) {
if (!isset($notification['sharedSecret'])) {
throw new BadRequestException(['sharedSecret']);
}
@ -550,15 +549,15 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
/**
* recipient of a share request to re-share the file with another user
*
* @param $id
* @param $notification
* @param string $id
* @param array $notification
* @return array
* @throws AuthenticationFailedException
* @throws BadRequestException
* @throws ProviderCouldNotAddShareException
* @throws ShareNotFound
*/
protected function reshareRequested($id, $notification) {
protected function reshareRequested($id, array $notification) {
if (!isset($notification['sharedSecret'])) {
throw new BadRequestException(['sharedSecret']);
@ -602,7 +601,6 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id);
}
throw new BadRequestException([]);
}
/**
@ -615,7 +613,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
* @throws AuthenticationFailedException
* @throws BadRequestException
*/
protected function updateResharePermissions($id, $notification) {
protected function updateResharePermissions($id, array $notification) {
if (!isset($notification['sharedSecret'])) {
throw new BadRequestException(['sharedSecret']);
@ -640,12 +638,11 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
/**
* translate OCM Permissions to Nextcloud permissions
*
* @param $ocmPermissions
* @param array $ocmPermissions
* @return int
* @throws BadRequestException
*/
protected function ocmPermissions2ncPermissions($ocmPermissions) {
error_log("ocm permissions: " . json_encode($ocmPermissions));
protected function ocmPermissions2ncPermissions(array $ocmPermissions) {
$ncPermissions = 0;
foreach($ocmPermissions as $permission) {
switch (strtolower($permission)) {
@ -701,7 +698,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
$args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file);
$link = Util::linkToAbsolute('files', 'index.php', $args);
return array($file, $link);
return [$file, $link];
}

View File

@ -23,6 +23,13 @@ namespace OC\Federation;
use OCP\Federation\ICloudFederationNotification;
/**
* Class CloudFederationNotification
*
* @package OC\Federation
*
* @since 14.0.0
*/
class CloudFederationNotification implements ICloudFederationNotification {
private $message = [];

View File

@ -200,7 +200,7 @@ class CloudFederationProviderManager implements ICloudFederationProviderManager
* @return bool
*/
public function isReady() {
return $this->appManager->isEnabledForUser('cloud_federation_api', false);
return $this->appManager->isEnabledForUser('cloud_federation_api');
}
/**
* check if server supports the new OCM api and ask for the correct end-point

View File

@ -23,11 +23,20 @@ namespace OCP\Federation\Exceptions;
use OC\HintException;
/**
* Class ActionNotSupportedException
*
* @package OCP\Federation\Exceptions
*
* @since 14.0.0
*/
class ActionNotSupportedException extends HintException {
/**
* ActionNotSupportedException constructor.
*
* @since 14.0.0
*
*/
public function __construct($action) {
$l = \OC::$server->getL10N('federation');

View File

@ -23,12 +23,20 @@ namespace OCP\Federation\Exceptions;
use OC\HintException;
/**
* Class AuthenticationFailedException
*
* @package OCP\Federation\Exceptions
*
* @since 14.0.0
*/
class AuthenticationFailedException extends HintException {
/**
* BadRequestException constructor.
*
* @param array $missingParameters
* @since 14.0.0
*
*/
public function __construct() {
$l = \OC::$server->getL10N('federation');

View File

@ -23,6 +23,13 @@ namespace OCP\Federation\Exceptions;
use OC\HintException;
/**
* Class BadRequestException
*
* @package OCP\Federation\Exceptions
*
* @since 14.0.0
*/
class BadRequestException extends HintException {
private $parameterList;
@ -30,6 +37,8 @@ class BadRequestException extends HintException {
/**
* BadRequestException constructor.
*
* @since 14.0.0
*
* @param array $missingParameters
*/
public function __construct(array $missingParameters) {
@ -44,6 +53,8 @@ class BadRequestException extends HintException {
/**
* get array with the return message as defined in the OCM API
*
* @since 14.0.0
*
* @return array
*/
public function getReturnMessage() {

View File

@ -23,11 +23,20 @@ namespace OCP\Federation\Exceptions;
use OC\HintException;
/**
* Class ProviderAlreadyExistsException
*
* @package OCP\Federation\Exceptions
*
* @since 14.0.0
*/
class ProviderAlreadyExistsException extends HintException {
/**
* ProviderAlreadyExistsException constructor.
*
* @since 14.0.0
*
* @param string $newProviderId cloud federation provider ID of the new provider
* @param string $existingProviderName name of cloud federation provider which already use the same ID
*/

View File

@ -24,8 +24,25 @@ namespace OCP\Federation\Exceptions;
use OC\HintException;
use OCP\AppFramework\Http;
/**
* Class ProviderCouldNotAddShareException
*
* @package OCP\Federation\Exceptions
*
* @since 14.0.0
*/
class ProviderCouldNotAddShareException extends HintException {
/**
* ProviderCouldNotAddShareException constructor.
*
* @since 14.0.0
*
* @param string $message
* @param string $hint
* @param int $code
* @param \Exception|null $previous
*/
public function __construct($message, $hint = '', $code = Http::STATUS_BAD_REQUEST, \Exception $previous = null) {
parent::__construct($message, $hint, $code, $previous);
}

View File

@ -23,11 +23,20 @@ namespace OCP\Federation\Exceptions;
use OC\HintException;
/**
* Class ProviderDoesNotExistsException
*
* @package OCP\Federation\Exceptions
*
* @since 14.0.0
*/
class ProviderDoesNotExistsException extends HintException {
/**
* ProviderDoesNotExistsException constructor.
*
* @since 14.0.0
*
* @param string $providerId cloud federation provider ID
*/
public function __construct($providerId) {

View File

@ -21,6 +21,13 @@
namespace OCP\Federation;
/**
* Interface ICloudFederationFactory
*
* @package OCP\Federation
*
* @since 14.0.0
*/
interface ICloudFederationFactory {
/**

View File

@ -21,6 +21,13 @@
namespace OCP\Federation;
/**
* Interface ICloudFederationNotification
*
* @package OCP\Federation
*
* @since 14.0.0
*/
interface ICloudFederationNotification {
/**
@ -31,7 +38,6 @@ interface ICloudFederationNotification {
* @param $providerId id of the share
* @param array $notification , payload of the notification
*
* @return
* @since 14.0.0
*/
public function setMessage($notificationType, $resourceType, $providerId, array $notification);
@ -39,7 +45,7 @@ interface ICloudFederationNotification {
/**
* get message, ready to send out
*
* @return string
* @return array
*
* @since 14.0.0
*/

View File

@ -21,6 +21,13 @@
namespace OCP\Federation;
/**
* Interface ICloudFederationShare
*
* @package OCP\Federation
*
* @since 14.0.0
*/
interface ICloudFederationShare {
/**

View File

@ -557,6 +557,7 @@ interface IServerContainer extends IContainer {
/**
* @return \OCP\GlobalScale\IConfig
* @since 14.0.0
*/
public function getGlobalScaleConfig();