Completed
Push — master ( 6a3d7a...383329 )
by Maxence
03:05 queued 10s
created

Circles::generateLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
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
 * @author Vinicius Cubas Brand <[email protected]>
10
 * @author Daniel Tygel <[email protected]>
11
 *
12
 * @copyright 2017
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
namespace OCA\Circles\Api\v1;
31
32
33
use daita\MySmallPhpTools\Model\SimpleDataStore;
34
use OCA\Circles\Exceptions\CircleNotFoundException;
35
use OCA\Circles\Exceptions\FederatedUserException;
36
use OCA\Circles\Exceptions\FederatedUserNotFoundException;
37
use OCA\Circles\Exceptions\InitiatorNotFoundException;
38
use OCA\Circles\Exceptions\InvalidIdException;
39
use OCA\Circles\Exceptions\RequestBuilderException;
40
use OCA\Circles\Exceptions\SingleCircleNotFoundException;
41
use OCA\Circles\Model\Circle;
42
use OCA\Circles\Model\DeprecatedCircle;
43
use OCA\Circles\Model\DeprecatedMember;
44
use OCA\Circles\Model\Member;
45
use OCA\Circles\Service\CircleService;
46
use OCA\Circles\Service\FederatedUserService;
47
48
class Circles {
49
50
	const API_VERSION = [0, 10, 0];
51
52
	// Expose circle and member constants via API
53
	const CIRCLES_PERSONAL = DeprecatedCircle::CIRCLES_PERSONAL;
54
	const CIRCLES_SECRET = DeprecatedCircle::CIRCLES_SECRET;
55
	const CIRCLES_CLOSED = DeprecatedCircle::CIRCLES_CLOSED;
56
	const CIRCLES_PUBLIC = DeprecatedCircle::CIRCLES_PUBLIC;
57
	const CIRCLES_ALL = DeprecatedCircle::CIRCLES_ALL;
58
59
	const TYPE_USER = DeprecatedMember::TYPE_USER;
60
	const TYPE_GROUP = DeprecatedMember::TYPE_GROUP;
61
	const TYPE_MAIL = DeprecatedMember::TYPE_MAIL;
62
	const TYPE_CONTACT = DeprecatedMember::TYPE_CONTACT;
63
64
	const LEVEL_NONE = DeprecatedMember::LEVEL_NONE;
65
	const LEVEL_MEMBER = DeprecatedMember::LEVEL_MEMBER;
66
	const LEVEL_MODERATOR = DeprecatedMember::LEVEL_MODERATOR;
67
	const LEVEL_ADMIN = DeprecatedMember::LEVEL_ADMIN;
68
	const LEVEL_OWNER = DeprecatedMember::LEVEL_OWNER;
69
70
71
	/**
72
	 * Circles::listCircles();
73
	 *
74
	 * This function list all circles fitting a search regarding its name and the level and the
75
	 * rights from the current user. In case of Secret circle, name needs to be complete so the
76
	 * circle is included in the list (or if the current user is the owner)
77
	 *
78
	 * example: Circles::listCircles(Circles::CIRCLES_ALL, '', 8, callback); will returns all
79
	 * circles when the current user is at least an Admin.
80
	 *
81
	 * @param mixed $type
82
	 * @param string $name
83
	 * @param int $level
84
	 * @param string $userId
85
	 * @param bool $forceAll
86
	 *
87
	 * @return Circle[]
88
	 */
89 View Code Duplication
	public static function listCircles($type, $name = '', $level = 0, $userId = '', $forceAll = false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $level is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
		/** @var FederatedUserService $federatedUserService */
91
		$federatedUserService = \OC::$server->get(FederatedUserService::class);
92
93
		$personalCircle = false;
94
		if ($forceAll) {
95
			$personalCircle = true;
96
		}
97
98
99
		if ($userId === '') {
100
			$federatedUserService->initCurrentUser();
101
		} else {
102
			$federatedUserService->setLocalCurrentUserId($userId);
103
		}
104
105
		/** @var CircleService $circleService */
106
		$circleService = \OC::$server->get(CircleService::class);
107
108
		return $circleService->getCircles(
109
			null,
110
			null,
111
			new SimpleDataStore(['includePersonalCircles' => $personalCircle])
112
		);
113
	}
114
115
116
	/**
117
	 * @param string $userId
118
	 * @param bool $forceAll
119
	 *
120
	 * @return Circle[]
121
	 * @throws FederatedUserException
122
	 * @throws FederatedUserNotFoundException
123
	 * @throws InitiatorNotFoundException
124
	 * @throws InvalidIdException
125
	 * @throws RequestBuilderException
126
	 * @throws SingleCircleNotFoundException
127
	 *
128
	 * @deprecated - used by apps/dav/lib/Connector/Sabre/Principal.php
129
	 *
130
	 * Circles::joinedCircles();
131
	 *
132
	 * Return all the circle the current user is a member.
133
	 */
134 View Code Duplication
	public static function joinedCircles($userId = '', $forceAll = false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
135
		/** @var FederatedUserService $federatedUserService */
136
		$federatedUserService = \OC::$server->get(FederatedUserService::class);
137
138
		$personalCircle = false;
139
		if ($forceAll) {
140
			$personalCircle = true;
141
		}
142
143
		if ($userId === '') {
144
			$federatedUserService->initCurrentUser();
145
		} else {
146
			$federatedUserService->setLocalCurrentUserId($userId);
147
		}
148
149
		/** @var CircleService $circleService */
150
		$circleService = \OC::$server->get(CircleService::class);
151
152
		return $circleService->getCircles(
153
			null,
154
			null,
155
			new SimpleDataStore(
156
				[
157
					'mustBeMember'           => true,
158
					'includePersonalCircles' => $personalCircle
159
				]
160
			)
161
		);
162
	}
163
164
165
	/**
166
	 * @param string $circleUniqueId
167
	 * @param bool $forceAll
168
	 *
169
	 * @return Circle
170
	 * @throws CircleNotFoundException
171
	 * @throws FederatedUserException
172
	 * @throws FederatedUserNotFoundException
173
	 * @throws InitiatorNotFoundException
174
	 * @throws InvalidIdException
175
	 * @throws RequestBuilderException
176
	 * @throws SingleCircleNotFoundException
177
	 *
178
	 * @deprecated - used by apps/dav/lib/Connector/Sabre/Principal.php
179
	 *             - used by apps/files_sharing/lib/Controller/ShareAPIController.php
180
	 *             - used by lib/private/Share20/Manager.php
181
	 *
182
	 * Circles::detailsCircle();
183
	 *
184
	 * WARNING - This function is called by the core - WARNING
185
	 *                 Do not change it
186
	 *
187
	 * Returns details on the circle. If the current user is a member, the members list will be
188
	 * return as well.
189
	 *
190
	 */
191
	public static function detailsCircle(string $circleUniqueId, bool $forceAll = false): Circle {
192
		/** @var FederatedUserService $federatedUserService */
193
		$federatedUserService = \OC::$server->get(FederatedUserService::class);
194
		if ($forceAll) {
195
			$federatedUserService->bypassCurrentUserCondition($forceAll);
196
		} else {
197
			$federatedUserService->initCurrentUser();
198
		}
199
200
		/** @var CircleService $circleService */
201
		$circleService = \OC::$server->get(CircleService::class);
202
203
		return $circleService->getCircle($circleUniqueId);
204
	}
205
206
207
	/**
208
	 * @param string $circleUniqueId
209
	 * @param string $ident
210
	 * @param int $type
211
	 * @param bool $forceAll
212
	 *
213
	 * @return Member
214
	 *
215
	 * @deprecated - used by apps/files_sharing/lib/Controller/ShareAPIController.php
216
	 *
217
	 * Circles::getMember();
218
	 *
219
	 * This function will return information on a member of the circle. Current user need at least
220
	 * to be Member.
221
	 *
222
	 */
223
	public static function getMember($circleUniqueId, $ident, $type, $forceAll = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $circleUniqueId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $ident is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $forceAll is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
224
//		$c = self::getContainer();
225
//
226
//		return $c->query(MembersService::class)
227
//				 ->getMember($circleUniqueId, $ident, $type, $forceAll);
228
	}
229
230
231
	/**
232
	 * @param array $circleUniqueIds
233
	 *
234
	 * @return string[] array of object ids or empty array if none found
235
	 *
236
	 * @deprecated - used by apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
237
	 *
238
	 * Get a list of objects which are shred with $circleUniqueId.
239
	 *
240
	 * @since 0.14.0
241
	 *
242
	 */
243
	public static function getFilesForCircles($circleUniqueIds) {
0 ignored issues
show
Unused Code introduced by
The parameter $circleUniqueIds is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
244
//		$c = self::getContainer();
245
//
246
//		return $c->query(CirclesService::class)
247
//				 ->getFilesForCircles($circleUniqueIds);
248
	}
249
250
}
251
252