Passed
Push — master ( 21b7e5...813bdc )
by Christoph
12:53 queued 10s
created
apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -47,20 +47,20 @@  discard block
 block discarded – undo
47 47
  */
48 48
 class SharingCheckMiddleware extends Middleware {
49 49
 
50
-	/** @var string */
51
-	protected $appName;
52
-	/** @var IConfig */
53
-	protected $config;
54
-	/** @var IAppManager */
55
-	protected $appManager;
56
-	/** @var IControllerMethodReflector */
57
-	protected $reflector;
58
-	/** @var IManager */
59
-	protected $shareManager;
60
-	/** @var IRequest */
61
-	protected $request;
62
-
63
-	/***
50
+    /** @var string */
51
+    protected $appName;
52
+    /** @var IConfig */
53
+    protected $config;
54
+    /** @var IAppManager */
55
+    protected $appManager;
56
+    /** @var IControllerMethodReflector */
57
+    protected $reflector;
58
+    /** @var IManager */
59
+    protected $shareManager;
60
+    /** @var IRequest */
61
+    protected $request;
62
+
63
+    /***
64 64
 	 * @param string $appName
65 65
 	 * @param IConfig $config
66 66
 	 * @param IAppManager $appManager
@@ -68,94 +68,94 @@  discard block
 block discarded – undo
68 68
 	 * @param IManager $shareManager
69 69
 	 * @param IRequest $request
70 70
 	 */
71
-	public function __construct($appName,
72
-								IConfig $config,
73
-								IAppManager $appManager,
74
-								IControllerMethodReflector $reflector,
75
-								IManager $shareManager,
76
-								IRequest $request
77
-								) {
78
-		$this->appName = $appName;
79
-		$this->config = $config;
80
-		$this->appManager = $appManager;
81
-		$this->reflector = $reflector;
82
-		$this->shareManager = $shareManager;
83
-		$this->request = $request;
84
-	}
85
-
86
-	/**
87
-	 * Check if sharing is enabled before the controllers is executed
88
-	 *
89
-	 * @param Controller $controller
90
-	 * @param string $methodName
91
-	 * @throws NotFoundException
92
-	 * @throws S2SException
93
-	 * @throws ShareNotFound
94
-	 */
95
-	public function beforeController($controller, $methodName) {
96
-		if(!$this->isSharingEnabled()) {
97
-			throw new NotFoundException('Sharing is disabled.');
98
-		}
99
-
100
-		if ($controller instanceof ExternalSharesController &&
101
-			!$this->externalSharesChecks()) {
102
-			throw new S2SException('Federated sharing not allowed');
103
-		}
104
-	}
105
-
106
-	/**
107
-	 * Return 404 page in case of a not found exception
108
-	 *
109
-	 * @param Controller $controller
110
-	 * @param string $methodName
111
-	 * @param \Exception $exception
112
-	 * @return NotFoundResponse
113
-	 * @throws \Exception
114
-	 */
115
-	public function afterException($controller, $methodName, \Exception $exception) {
116
-		if(is_a($exception, NotFoundException::class)) {
117
-			return new NotFoundResponse();
118
-		}
119
-
120
-		if (is_a($exception, S2SException::class)) {
121
-			return new JSONResponse($exception->getMessage(), 405);
122
-		}
123
-
124
-		throw $exception;
125
-	}
126
-
127
-	/**
128
-	 * Checks for externalshares controller
129
-	 * @return bool
130
-	 */
131
-	private function externalSharesChecks() {
132
-
133
-		if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') &&
134
-			$this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') {
135
-			return false;
136
-		}
137
-
138
-		if (!$this->reflector->hasAnnotation('NoOutgoingFederatedSharingRequired') &&
139
-			$this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') {
140
-			return false;
141
-		}
142
-
143
-		return true;
144
-	}
145
-
146
-	/**
147
-	 * Check whether sharing is enabled
148
-	 * @return bool
149
-	 */
150
-	private function isSharingEnabled() {
151
-		// FIXME: This check is done here since the route is globally defined and not inside the files_sharing app
152
-		// Check whether the sharing application is enabled
153
-		if(!$this->appManager->isEnabledForUser($this->appName)) {
154
-			return false;
155
-		}
156
-
157
-		return true;
158
-	}
71
+    public function __construct($appName,
72
+                                IConfig $config,
73
+                                IAppManager $appManager,
74
+                                IControllerMethodReflector $reflector,
75
+                                IManager $shareManager,
76
+                                IRequest $request
77
+                                ) {
78
+        $this->appName = $appName;
79
+        $this->config = $config;
80
+        $this->appManager = $appManager;
81
+        $this->reflector = $reflector;
82
+        $this->shareManager = $shareManager;
83
+        $this->request = $request;
84
+    }
85
+
86
+    /**
87
+     * Check if sharing is enabled before the controllers is executed
88
+     *
89
+     * @param Controller $controller
90
+     * @param string $methodName
91
+     * @throws NotFoundException
92
+     * @throws S2SException
93
+     * @throws ShareNotFound
94
+     */
95
+    public function beforeController($controller, $methodName) {
96
+        if(!$this->isSharingEnabled()) {
97
+            throw new NotFoundException('Sharing is disabled.');
98
+        }
99
+
100
+        if ($controller instanceof ExternalSharesController &&
101
+            !$this->externalSharesChecks()) {
102
+            throw new S2SException('Federated sharing not allowed');
103
+        }
104
+    }
105
+
106
+    /**
107
+     * Return 404 page in case of a not found exception
108
+     *
109
+     * @param Controller $controller
110
+     * @param string $methodName
111
+     * @param \Exception $exception
112
+     * @return NotFoundResponse
113
+     * @throws \Exception
114
+     */
115
+    public function afterException($controller, $methodName, \Exception $exception) {
116
+        if(is_a($exception, NotFoundException::class)) {
117
+            return new NotFoundResponse();
118
+        }
119
+
120
+        if (is_a($exception, S2SException::class)) {
121
+            return new JSONResponse($exception->getMessage(), 405);
122
+        }
123
+
124
+        throw $exception;
125
+    }
126
+
127
+    /**
128
+     * Checks for externalshares controller
129
+     * @return bool
130
+     */
131
+    private function externalSharesChecks() {
132
+
133
+        if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') &&
134
+            $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') {
135
+            return false;
136
+        }
137
+
138
+        if (!$this->reflector->hasAnnotation('NoOutgoingFederatedSharingRequired') &&
139
+            $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') {
140
+            return false;
141
+        }
142
+
143
+        return true;
144
+    }
145
+
146
+    /**
147
+     * Check whether sharing is enabled
148
+     * @return bool
149
+     */
150
+    private function isSharingEnabled() {
151
+        // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app
152
+        // Check whether the sharing application is enabled
153
+        if(!$this->appManager->isEnabledForUser($this->appName)) {
154
+            return false;
155
+        }
156
+
157
+        return true;
158
+    }
159 159
 
160 160
 
161 161
 
Please login to merge, or discard this patch.
apps/files_sharing/templates/public.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -111,10 +111,10 @@
 block discarded – undo
111 111
 			<?php if (!empty($_['disclaimer'])) { ?>
112 112
 				<div>
113 113
 					<?php
114
-						echo $l->t('By uploading files, you agree to the %1$sterms of service%2$s.', [
115
-							'<span id="show-terms-dialog">', '</span>'
116
-						]);
117
-					?>
114
+                        echo $l->t('By uploading files, you agree to the %1$sterms of service%2$s.', [
115
+                            '<span id="show-terms-dialog">', '</span>'
116
+                        ]);
117
+                    ?>
118 118
 				</div>
119 119
 			<?php } ?>
120 120
 		</div>
Please login to merge, or discard this patch.
apps/federation/lib/SyncFederationAddressBooks.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -33,64 +33,64 @@
 block discarded – undo
33 33
 
