Completed
Push — federated-circles ( 80cab6...74a72b )
by Maxence
02:32
created

FederatedController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 82
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B requestedLink() 0 45 4
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Circles\Controller;
28
29
use OC\AppFramework\Http;
30
use OCA\Circles\Model\Circle;
31
use OCA\Circles\Model\FederatedLink;
32
use OCA\Circles\Service\FederatedService;
33
use OCA\Circles\Service\CirclesService;
34
use OCA\Circles\Service\ConfigService;
35
use OCA\Circles\Service\MembersService;
36
use OCA\Circles\Service\MiscService;
37
use OCA\Circles\Service\SharesService;
38
use OCP\AppFramework\Http\DataResponse;
39
use OCP\IL10N;
40
use OCP\IRequest;
41
42
class FederatedController extends BaseController {
43
44
	/** @var string */
45
	protected $userId;
46
47
	/** @var IL10N */
48
	protected $l10n;
49
50
	/** @var ConfigService */
51
	protected $configService;
52
53
	/** @var CirclesService */
54
	protected $circlesService;
55
56
	/** @var MembersService */
57
	protected $membersService;
58
59
	/** @var SharesService */
60
	protected $sharesService;
61
62
	/** @var FederatedService */
63
	protected $federatedService;
64
65
	/** @var MiscService */
66
	protected $miscService;
67
68
69
	/**
70
	 * @PublicPage
71
	 * @NoCSRFRequired
72
	 *
73
	 * @param string $circleName
74
	 *
75
	 * @return DataResponse
76
	 */
77
	public function requestedLink($sourceId, $sourceName, $circleName) {
78
79
		if (!$this->configService->isFederatedAllowed()) {
80
			return new DataResponse(
81
				[
82
					'status' => FederatedService::STATUS_ERROR,
83
					'reason' => 'federated_not_allowed'
84
				],
85
				Http::STATUS_OK
86
			);
87
		}
88
89
		$circle = $this->circlesService->infoCircleByName($circleName);
90
		if ($circle === null) {
91
			return new DataResponse(
92
				[
93
					'status' => FederatedService::STATUS_ERROR,
94
					'reason' => 'circle_does_not_exist'
95
				],
96
				Http::STATUS_OK
97
			);
98
		}
99
100
		$link = new FederatedLink();
101
		$link->setRemoteCircleId($sourceId)
0 ignored issues
show
Bug introduced by
The method setRemoteCircleName cannot be called on $link->setRemoteCircleId($sourceId) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
102
			 ->setRemoteCircleName($sourceName);
103
		
104
		if (!$this->federatedService->initiateLink($circle, $link)) {
105
			return new DataResponse(
106
				[
107
					'status' => FederatedService::STATUS_LINK_UP,
108
					'token'  => $link->getToken()
109
				],
110
				Http::STATUS_OK
111
			);
112
		} else {
113
			return new DataResponse(
114
				[
115
					'status' => FederatedService::STATUS_REQUEST_SENT,
116
					'token'  => $link->getToken()
117
				],
118
				Http::STATUS_OK
119
			);
120
		}
121
	}
122
123
}