34 34
 class SyncFederationAddressBooks {
35 35
 
36
-	/** @var DbHandler */
37
-	protected $dbHandler;
36
+    /** @var DbHandler */
37
+    protected $dbHandler;
38 38
 
39
-	/** @var SyncService */
40
-	private $syncService;
39
+    /** @var SyncService */
40
+    private $syncService;
41 41
 
42
-	/** @var  DiscoveryService */
43
-	private $ocsDiscoveryService;
42
+    /** @var  DiscoveryService */
43
+    private $ocsDiscoveryService;
44 44
 
45
-	/**
46
-	 * @param DbHandler $dbHandler
47
-	 * @param SyncService $syncService
48
-	 * @param IDiscoveryService $ocsDiscoveryService
49
-	 */
50
-	public function __construct(DbHandler $dbHandler,
51
-								SyncService $syncService,
52
-								IDiscoveryService $ocsDiscoveryService
53
-	) {
54
-		$this->syncService = $syncService;
55
-		$this->dbHandler = $dbHandler;
56
-		$this->ocsDiscoveryService = $ocsDiscoveryService;
57
-	}
45
+    /**
46
+     * @param DbHandler $dbHandler
47
+     * @param SyncService $syncService
48
+     * @param IDiscoveryService $ocsDiscoveryService
49
+     */
50
+    public function __construct(DbHandler $dbHandler,
51
+                                SyncService $syncService,
52
+                                IDiscoveryService $ocsDiscoveryService
53
+    ) {
54
+        $this->syncService = $syncService;
55
+        $this->dbHandler = $dbHandler;
56
+        $this->ocsDiscoveryService = $ocsDiscoveryService;
57
+    }
58 58
 
59
-	/**
60
-	 * @param \Closure $callback
61
-	 */
62
-	public function syncThemAll(\Closure $callback) {
59
+    /**
60
+     * @param \Closure $callback
61
+     */
62
+    public function syncThemAll(\Closure $callback) {
63 63
 
64
-		$trustedServers = $this->dbHandler->getAllServer();
65
-		foreach ($trustedServers as $trustedServer) {
66
-			$url = $trustedServer['url'];
67
-			$callback($url, null);
68
-			$sharedSecret = $trustedServer['shared_secret'];
69
-			$syncToken = $trustedServer['sync_token'];
64
+        $trustedServers = $this->dbHandler->getAllServer();
65
+        foreach ($trustedServers as $trustedServer) {
66
+            $url = $trustedServer['url'];
67
+            $callback($url, null);
68
+            $sharedSecret = $trustedServer['shared_secret'];
69
+            $syncToken = $trustedServer['sync_token'];
70 70
 
71
-			$endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
72
-			$cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system';
73
-			$addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system';
71
+            $endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
72
+            $cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system';
73
+            $addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system';
74 74
 
75
-			if (is_null($sharedSecret)) {
76
-				continue;
77
-			}
78
-			$targetBookId = $trustedServer['url_hash'];
79
-			$targetPrincipal = "principals/system/system";
80
-			$targetBookProperties = [
81
-				'{DAV:}displayname' => $url
82
-			];
83
-			try {
84
-				$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
85
-				if ($newToken !== $syncToken) {
86
-					$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
87
-				}
88
-			} catch (\Exception $ex) {
89
-				if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
90
-					$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED);
91
-				}
92
-				$callback($url, $ex);
93
-			}
94
-		}
95
-	}
75
+            if (is_null($sharedSecret)) {
76
+                continue;
77
+            }
78
+            $targetBookId = $trustedServer['url_hash'];
79
+            $targetPrincipal = "principals/system/system";
80
+            $targetBookProperties = [
81
+                '{DAV:}displayname' => $url
82
+            ];
83
+            try {
84
+                $newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
85
+                if ($newToken !== $syncToken) {
86
+                    $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
87
+                }
88
+            } catch (\Exception $ex) {
89
+                if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
90
+                    $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED);
91
+                }
92
+                $callback($url, $ex);
93
+            }
94
+        }
95
+    }
96 96
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Config.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -33,87 +33,87 @@
 block discarded – undo
33 33
 use Symfony\Component\Console\Output\OutputInterface;
34 34
 
35 35
 class Config extends Base {
36
-	/**
37
-	 * @var GlobalStoragesService
38
-	 */
39
-	protected $globalService;
36
+    /**
37
+     * @var GlobalStoragesService
38
+     */
39
+    protected $globalService;
40 40
 
41
-	function __construct(GlobalStoragesService $globalService) {
42
-		parent::__construct();
43
-		$this->globalService = $globalService;
44
-	}
41
+    function __construct(GlobalStoragesService $globalService) {
42
+        parent::__construct();
43
+        $this->globalService = $globalService;
44
+    }
45 45
 
46
-	protected function configure() {
47
-		$this
48
-			->setName('files_external:config')
49
-			->setDescription('Manage backend configuration for a mount')
50
-			->addArgument(
51
-				'mount_id',
52
-				InputArgument::REQUIRED,
53
-				'The id of the mount to edit'
54
-			)->addArgument(
55
-				'key',
56
-				InputArgument::REQUIRED,
57
-				'key of the config option to set/get'
58
-			)->addArgument(
59
-				'value',
60
-				InputArgument::OPTIONAL,
61
-				'value to set the config option to, when no value is provided the existing value will be printed'
62
-			);
63
-		parent::configure();
64
-	}
46
+    protected function configure() {
47
+        $this
48
+            ->setName('files_external:config')
49
+            ->setDescription('Manage backend configuration for a mount')
50
+            ->addArgument(
51
+                'mount_id',
52
+                InputArgument::REQUIRED,
53
+                'The id of the mount to edit'
54
+            )->addArgument(
55
+                'key',
56
+                InputArgument::REQUIRED,
57
+                'key of the config option to set/get'
58
+            )->addArgument(
59
+                'value',
60
+                InputArgument::OPTIONAL,
61
+                'value to set the config option to, when no value is provided the existing value will be printed'
62
+            );
63
+        parent::configure();
64
+    }
65 65
 
66
-	protected function execute(InputInterface $input, OutputInterface $output) {
67
-		$mountId = $input->getArgument('mount_id');
68
-		$key = $input->getArgument('key');
69
-		try {
70
-			$mount = $this->globalService->getStorage($mountId);
71
-		} catch (NotFoundException $e) {
72
-			$output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
73
-			return 404;
74
-		}
66
+    protected function execute(InputInterface $input, OutputInterface $output) {
67
+        $mountId = $input->getArgument('mount_id');
68
+        $key = $input->getArgument('key');
69
+        try {
70
+            $mount = $this->globalService->getStorage($mountId);
71
+        } catch (NotFoundException $e) {
72
+            $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
73
+            return 404;
74
+        }
75 75
 
76
-		$value = $input->getArgument('value');
77
-		if ($value !== null) {
78
-			$this->setOption($mount, $key, $value, $output);
79
-		} else {
80
-			$this->getOption($mount, $key, $output);
81
-		}
82
-	}
76
+        $value = $input->getArgument('value');
77
+        if ($value !== null) {
78
+            $this->setOption($mount, $key, $value, $output);
79
+        } else {
80
+            $this->getOption($mount, $key, $output);
81
+        }
82
+    }
83 83
 
84
-	/**
85
-	 * @param StorageConfig $mount
86
-	 * @param string $key
87
-	 * @param OutputInterface $output
88
-	 */
89
-	protected function getOption(StorageConfig $mount, $key, OutputInterface $output) {
90
-		if ($key === 'mountpoint' || $key === 'mount_point') {
91
-			$value = $mount->getMountPoint();
92
-		} else {
93
-			$value = $mount->getBackendOption($key);
94
-		}
95
-		if (!is_string($value) && json_decode(json_encode($value)) === $value) { // show bools and objects correctly
96
-			$value = json_encode($value);
97
-		}
98
-		$output->writeln($value);
99
-	}
84
+    /**
85
+     * @param StorageConfig $mount
86
+     * @param string $key
87
+     * @param OutputInterface $output
88
+     */
89
+    protected function getOption(StorageConfig $mount, $key, OutputInterface $output) {
90
+        if ($key === 'mountpoint' || $key === 'mount_point') {
91
+            $value = $mount->getMountPoint();
92
+        } else {
93
+            $value = $mount->getBackendOption($key);
94
+        }
95
+        if (!is_string($value) && json_decode(json_encode($value)) === $value) { // show bools and objects correctly
96
+            $value = json_encode($value);
97
+        }
98
+        $output->writeln($value);
99
+    }
100 100
 
101
-	/**
102
-	 * @param StorageConfig $mount
103
-	 * @param string $key
104
-	 * @param string $value
105
-	 * @param OutputInterface $output
106
-	 */
107
-	protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) {
108
-		$decoded = json_decode($value, true);
109
-		if (!is_null($decoded) && json_encode($decoded) === $value) {
110
-			$value = $decoded;
111
-		}
112
-		if ($key === 'mountpoint' || $key === 'mount_point') {
113
-			$mount->setMountPoint($value);
114
-		} else {
115
-			$mount->setBackendOption($key, $value);
116
-		}
117
-		$this->globalService->updateStorage($mount);
118
-	}
101
+    /**
102
+     * @param StorageConfig $mount
103
+     * @param string $key
104
+     * @param string $value
105
+     * @param OutputInterface $output
106
+     */
107
+    protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) {
108
+        $decoded = json_decode($value, true);
109
+        if (!is_null($decoded) && json_encode($decoded) === $value) {
110
+            $value = $decoded;
111
+        }
112
+        if ($key === 'mountpoint' || $key === 'mount_point') {
113
+            $mount->setMountPoint($value);
114
+        } else {
115
+            $mount->setBackendOption($key, $value);
116
+        }
117
+        $this->globalService->updateStorage($mount);
118
+    }
119 119
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Controller/AjaxController.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -38,84 +38,84 @@
 block discarded – undo
38 38
 use OCP\IUserSession;
39 39
 
40 40
 class AjaxController extends Controller {
41
-	/** @var RSA */
42
-	private $rsaMechanism;
43
-	/** @var GlobalAuth  */
44
-	private $globalAuth;
45
-	/** @var IUserSession */
46
-	private $userSession;
47
-	/** @var IGroupManager */
48
-	private $groupManager;
41
+    /** @var RSA */
42
+    private $rsaMechanism;
43
+    /** @var GlobalAuth  */
44
+    private $globalAuth;
45
+    /** @var IUserSession */
46
+    private $userSession;
47
+    /** @var IGroupManager */
48
+    private $groupManager;
49 49
 
50
-	/**
51
-	 * @param string $appName
52
-	 * @param IRequest $request
53
-	 * @param RSA $rsaMechanism
54
-	 * @param GlobalAuth $globalAuth
55
-	 * @param IUserSession $userSession
56
-	 * @param IGroupManager $groupManager
57
-	 */
58
-	public function __construct($appName,
59
-								IRequest $request,
60
-								RSA $rsaMechanism,
61
-								GlobalAuth $globalAuth,
62
-								IUserSession $userSession,
63
-								IGroupManager $groupManager) {
64
-		parent::__construct($appName, $request);
65
-		$this->rsaMechanism = $rsaMechanism;
66
-		$this->globalAuth = $globalAuth;
67
-		$this->userSession = $userSession;
68
-		$this->groupManager = $groupManager;
69
-	}
50
+    /**
51
+     * @param string $appName
52
+     * @param IRequest $request
53
+     * @param RSA $rsaMechanism
54
+     * @param GlobalAuth $globalAuth
55
+     * @param IUserSession $userSession
56
+     * @param IGroupManager $groupManager
57
+     */
58
+    public function __construct($appName,
59
+                                IRequest $request,
60
+                                RSA $rsaMechanism,
61
+                                GlobalAuth $globalAuth,
62
+                                IUserSession $userSession,
63
+                                IGroupManager $groupManager) {
64
+        parent::__construct($appName, $request);
65
+        $this->rsaMechanism = $rsaMechanism;
66
+        $this->globalAuth = $globalAuth;
67
+        $this->userSession = $userSession;
68
+        $this->groupManager = $groupManager;
69
+    }
70 70
 
71
-	/**
72
-	 * @param int $keyLength
73
-	 * @return array
74
-	 */
75
-	private function generateSshKeys($keyLength) {
76
-		$key = $this->rsaMechanism->createKey($keyLength);
77
-		// Replace the placeholder label with a more meaningful one
78
-		$key['publickey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']);
71
+    /**
72
+     * @param int $keyLength
73
+     * @return array
74
+     */
75
+    private function generateSshKeys($keyLength) {
76
+        $key = $this->rsaMechanism->createKey($keyLength);
77
+        // Replace the placeholder label with a more meaningful one
78
+        $key['publickey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']);
79 79
 
80
-		return $key;
81
-	}
80
+        return $key;
81
+    }
82 82
 
83
-	/**
84
-	 * Generates an SSH public/private key pair.
85
-	 *
86
-	 * @NoAdminRequired
87
-	 * @param int $keyLength
88
-	 */
89
-	public function getSshKeys($keyLength = 1024) {
90
-		$key = $this->generateSshKeys($keyLength);
91
-		return new JSONResponse(
92
-			['data' => [
93
-				'private_key' => $key['privatekey'],
94
-				'public_key' => $key['publickey']
95
-			],
96
-				'status' => 'success'
97
-			]);
98
-	}
83
+    /**
84
+     * Generates an SSH public/private key pair.
85
+     *
86
+     * @NoAdminRequired
87
+     * @param int $keyLength
88
+     */
89
+    public function getSshKeys($keyLength = 1024) {
90
+        $key = $this->generateSshKeys($keyLength);
91
+        return new JSONResponse(
92
+            ['data' => [
93
+                'private_key' => $key['privatekey'],
94
+                'public_key' => $key['publickey']
95
+            ],
96
+                'status' => 'success'
97
+            ]);
98
+    }
99 99
 
100
-	/**
101
-	 * @NoAdminRequired
102
-	 *
103
-	 * @param string $uid
104
-	 * @param string $user
105
-	 * @param string $password
106
-	 * @return bool
107
-	 */
108
-	public function saveGlobalCredentials($uid, $user, $password) {
109
-		$currentUser = $this->userSession->getUser();
100
+    /**
101
+     * @NoAdminRequired
102
+     *
103
+     * @param string $uid
104
+     * @param string $user
105
+     * @param string $password
106
+     * @return bool
107
+     */
108
+    public function saveGlobalCredentials($uid, $user, $password) {
109
+        $currentUser = $this->userSession->getUser();
110 110
 
111
-		// Non-admins can only edit their own credentials
112
-		$allowedToEdit = ($this->groupManager->isAdmin($currentUser->getUID()) || $currentUser->getUID() === $uid);
111
+        // Non-admins can only edit their own credentials
112
+        $allowedToEdit = ($this->groupManager->isAdmin($currentUser->getUID()) || $currentUser->getUID() === $uid);
113 113
 
114
-		if ($allowedToEdit) {
115
-			$this->globalAuth->saveAuth($uid, $user, $password);
116
-			return true;
117
-		} else {
118
-			return false;
119
-		}
120
-	}
114
+        if ($allowedToEdit) {
115
+            $this->globalAuth->saveAuth($uid, $user, $password);
116
+            return true;
117
+        } else {
118
+            return false;
119
+        }
120
+    }
121 121
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/Notifications.php 1 patch
Indentation   +409 added lines, -409 removed lines patch added patch discarded remove patch
@@ -33,413 +33,413 @@
 block discarded – undo
33 33
 use OCP\OCS\IDiscoveryService;
34 34
 
35 35
 class Notifications {
36
-	const RESPONSE_FORMAT = 'json'; // default response format for ocs calls
37
-
38
-	/** @var AddressHandler */
39
-	private $addressHandler;
40
-
41
-	/** @var IClientService */
42
-	private $httpClientService;
43
-
44
-	/** @var IDiscoveryService */
45
-	private $discoveryService;
46
-
47
-	/** @var IJobList  */
48
-	private $jobList;
49
-
50
-	/** @var ICloudFederationProviderManager */
51
-	private $federationProviderManager;
52
-
53
-	/** @var ICloudFederationFactory */
54
-	private $cloudFederationFactory;
55
-
56
-	/**
57
-	 * @param AddressHandler $addressHandler
58
-	 * @param IClientService $httpClientService
59
-	 * @param IDiscoveryService $discoveryService
60
-	 * @param IJobList $jobList
61
-	 * @param ICloudFederationProviderManager $federationProviderManager
62
-	 * @param ICloudFederationFactory $cloudFederationFactory
63
-	 */
64
-	public function __construct(
65
-		AddressHandler $addressHandler,
66
-		IClientService $httpClientService,
67
-		IDiscoveryService $discoveryService,
68
-		IJobList $jobList,
69
-		ICloudFederationProviderManager $federationProviderManager,
70
-		ICloudFederationFactory $cloudFederationFactory
71
-	) {
72
-		$this->addressHandler = $addressHandler;
73
-		$this->httpClientService = $httpClientService;
74
-		$this->discoveryService = $discoveryService;
75
-		$this->jobList = $jobList;
76
-		$this->federationProviderManager = $federationProviderManager;
77
-		$this->cloudFederationFactory = $cloudFederationFactory;
78
-	}
79
-
80
-	/**
81
-	 * send server-to-server share to remote server
82
-	 *
83
-	 * @param string $token
84
-	 * @param string $shareWith
85
-	 * @param string $name
86
-	 * @param int $remote_id
87
-	 * @param string $owner
88
-	 * @param string $ownerFederatedId
89
-	 * @param string $sharedBy
90
-	 * @param string $sharedByFederatedId
91
-	 * @param int $shareType (can be a remote user or group share)
92
-	 * @return bool
93
-	 * @throws \OC\HintException
94
-	 * @throws \OC\ServerNotAvailableException
95
-	 */
96
-	public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId, $shareType) {
97
-
98
-		list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
99
-
100
-		if ($user && $remote) {
101
-			$local = $this->addressHandler->generateRemoteURL();
102
-
103
-			$fields = [
104
-				'shareWith' => $user,
105
-				'token' => $token,
106
-				'name' => $name,
107
-				'remoteId' => $remote_id,
108
-				'owner' => $owner,
109
-				'ownerFederatedId' => $ownerFederatedId,
110
-				'sharedBy' => $sharedBy,
111
-				'sharedByFederatedId' => $sharedByFederatedId,
112
-				'remote' => $local,
113
-				'shareType' => $shareType
114
-			];
115
-
116
-			$result = $this->tryHttpPostToShareEndpoint($remote, '', $fields);
117
-			$status = json_decode($result['result'], true);
118
-
119
-			$ocsStatus = isset($status['ocs']);
120
-			$ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200);
121
-
122
-			if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) {
123
-				\OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]);
124
-				return true;
125
-			}
126
-
127
-		}
128
-
129
-		return false;
130
-	}
131
-
132
-	/**
133
-	 * ask owner to re-share the file with the given user
134
-	 *
135
-	 * @param string $token
136
-	 * @param int $id remote Id
137
-	 * @param int $shareId internal share Id
138
-	 * @param string $remote remote address of the owner
139
-	 * @param string $shareWith
140
-	 * @param int $permission
141
-	 * @param string $filename
142
-	 * @return bool
143
-	 * @throws \OC\HintException
144
-	 * @throws \OC\ServerNotAvailableException
145
-	 */
146
-	public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission, $filename) {
147
-
148
-		$fields = [
149
-			'shareWith' => $shareWith,
150
-			'token' => $token,
151
-			'permission' => $permission,
152
-			'remoteId' => $shareId,
153
-		];
154
-
155
-		$ocmFields = $fields;
156
-		$ocmFields['remoteId'] = $id;
157
-		$ocmFields['localId'] = $shareId;
158
-		$ocmFields['name'] = $filename;
159
-
160
-		$ocmResult = $this->tryOCMEndPoint($remote, $ocmFields, 'reshare');
161
-		if (is_array($ocmResult) && isset($ocmResult['token']) && isset($ocmResult['providerId'])) {
162
-			return [$ocmResult['token'], $ocmResult['providerId']];
163
-		}
164
-
165
-		$result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields);
166
-		$status = json_decode($result['result'], true);
167
-
168
-		$httpRequestSuccessful = $result['success'];
169
-		$ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200;
170
-		$validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']);
171
-		$validRemoteId = isset($status['ocs']['data']['remoteId']);
172
-
173
-		if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) {
174
-			return [
175
-				$status['ocs']['data']['token'],
176
-				(int)$status['ocs']['data']['remoteId']
177
-			];
178
-		}
179
-
180
-		return false;
181
-	}
182
-
183
-	/**
184
-	 * send server-to-server unshare to remote server
185
-	 *
186
-	 * @param string $remote url
187
-	 * @param int $id share id
188
-	 * @param string $token
189
-	 * @return bool
190
-	 */
191
-	public function sendRemoteUnShare($remote, $id, $token) {
192
-		$this->sendUpdateToRemote($remote, $id, $token, 'unshare');
193
-	}
194
-
195
-	/**
196
-	 * send server-to-server unshare to remote server
197
-	 *
198
-	 * @param string $remote url
199
-	 * @param int $id share id
200
-	 * @param string $token
201
-	 * @return bool
202
-	 */
203
-	public function sendRevokeShare($remote, $id, $token) {
204
-		$this->sendUpdateToRemote($remote, $id, $token, 'reshare_undo');
205
-	}
206
-
207
-	/**
208
-	 * send notification to remote server if the permissions was changed
209
-	 *
210
-	 * @param string $remote
211
-	 * @param int $remoteId
212
-	 * @param string $token
213
-	 * @param int $permissions
214
-	 * @return bool
215
-	 */
216
-	public function sendPermissionChange($remote, $remoteId, $token, $permissions) {
217
-		$this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]);
218
-	}
219
-
220
-	/**
221
-	 * forward accept reShare to remote server
222
-	 *
223
-	 * @param string $remote
224
-	 * @param int $remoteId
225
-	 * @param string $token
226
-	 */
227
-	public function sendAcceptShare($remote, $remoteId, $token) {
228
-		$this->sendUpdateToRemote($remote, $remoteId, $token, 'accept');
229
-	}
230
-
231
-	/**
232
-	 * forward decline reShare to remote server
233
-	 *
234
-	 * @param string $remote
235
-	 * @param int $remoteId
236
-	 * @param string $token
237
-	 */
238
-	public function sendDeclineShare($remote, $remoteId, $token) {
239
-		$this->sendUpdateToRemote($remote, $remoteId, $token, 'decline');
240
-	}
241
-
242
-	/**
243
-	 * inform remote server whether server-to-server share was accepted/declined
244
-	 *
245
-	 * @param string $remote
246
-	 * @param string $token
247
-	 * @param int $remoteId Share id on the remote host
248
-	 * @param string $action possible actions: accept, decline, unshare, revoke, permissions
249
-	 * @param array $data
250
-	 * @param int $try
251
-	 * @return boolean
252
-	 */
253
-	public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) {
254
-
255
-		$fields = [
256
-			'token' => $token,
257
-			'remoteId' => $remoteId
258
-		];
259
-		foreach ($data as $key => $value) {
260
-			$fields[$key] = $value;
261
-		}
262
-
263
-		$result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields, $action);
264
-		$status = json_decode($result['result'], true);
265
-
266
-		if ($result['success'] &&
267
-			($status['ocs']['meta']['statuscode'] === 100 ||
268
-				$status['ocs']['meta']['statuscode'] === 200
269
-			)
270
-		) {
271
-			return true;
272
-		} elseif ($try === 0) {
273
-			// only add new job on first try
274
-			$this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob',
275
-				[
276
-					'remote' => $remote,
277
-					'remoteId' => $remoteId,
278
-					'token' => $token,
279
-					'action' => $action,
280
-					'data' => json_encode($data),
281
-					'try' => $try,
282
-					'lastRun' => $this->getTimestamp()
283
-				]
284
-			);
285
-		}
286
-
287
-		return false;
288
-	}
289
-
290
-
291
-	/**
292
-	 * return current timestamp
293
-	 *
294
-	 * @return int
295
-	 */
296
-	protected function getTimestamp() {
297
-		return time();
298
-	}
299
-
300
-	/**
301
-	 * try http post with the given protocol, if no protocol is given we pick
302
-	 * the secure one (https)
303
-	 *
304
-	 * @param string $remoteDomain
305
-	 * @param string $urlSuffix
306
-	 * @param array $fields post parameters
307
-	 * @param string $action define the action (possible values: share, reshare, accept, decline, unshare, revoke, permissions)
308
-	 * @return array
309
-	 * @throws \Exception
310
-	 */
311
-	protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action="share") {
312
-
313
-		if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) {
314
-			$remoteDomain = 'https://' . $remoteDomain;
315
-		}
316
-
317
-		$result = [
318
-			'success' => false,
319
-			'result' => '',
320
-		];
321
-
322
-		// if possible we use the new OCM API
323
-		$ocmResult = $this->tryOCMEndPoint($remoteDomain, $fields, $action);
324
-		if (is_array($ocmResult)) {
325
-			$result['success'] = true;
326
-			$result['result'] = json_encode([
327
-				'ocs' => ['meta' => ['statuscode' => 200]]]);
328
-			return $result;
329
-		}
330
-
331
-		return $this->tryLegacyEndPoint($remoteDomain, $urlSuffix, $fields);
332
-	}
333
-
334
-	/**
335
-	 * try old federated sharing API if the OCM api doesn't work
336
-	 *
337
-	 * @param $remoteDomain
338
-	 * @param $urlSuffix
339
-	 * @param array $fields
340
-	 * @return mixed
341
-	 * @throws \Exception
342
-	 */
343
-	protected function tryLegacyEndPoint($remoteDomain, $urlSuffix, array $fields) {
344
-
345
-		$result = [
346
-			'success' => false,
347
-			'result' => '',
348
-		];
349
-
350
-		// Fall back to old API
351
-		$client = $this->httpClientService->newClient();
352
-		$federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING');
353
-		$endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
354
-		try {
355
-			$response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [
356
-				'body' => $fields,
357
-				'timeout' => 10,
358
-				'connect_timeout' => 10,
359
-			]);
360
-			$result['result'] = $response->getBody();
361
-			$result['success'] = true;
362
-		} catch (\Exception $e) {
363
-			// if flat re-sharing is not supported by the remote server
364
-			// we re-throw the exception and fall back to the old behaviour.
365
-			// (flat re-shares has been introduced in Nextcloud 9.1)
366
-			if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
367
-				throw $e;
368
-			}
369
-		}
370
-
371
-		return $result;
372
-
373
-	}
374
-
375
-	/**
376
-	 * send action regarding federated sharing to the remote server using the OCM API
377
-	 *
378
-	 * @param $remoteDomain
379
-	 * @param $fields
380
-	 * @param $action
381
-	 *
382
-	 * @return bool
383
-	 */
384
-	protected function tryOCMEndPoint($remoteDomain, $fields, $action) {
385
-		switch ($action) {
386
-			case 'share':
387
-				$share = $this->cloudFederationFactory->getCloudFederationShare(
388
-					$fields['shareWith'] . '@' . $remoteDomain,
389
-					$fields['name'],
390
-					'',
391
-					$fields['remoteId'],
392
-					$fields['ownerFederatedId'],
393
-					$fields['owner'],
394
-					$fields['sharedByFederatedId'],
395
-					$fields['sharedBy'],
396
-					$fields['token'],
397
-					$fields['shareType'],
398
-					'file'
399
-				);
400
-				return $this->federationProviderManager->sendShare($share);
401
-			case 'reshare':
402
-				// ask owner to reshare a file
403
-				$notification = $this->cloudFederationFactory->getCloudFederationNotification();
404
-				$notification->setMessage('REQUEST_RESHARE',
405
-					'file',
406
-					$fields['remoteId'],
407
-					[
408
-						'sharedSecret' => $fields['token'],
409
-						'shareWith' => $fields['shareWith'],
410
-						'senderId' => $fields['localId'],
411
-						'shareType' => $fields['shareType'],
412
-						'message' => 'Ask owner to reshare the file'
413
-					]
414
-				);
415
-				return $this->federationProviderManager->sendNotification($remoteDomain, $notification);
416
-			case 'unshare':
417
-				//owner unshares the file from the recipient again
418
-				$notification = $this->cloudFederationFactory->getCloudFederationNotification();
419
-				$notification->setMessage('SHARE_UNSHARED',
420
-					'file',
421
-					$fields['remoteId'],
422
-					[
423
-						'sharedSecret' => $fields['token'],
424
-						'messgage' => 'file is no longer shared with you'
425
-					]
426
-				);
427
-				return $this->federationProviderManager->sendNotification($remoteDomain, $notification);
428
-			case 'reshare_undo':
429
-				// if a reshare was unshared we send the information to the initiator/owner
430
-				$notification = $this->cloudFederationFactory->getCloudFederationNotification();
431
-				$notification->setMessage('RESHARE_UNDO',
432
-					'file',
433
-					$fields['remoteId'],
434
-					[
435
-						'sharedSecret' => $fields['token'],
436
-						'message' => 'reshare was revoked'
437
-					]
438
-				);
439
-				return $this->federationProviderManager->sendNotification($remoteDomain, $notification);
440
-		}
441
-
442
-		return false;
443
-
444
-	}
36
+    const RESPONSE_FORMAT = 'json'; // default response format for ocs calls
37
+
38
+    /** @var AddressHandler */
39
+    private $addressHandler;
40
+
41
+    /** @var IClientService */
42
+    private $httpClientService;
43
+
44
+    /** @var IDiscoveryService */
45
+    private $discoveryService;
46
+
47
+    /** @var IJobList  */
48
+    private $jobList;
49
+
50
+    /** @var ICloudFederationProviderManager */
51
+    private $federationProviderManager;
52
+
53
+    /** @var ICloudFederationFactory */
54
+    private $cloudFederationFactory;
55
+
56
+    /**
57
+     * @param AddressHandler $addressHandler
58
+     * @param IClientService $httpClientService
59
+     * @param IDiscoveryService $discoveryService
60
+     * @param IJobList $jobList
61
+     * @param ICloudFederationProviderManager $federationProviderManager
62
+     * @param ICloudFederationFactory $cloudFederationFactory
63
+     */
64
+    public function __construct(
65
+        AddressHandler $addressHandler,
66
+        IClientService $httpClientService,
67
+        IDiscoveryService $discoveryService,
68
+        IJobList $jobList,
69
+        ICloudFederationProviderManager $federationProviderManager,
70
+        ICloudFederationFactory $cloudFederationFactory
71
+    ) {
72
+        $this->addressHandler = $addressHandler;
73
+        $this->httpClientService = $httpClientService;
74
+        $this->discoveryService = $discoveryService;
75
+        $this->jobList = $jobList;
76
+        $this->federationProviderManager = $federationProviderManager;
77
+        $this->cloudFederationFactory = $cloudFederationFactory;
78
+    }
79
+
80
+    /**
81
+     * send server-to-server share to remote server
82
+     *
83
+     * @param string $token
84
+     * @param string $shareWith
85
+     * @param string $name
86
+     * @param int $remote_id
87
+     * @param string $owner
88
+     * @param string $ownerFederatedId
89
+     * @param string $sharedBy
90
+     * @param string $sharedByFederatedId
91
+     * @param int $shareType (can be a remote user or group share)
92
+     * @return bool
93
+     * @throws \OC\HintException
94
+     * @throws \OC\ServerNotAvailableException
95
+     */
96
+    public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId, $shareType) {
97
+
98
+        list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
99
+
100
+        if ($user && $remote) {
101
+            $local = $this->addressHandler->generateRemoteURL();
102
+
103
+            $fields = [
104
+                'shareWith' => $user,
105
+                'token' => $token,
106
+                'name' => $name,
107
+                'remoteId' => $remote_id,
108
+                'owner' => $owner,
109
+                'ownerFederatedId' => $ownerFederatedId,
110
+                'sharedBy' => $sharedBy,
111
+                'sharedByFederatedId' => $sharedByFederatedId,
112
+                'remote' => $local,
113
+                'shareType' => $shareType
114
+            ];
115
+
116
+            $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields);
117
+            $status = json_decode($result['result'], true);
118
+
119
+            $ocsStatus = isset($status['ocs']);
120
+            $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200);
121
+
122
+            if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) {
123
+                \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]);
124
+                return true;
125
+            }
126
+
127
+        }
128
+
129
+        return false;
130
+    }
131
+
132
+    /**
133
+     * ask owner to re-share the file with the given user
134
+     *
135
+     * @param string $token
136
+     * @param int $id remote Id
137
+     * @param int $shareId internal share Id
138
+     * @param string $remote remote address of the owner
139
+     * @param string $shareWith
140
+     * @param int $permission
141
+     * @param string $filename
142
+     * @return bool
143
+     * @throws \OC\HintException
144
+     * @throws \OC\ServerNotAvailableException
145
+     */
146
+    public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission, $filename) {
147
+
148
+        $fields = [
149
+            'shareWith' => $shareWith,
150
+            'token' => $token,
151
+            'permission' => $permission,
152
+            'remoteId' => $shareId,
153
+        ];
154
+
155
+        $ocmFields = $fields;
156
+        $ocmFields['remoteId'] = $id;
157
+        $ocmFields['localId'] = $shareId;
158
+        $ocmFields['name'] = $filename;
159
+
160
+        $ocmResult = $this->tryOCMEndPoint($remote, $ocmFields, 'reshare');
161
+        if (is_array($ocmResult) && isset($ocmResult['token']) && isset($ocmResult['providerId'])) {
162
+            return [$ocmResult['token'], $ocmResult['providerId']];
163
+        }
164
+
165
+        $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields);
166
+        $status = json_decode($result['result'], true);
167
+
168
+        $httpRequestSuccessful = $result['success'];
169
+        $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200;
170
+        $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']);
171
+        $validRemoteId = isset($status['ocs']['data']['remoteId']);
172
+
173
+        if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) {
174
+            return [
175
+                $status['ocs']['data']['token'],
176
+                (int)$status['ocs']['data']['remoteId']
177
+            ];
178
+        }
179
+
180
+        return false;
181
+    }
182
+
183
+    /**
184
+     * send server-to-server unshare to remote server
185
+     *
186
+     * @param string $remote url
187
+     * @param int $id share id
188
+     * @param string $token
189
+     * @return bool
190
+     */
191
+    public function sendRemoteUnShare($remote, $id, $token) {
192
+        $this->sendUpdateToRemote($remote, $id, $token, 'unshare');
193
+    }
194
+
195
+    /**
196
+     * send server-to-server unshare to remote server
197
+     *
198
+     * @param string $remote url
199
+     * @param int $id share id
200
+     * @param string $token
201
+     * @return bool
202
+     */
203
+    public function sendRevokeShare($remote, $id, $token) {
204
+        $this->sendUpdateToRemote($remote, $id, $token, 'reshare_undo');
205
+    }
206
+
207
+    /**
208
+     * send notification to remote server if the permissions was changed
209
+     *
210
+     * @param string $remote
211
+     * @param int $remoteId
212
+     * @param string $token
213
+     * @param int $permissions
214
+     * @return bool
215
+     */
216
+    public function sendPermissionChange($remote, $remoteId, $token, $permissions) {
217
+        $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]);
218
+    }
219
+
220
+    /**
221
+     * forward accept reShare to remote server
222
+     *
223
+     * @param string $remote
224
+     * @param int $remoteId
225
+     * @param string $token
226
+     */
227
+    public function sendAcceptShare($remote, $remoteId, $token) {
228
+        $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept');
229
+    }
230
+
231
+    /**
232
+     * forward decline reShare to remote server
233
+     *
234
+     * @param string $remote
235
+     * @param int $remoteId
236
+     * @param string $token
237
+     */
238
+    public function sendDeclineShare($remote, $remoteId, $token) {
239
+        $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline');
240
+    }
241
+
242
+    /**
243
+     * inform remote server whether server-to-server share was accepted/declined
244
+     *
245
+     * @param string $remote
246
+     * @param string $token
247
+     * @param int $remoteId Share id on the remote host
248
+     * @param string $action possible actions: accept, decline, unshare, revoke, permissions
249
+     * @param array $data
250
+     * @param int $try
251
+     * @return boolean
252
+     */
253
+    public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) {
254
+
255
+        $fields = [
256
+            'token' => $token,
257
+            'remoteId' => $remoteId
258
+        ];
259
+        foreach ($data as $key => $value) {
260
+            $fields[$key] = $value;
261
+        }
262
+
263
+        $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields, $action);
264
+        $status = json_decode($result['result'], true);
265
+
266
+        if ($result['success'] &&
267
+            ($status['ocs']['meta']['statuscode'] === 100 ||
268
+                $status['ocs']['meta']['statuscode'] === 200
269
+            )
270
+        ) {
271
+            return true;
272
+        } elseif ($try === 0) {
273
+            // only add new job on first try
274
+            $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob',
275
+                [
276
+                    'remote' => $remote,
277
+                    'remoteId' => $remoteId,
278
+                    'token' => $token,
279
+                    'action' => $action,
280
+                    'data' => json_encode($data),
281
+                    'try' => $try,
282
+                    'lastRun' => $this->getTimestamp()
283
+                ]
284
+            );
285
+        }
286
+
287
+        return false;
288
+    }
289
+
290
+
291
+    /**
292
+     * return current timestamp
293
+     *
294
+     * @return int
295
+     */
296
+    protected function getTimestamp() {
297
+        return time();
298
+    }
299
+
300
+    /**
301
+     * try http post with the given protocol, if no protocol is given we pick
302
+     * the secure one (https)
303
+     *
304
+     * @param string $remoteDomain
305
+     * @param string $urlSuffix
306
+     * @param array $fields post parameters
307
+     * @param string $action define the action (possible values: share, reshare, accept, decline, unshare, revoke, permissions)
308
+     * @return array
309
+     * @throws \Exception
310
+     */
311
+    protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action="share") {
312
+
313
+        if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) {
314
+            $remoteDomain = 'https://' . $remoteDomain;
315
+        }
316
+
317
+        $result = [
318
+            'success' => false,
319
+            'result' => '',
320
+        ];
321
+
322
+        // if possible we use the new OCM API
323
+        $ocmResult = $this->tryOCMEndPoint($remoteDomain, $fields, $action);
324
+        if (is_array($ocmResult)) {
325
+            $result['success'] = true;
326
+            $result['result'] = json_encode([
327
+                'ocs' => ['meta' => ['statuscode' => 200]]]);
328
+            return $result;
329
+        }
330
+
331
+        return $this->tryLegacyEndPoint($remoteDomain, $urlSuffix, $fields);
332
+    }
333
+
334
+    /**
335
+     * try old federated sharing API if the OCM api doesn't work
336
+     *
337
+     * @param $remoteDomain
338
+     * @param $urlSuffix
339
+     * @param array $fields
340
+     * @return mixed
341
+     * @throws \Exception
342
+     */
343
+    protected function tryLegacyEndPoint($remoteDomain, $urlSuffix, array $fields) {
344
+
345
+        $result = [
346
+            'success' => false,
347
+            'result' => '',
348
+        ];
349
+
350
+        // Fall back to old API
351
+        $client = $this->httpClientService->newClient();
352
+        $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING');
353
+        $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
354
+        try {
355
+            $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [
356
+                'body' => $fields,
357
+                'timeout' => 10,
358
+                'connect_timeout' => 10,
359
+            ]);
360
+            $result['result'] = $response->getBody();
361
+            $result['success'] = true;
362
+        } catch (\Exception $e) {
363
+            // if flat re-sharing is not supported by the remote server
364
+            // we re-throw the exception and fall back to the old behaviour.
365
+            // (flat re-shares has been introduced in Nextcloud 9.1)
366
+            if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
367
+                throw $e;
368
+            }
369
+        }
370
+
371
+        return $result;
372
+
373
+    }
374
+
375
+    /**
376
+     * send action regarding federated sharing to the remote server using the OCM API
377
+     *
378
+     * @param $remoteDomain
379
+     * @param $fields
380
+     * @param $action
381
+     *
382
+     * @return bool
383
+     */
384
+    protected function tryOCMEndPoint($remoteDomain, $fields, $action) {
385
+        switch ($action) {
386
+            case 'share':
387
+                $share = $this->cloudFederationFactory->getCloudFederationShare(
388
+                    $fields['shareWith'] . '@' . $remoteDomain,
389
+                    $fields['name'],
390
+                    '',
391
+                    $fields['remoteId'],
392
+                    $fields['ownerFederatedId'],
393
+                    $fields['owner'],
394
+                    $fields['sharedByFederatedId'],
395
+                    $fields['sharedBy'],
396
+                    $fields['token'],
397
+                    $fields['shareType'],
398
+                    'file'
399
+                );
400
+                return $this->federationProviderManager->sendShare($share);
401
+            case 'reshare':
402
+                // ask owner to reshare a file
403
+                $notification = $this->cloudFederationFactory->getCloudFederationNotification();
404
+                $notification->setMessage('REQUEST_RESHARE',
405
+                    'file',
406
+                    $fields['remoteId'],
407
+                    [
408
+                        'sharedSecret' => $fields['token'],
409
+                        'shareWith' => $fields['shareWith'],
410
+                        'senderId' => $fields['localId'],
411
+                        'shareType' => $fields['shareType'],
412
+                        'message' => 'Ask owner to reshare the file'
413
+                    ]
414
+                );
415
+                return $this->federationProviderManager->sendNotification($remoteDomain, $notification);
416
+            case 'unshare':
417
+                //owner unshares the file from the recipient again
418
+                $notification = $this->cloudFederationFactory->getCloudFederationNotification();
419
+                $notification->setMessage('SHARE_UNSHARED',
420
+                    'file',
421
+                    $fields['remoteId'],
422
+                    [
423
+                        'sharedSecret' => $fields['token'],
424
+                        'messgage' => 'file is no longer shared with you'
425
+                    ]
426
+                );
427
+                return $this->federationProviderManager->sendNotification($remoteDomain, $notification);
428
+            case 'reshare_undo':
429
+                // if a reshare was unshared we send the information to the initiator/owner
430
+                $notification = $this->cloudFederationFactory->getCloudFederationNotification();
431
+                $notification->setMessage('RESHARE_UNDO',
432
+                    'file',
433
+                    $fields['remoteId'],
434
+                    [
435
+                        'sharedSecret' => $fields['token'],
436
+                        'message' => 'reshare was revoked'
437
+                    ]
438
+                );
439
+                return $this->federationProviderManager->sendNotification($remoteDomain, $notification);
440
+        }
441
+
442
+        return false;
443
+
444
+    }
445 445
 }
Please login to merge, or discard this patch.
apps/comments/lib/Activity/Provider.php 1 patch
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -36,244 +36,244 @@
 block discarded – undo
36 36
 
37 37
 class Provider implements IProvider {
38 38
 
39
-	/** @var IFactory */
40
-	protected $languageFactory;
41
-
42
-	/** @var IL10N */
43
-	protected $l;
44
-
45
-	/** @var IURLGenerator */
46
-	protected $url;
47
-
48
-	/** @var ICommentsManager */
49
-	protected $commentsManager;
50
-
51
-	/** @var IUserManager */
52
-	protected $userManager;
53
-
54
-	/** @var IManager */
55
-	protected $activityManager;
56
-
57
-	/** @var string[] */
58
-	protected $displayNames = [];
59
-
60
-	/**
61
-	 * @param IFactory $languageFactory
62
-	 * @param IURLGenerator $url
63
-	 * @param ICommentsManager $commentsManager
64
-	 * @param IUserManager $userManager
65
-	 * @param IManager $activityManager
66
-	 */
67
-	public function __construct(IFactory $languageFactory, IURLGenerator $url, ICommentsManager $commentsManager, IUserManager $userManager, IManager $activityManager) {
68
-		$this->languageFactory = $languageFactory;
69
-		$this->url = $url;
70
-		$this->commentsManager = $commentsManager;
71
-		$this->userManager = $userManager;
72
-		$this->activityManager = $activityManager;
73
-	}
74
-
75
-	/**
76
-	 * @param string $language
77
-	 * @param IEvent $event
78
-	 * @param IEvent|null $previousEvent
79
-	 * @return IEvent
80
-	 * @throws \InvalidArgumentException
81
-	 * @since 11.0.0
82
-	 */
83
-	public function parse($language, IEvent $event, IEvent $previousEvent = null) {
84
-		if ($event->getApp() !== 'comments') {
85
-			throw new \InvalidArgumentException();
86
-		}
87
-
88
-		$this->l = $this->languageFactory->get('comments', $language);
89
-
90
-		if ($event->getSubject() === 'add_comment_subject') {
91
-			$this->parseMessage($event);
92
-			if ($this->activityManager->getRequirePNG()) {
93
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.png')));
94
-			} else {
95
-				$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg')));
96
-			}
97
-
98
-			if ($this->activityManager->isFormattingFilteredObject()) {
99
-				try {
100
-					return $this->parseShortVersion($event);
101
-				} catch (\InvalidArgumentException $e) {
102
-					// Ignore and simply use the long version...
103
-				}
104
-			}
105
-
106
-			return $this->parseLongVersion($event);
107
-		} else {
108
-			throw new \InvalidArgumentException();
109
-		}
110
-	}
111
-
112
-	/**
113
-	 * @param IEvent $event
114
-	 * @return IEvent
115
-	 * @throws \InvalidArgumentException
116
-	 */
117
-	protected function parseShortVersion(IEvent $event) {
118
-		$subjectParameters = $this->getSubjectParameters($event);
119
-
120
-		if ($event->getSubject() === 'add_comment_subject') {
121
-			if ($subjectParameters['actor'] === $this->activityManager->getCurrentUserId()) {
122
-				$event->setParsedSubject($this->l->t('You commented'))
123
-					->setRichSubject($this->l->t('You commented'), []);
124
-			} else {
125
-				$author = $this->generateUserParameter($subjectParameters['actor']);
126
-				$event->setParsedSubject($this->l->t('%1$s commented', [$author['name']]))
127
-					->setRichSubject($this->l->t('{author} commented'), [
128
-						'author' => $author,
129
-					]);
130
-			}
131
-		} else {
132
-			throw new \InvalidArgumentException();
133
-		}
134
-
135
-		return $event;
136
-	}
137
-
138
-	/**
139
-	 * @param IEvent $event
140
-	 * @return IEvent
141
-	 * @throws \InvalidArgumentException
142
-	 */
143
-	protected function parseLongVersion(IEvent $event) {
144
-		$subjectParameters = $this->getSubjectParameters($event);
145
-
146
-		if ($event->getSubject() === 'add_comment_subject') {
147
-			if ($subjectParameters['actor'] === $this->activityManager->getCurrentUserId()) {
148
-				$event->setParsedSubject($this->l->t('You commented on %1$s', [
149
-					$subjectParameters['filePath'],
150
-				]))
151
-					->setRichSubject($this->l->t('You commented on {file}'), [
152
-						'file' => $this->generateFileParameter($subjectParameters['fileId'], $subjectParameters['filePath']),
153
-					]);
154
-			} else {
155
-				$author = $this->generateUserParameter($subjectParameters['actor']);
156
-				$event->setParsedSubject($this->l->t('%1$s commented on %2$s', [
157
-					$author['name'],
158
-					$subjectParameters['filePath'],
159
-				]))
160
-					->setRichSubject($this->l->t('{author} commented on {file}'), [
161
-						'author' => $author,
162
-						'file' => $this->generateFileParameter($subjectParameters['fileId'], $subjectParameters['filePath']),
163
-					]);
164
-			}
165
-		} else {
166
-			throw new \InvalidArgumentException();
167
-		}
168
-
169
-		return $event;
170
-	}
171
-
172
-	protected function getSubjectParameters(IEvent $event) {
173
-		$subjectParameters = $event->getSubjectParameters();
174
-		if (isset($subjectParameters['fileId'])) {
175
-			return $subjectParameters;
176
-		}
177
-
178
-		// Fix subjects from 12.0.3 and older
179
-		//
180
-		// Do NOT Remove unless necessary
181
-		// Removing this will break parsing of activities that were created on
182
-		// Nextcloud 12, so we should keep this as long as it's acceptable.
183
-		// Otherwise if people upgrade over multiple releases in a short period,
184
-		// they will get the dead entries in their stream.
185
-		return [
186
-			'actor' => $subjectParameters[0],
187
-			'fileId' => (int) $event->getObjectId(),
188
-			'filePath' => trim($subjectParameters[1], '/'),
189
-		];
190
-	}
191
-
192
-	/**
193
-	 * @param IEvent $event
194
-	 */
195
-	protected function parseMessage(IEvent $event) {
196
-		$messageParameters = $event->getMessageParameters();
197
-		if (empty($messageParameters)) {
198
-			// Email
199
-			return;
200
-		}
201
-
202
-		$commentId = isset($messageParameters['commentId']) ? $messageParameters['commentId'] : $messageParameters[0];
203
-
204
-		try {
205
-			$comment = $this->commentsManager->get((string) $commentId);
206
-			$message = $comment->getMessage();
207
-
208
-			$mentionCount = 1;
209
-			$mentions = [];
210
-			foreach ($comment->getMentions() as $mention) {
211
-				if ($mention['type'] !== 'user') {
212
-					continue;
213
-				}
214
-
215
-				$pattern = '/(^|\s)(' . '@' . $mention['id'] . ')(\b)/';
216
-				if (strpos($mention['id'], ' ') !== false) {
217
-					$pattern = '/(^|\s)(' . '@"' . $mention['id'] . '"' . ')(\b)?/';
218
-				}
219
-
220
-				$message = preg_replace(
221
-					$pattern,
222
-					//'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}',
223
-					'${1}' . '{mention' . $mentionCount . '}' . '${3}',
224
-					$message
225
-				);
226
-				$mentions['mention' . $mentionCount] = $this->generateUserParameter($mention['id']);
227
-				$mentionCount++;
228
-			}
229
-
230
-			$event->setParsedMessage($comment->getMessage())
231
-				->setRichMessage($message, $mentions);
232
-		} catch (NotFoundException $e) {
233
-		}
234
-	}
235
-
236
-	/**
237
-	 * @param int $id
238
-	 * @param string $path
239
-	 * @return array
240
-	 */
241
-	protected function generateFileParameter($id, $path) {
242
-		return [
243
-			'type' => 'file',
244
-			'id' => $id,
245
-			'name' => basename($path),
246
-			'path' => $path,
247
-			'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
248
-		];
249
-	}
250
-
251
-	/**
252
-	 * @param string $uid
253
-	 * @return array
254
-	 */
255
-	protected function generateUserParameter($uid) {
256
-		if (!isset($this->displayNames[$uid])) {
257
-			$this->displayNames[$uid] = $this->getDisplayName($uid);
258
-		}
259
-
260
-		return [
261
-			'type' => 'user',
262
-			'id' => $uid,
263
-			'name' => $this->displayNames[$uid],
264
-		];
265
-	}
266
-
267
-	/**
268
-	 * @param string $uid
269
-	 * @return string
270
-	 */
271
-	protected function getDisplayName($uid) {
272
-		$user = $this->userManager->get($uid);
273
-		if ($user instanceof IUser) {
274
-			return $user->getDisplayName();
275
-		} else {
276
-			return $uid;
277
-		}
278
-	}
39
+    /** @var IFactory */
40
+    protected $languageFactory;
41
+
42
+    /** @var IL10N */
43
+    protected $l;
44
+
45
+    /** @var IURLGenerator */
46
+    protected $url;
47
+
48
+    /** @var ICommentsManager */
49
+    protected $commentsManager;
50
+
51
+    /** @var IUserManager */
52
+    protected $userManager;
53
+
54
+    /** @var IManager */
55
+    protected $activityManager;
56
+
57
+    /** @var string[] */
58
+    protected $displayNames = [];
59
+
60
+    /**
61
+     * @param IFactory $languageFactory
62
+     * @param IURLGenerator $url
63
+     * @param ICommentsManager $commentsManager
64
+     * @param IUserManager $userManager
65
+     * @param IManager $activityManager
66
+     */
67
+    public function __construct(IFactory $languageFactory, IURLGenerator $url, ICommentsManager $commentsManager, IUserManager $userManager, IManager $activityManager) {
68
+        $this->languageFactory = $languageFactory;
69
+        $this->url = $url;
70
+        $this->commentsManager = $commentsManager;
71
+        $this->userManager = $userManager;
72
+        $this->activityManager = $activityManager;
73
+    }
74
+
75
+    /**
76
+     * @param string $language
77
+     * @param IEvent $event
78
+     * @param IEvent|null $previousEvent
79
+     * @return IEvent
80
+     * @throws \InvalidArgumentException
81
+     * @since 11.0.0
82
+     */
83
+    public function parse($language, IEvent $event, IEvent $previousEvent = null) {
84
+        if ($event->getApp() !== 'comments') {
85
+            throw new \InvalidArgumentException();
86
+        }
87
+
88
+        $this->l = $this->languageFactory->get('comments', $language);
89
+
90
+        if ($event->getSubject() === 'add_comment_subject') {
91
+            $this->parseMessage($event);
92
+            if ($this->activityManager->getRequirePNG()) {
93
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.png')));
94
+            } else {
95
+                $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg')));
96
+            }
97
+
98
+            if ($this->activityManager->isFormattingFilteredObject()) {
99
+                try {
100
+                    return $this->parseShortVersion($event);
101
+                } catch (\InvalidArgumentException $e) {
102
+                    // Ignore and simply use the long version...
103
+                }
104
+            }
105
+
106
+            return $this->parseLongVersion($event);
107
+        } else {
108
+            throw new \InvalidArgumentException();
109
+        }
110
+    }
111
+
112
+    /**
113
+     * @param IEvent $event
114
+     * @return IEvent
115
+     * @throws \InvalidArgumentException
116
+     */
117
+    protected function parseShortVersion(IEvent $event) {
118
+        $subjectParameters = $this->getSubjectParameters($event);
119
+
120
+        if ($event->getSubject() === 'add_comment_subject') {
121
+            if ($subjectParameters['actor'] === $this->activityManager->getCurrentUserId()) {
122
+                $event->setParsedSubject($this->l->t('You commented'))
123
+                    ->setRichSubject($this->l->t('You commented'), []);
124
+            } else {
125
+                $author = $this->generateUserParameter($subjectParameters['actor']);
126
+                $event->setParsedSubject($this->l->t('%1$s commented', [$author['name']]))
127
+                    ->setRichSubject($this->l->t('{author} commented'), [
128
+                        'author' => $author,
129
+                    ]);
130
+            }
131
+        } else {
132
+            throw new \InvalidArgumentException();
133
+        }
134
+
135
+        return $event;
136
+    }
137
+
138
+    /**
139
+     * @param IEvent $event
140
+     * @return IEvent
141
+     * @throws \InvalidArgumentException
142
+     */
143
+    protected function parseLongVersion(IEvent $event) {
144
+        $subjectParameters = $this->getSubjectParameters($event);
145
+
146
+        if ($event->getSubject() === 'add_comment_subject') {
147
+            if ($subjectParameters['actor'] === $this->activityManager->getCurrentUserId()) {
148
+                $event->setParsedSubject($this->l->t('You commented on %1$s', [
149
+                    $subjectParameters['filePath'],
150
+                ]))
151
+                    ->setRichSubject($this->l->t('You commented on {file}'), [
152
+                        'file' => $this->generateFileParameter($subjectParameters['fileId'], $subjectParameters['filePath']),
153
+                    ]);
154
+            } else {
155
+                $author = $this->generateUserParameter($subjectParameters['actor']);
156
+                $event->setParsedSubject($this->l->t('%1$s commented on %2$s', [
157
+                    $author['name'],
158
+                    $subjectParameters['filePath'],
159
+                ]))
160
+                    ->setRichSubject($this->l->t('{author} commented on {file}'), [
161
+                        'author' => $author,
162
+                        'file' => $this->generateFileParameter($subjectParameters['fileId'], $subjectParameters['filePath']),
163
+                    ]);
164
+            }
165
+        } else {
166
+            throw new \InvalidArgumentException();
167
+        }
168
+
169
+        return $event;
170
+    }
171
+
172
+    protected function getSubjectParameters(IEvent $event) {
173
+        $subjectParameters = $event->getSubjectParameters();
174
+        if (isset($subjectParameters['fileId'])) {
175
+            return $subjectParameters;
176
+        }
177
+
178
+        // Fix subjects from 12.0.3 and older
179
+        //
180
+        // Do NOT Remove unless necessary
181
+        // Removing this will break parsing of activities that were created on
182
+        // Nextcloud 12, so we should keep this as long as it's acceptable.
183
+        // Otherwise if people upgrade over multiple releases in a short period,
184
+        // they will get the dead entries in their stream.
185
+        return [
186
+            'actor' => $subjectParameters[0],
187
+            'fileId' => (int) $event->getObjectId(),
188
+            'filePath' => trim($subjectParameters[1], '/'),
189
+        ];
190
+    }
191
+
192
+    /**
193
+     * @param IEvent $event
194
+     */
195
+    protected function parseMessage(IEvent $event) {
196
+        $messageParameters = $event->getMessageParameters();
197
+        if (empty($messageParameters)) {
198
+            // Email
199
+            return;
200
+        }
201
+
202
+        $commentId = isset($messageParameters['commentId']) ? $messageParameters['commentId'] : $messageParameters[0];
203
+
204
+        try {
205
+            $comment = $this->commentsManager->get((string) $commentId);
206
+            $message = $comment->getMessage();
207
+
208
+            $mentionCount = 1;
209
+            $mentions = [];
210
+            foreach ($comment->getMentions() as $mention) {
211
+                if ($mention['type'] !== 'user') {
212
+                    continue;
213
+                }
214
+
215
+                $pattern = '/(^|\s)(' . '@' . $mention['id'] . ')(\b)/';
216
+                if (strpos($mention['id'], ' ') !== false) {
217
+                    $pattern = '/(^|\s)(' . '@"' . $mention['id'] . '"' . ')(\b)?/';
218
+                }
219
+
220
+                $message = preg_replace(
221
+                    $pattern,
222
+                    //'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}',
223
+                    '${1}' . '{mention' . $mentionCount . '}' . '${3}',
224
+                    $message
225
+                );
226
+                $mentions['mention' . $mentionCount] = $this->generateUserParameter($mention['id']);
227
+                $mentionCount++;
228
+            }
229
+
230
+            $event->setParsedMessage($comment->getMessage())
231
+                ->setRichMessage($message, $mentions);
232
+        } catch (NotFoundException $e) {
233
+        }
234
+    }
235
+
236
+    /**
237
+     * @param int $id
238
+     * @param string $path
239
+     * @return array
240
+     */
241
+    protected function generateFileParameter($id, $path) {
242
+        return [
243
+            'type' => 'file',
244
+            'id' => $id,
245
+            'name' => basename($path),
246
+            'path' => $path,
247
+            'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
248
+        ];
249
+    }
250
+
251
+    /**
252
+     * @param string $uid
253
+     * @return array
254
+     */
255
+    protected function generateUserParameter($uid) {
256
+        if (!isset($this->displayNames[$uid])) {
257
+            $this->displayNames[$uid] = $this->getDisplayName($uid);
258
+        }
259
+
260
+        return [
261
+            'type' => 'user',
262
+            'id' => $uid,
263
+            'name' => $this->displayNames[$uid],
264
+        ];
265
+    }
266
+
267
+    /**
268
+     * @param string $uid
269
+     * @return string
270
+     */
271
+    protected function getDisplayName($uid) {
272
+        $user = $this->userManager->get($uid);
273
+        if ($user instanceof IUser) {
274
+            return $user->getDisplayName();
275
+        } else {
276
+            return $uid;
277
+        }
278
+    }
279 279
 }
Please login to merge, or discard this patch.
core/templates/loginflow/grant.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@
 block discarded – undo
31 31
 	<h2><?php p($l->t('Account access')) ?></h2>
32 32
 	<p class="info">
33 33
 		<?php print_unescaped($l->t('You are about to grant %1$s access to your %2$s account.', [
34
-			'<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>',
35
-			\OCP\Util::sanitizeHTML($_['instanceName'])
36
-		])) ?>
34
+            '<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>',
35
+            \OCP\Util::sanitizeHTML($_['instanceName'])
36
+        ])) ?>
37 37
 	</p>
38 38
 
39 39
 	<br/>
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
 	<h2><?php p($l->t('Account access')) ?></h2>
32 32
 	<p class="info">
33 33
 		<?php print_unescaped($l->t('You are about to grant %1$s access to your %2$s account.', [
34
-			'<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>',
34
+			'<strong>'.\OCP\Util::sanitizeHTML($_['client']).'</strong>',
35 35
 			\OCP\Util::sanitizeHTML($_['instanceName'])
36 36
 		])) ?>
37 37
 	</p>
Please login to merge, or discard this patch.
core/templates/loginflow/authpicker.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@
 block discarded – undo
31 31
 	<h2><?php p($l->t('Connect to your account')) ?></h2>
32 32
 	<p class="info">
33 33
 		<?php print_unescaped($l->t('Please log in before granting %1$s access to your %2$s account.', [
34
-			'<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>',
35
-			\OCP\Util::sanitizeHTML($_['instanceName'])
36
-		])) ?>
34
+            '<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>',
35
+            \OCP\Util::sanitizeHTML($_['instanceName'])
36
+        ])) ?>
37 37
 	</p>
38 38
 
39 39
 	<br/>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	<h2><?php p($l->t('Connect to your account')) ?></h2>
32 32
 	<p class="info">
33 33
 		<?php print_unescaped($l->t('Please log in before granting %1$s access to your %2$s account.', [
34
-			'<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>',
34
+			'<strong>'.\OCP\Util::sanitizeHTML($_['client']).'</strong>',
35 35
 			\OCP\Util::sanitizeHTML($_['instanceName'])
36 36
 		])) ?>
37 37
 	</p>
@@ -59,6 +59,6 @@  discard block
 block discarded – undo
59 59
 	</form>
60 60
 </div>
61 61
 
62
-<?php if(empty($_['oauthState'])): ?>
62
+<?php if (empty($_['oauthState'])): ?>
63 63
 <a id="app-token-login" class="warning" href="#"><?php p($l->t('Alternative log in using app token')) ?></a>
64 64
 <?php endif; ?>
Please login to merge, or discard this patch.