Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Circles.php « v1 « Api « lib - github.com/nextcloud/circles.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a2b94bb44ad6484ea39aad671b324d8fd85ed1e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/**
 * Circles - Bring cloud-users closer together.
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Maxence Lange <maxence@artificial-owl.com>
 * @author Vinicius Cubas Brand <vinicius@eita.org.br>
 * @author Daniel Tygel <dtygel@eita.org.br>
 *
 * @copyright 2017
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace OCA\Circles\Api\v1;

use OCA\Circles\Exceptions\CircleNotFoundException;
use OCA\Circles\Exceptions\FederatedUserException;
use OCA\Circles\Exceptions\FederatedUserNotFoundException;
use OCA\Circles\Exceptions\InitiatorNotFoundException;
use OCA\Circles\Exceptions\InvalidIdException;
use OCA\Circles\Exceptions\RequestBuilderException;
use OCA\Circles\Exceptions\SingleCircleNotFoundException;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\Probes\CircleProbe;
use OCA\Circles\Service\CircleService;
use OCA\Circles\Service\FederatedUserService;

class Circles {
	public const API_VERSION = [0, 10, 0];

	// Expose circle and member constants via API
	public const CIRCLES_PERSONAL = 1;
	public const CIRCLES_SECRET = 2;
	public const CIRCLES_CLOSED = 4;
	public const CIRCLES_PUBLIC = 8;
	public const CIRCLES_ALL = 15;

	public const TYPE_USER = Member::TYPE_USER;
	public const TYPE_GROUP = Member::TYPE_GROUP;
	public const TYPE_MAIL = Member::TYPE_MAIL;
	public const TYPE_CONTACT = Member::TYPE_CONTACT;

	public const LEVEL_NONE = Member::LEVEL_NONE;
	public const LEVEL_MEMBER = Member::LEVEL_MEMBER;
	public const LEVEL_MODERATOR = Member::LEVEL_MODERATOR;
	public const LEVEL_ADMIN = Member::LEVEL_ADMIN;
	public const LEVEL_OWNER = Member::LEVEL_OWNER;


	/**
	 * Circles::listCircles();
	 *
	 * This function list all circles fitting a search regarding its name and the level and the
	 * rights from the current user. In case of Secret circle, name needs to be complete so the
	 * circle is included in the list (or if the current user is the owner)
	 *
	 * example: Circles::listCircles(Circles::CIRCLES_ALL, '', 8, callback); will returns all
	 * circles when the current user is at least an Admin.
	 *
	 * @param mixed $type
	 * @param string $name
	 * @param int $level
	 * @param string $userId
	 * @param bool $forceAll
	 *
	 * @return Circle[]
	 */
	public static function listCircles($type, $name = '', $level = 0, $userId = '', $forceAll = false) {
		/** @var FederatedUserService $federatedUserService */
		$federatedUserService = \OC::$server->get(FederatedUserService::class);

		$personalCircle = false;
		if ($forceAll) {
			$personalCircle = true;
		}

		if ($userId === '') {
			$federatedUserService->initCurrentUser();
		} else {
			$federatedUserService->setLocalCurrentUserId($userId);
		}

		/** @var CircleService $circleService */
		$circleService = \OC::$server->get(CircleService::class);

		$probe = new CircleProbe();
		$probe->includePersonalCircles($personalCircle);
		$probe->filterHiddenCircles();

		return $circleService->getCircles($probe);
	}


	/**
	 * @param string $userId
	 * @param bool $forceAll
	 *
	 * @return Circle[]
	 * @throws FederatedUserException
	 * @throws FederatedUserNotFoundException
	 * @throws InitiatorNotFoundException
	 * @throws InvalidIdException
	 * @throws RequestBuilderException
	 * @throws SingleCircleNotFoundException
	 *
	 * @deprecated - used by apps/dav/lib/Connector/Sabre/Principal.php
	 *
	 * Circles::joinedCircles();
	 *
	 * Return all the circle the current user is a member.
	 */
	public static function joinedCircles($userId = '', $forceAll = false) {
		/** @var FederatedUserService $federatedUserService */
		$federatedUserService = \OC::$server->get(FederatedUserService::class);

		$personalCircle = false;
		if ($forceAll) {
			$personalCircle = true;
		}

		if ($userId === '') {
			$federatedUserService->initCurrentUser();
		} else {
			$federatedUserService->setLocalCurrentUserId($userId);
		}

		/** @var CircleService $circleService */
		$circleService = \OC::$server->get(CircleService::class);

		$probe = new CircleProbe();
		$probe->mustBeMember();
		$probe->includePersonalCircles($personalCircle);
		$probe->filterHiddenCircles();

		return $circleService->getCircles($probe);
	}


	/**
	 * @param string $circleUniqueId
	 * @param bool $forceAll
	 *
	 * @return Circle
	 * @throws CircleNotFoundException
	 * @throws FederatedUserException
	 * @throws FederatedUserNotFoundException
	 * @throws InitiatorNotFoundException
	 * @throws InvalidIdException
	 * @throws RequestBuilderException
	 * @throws SingleCircleNotFoundException
	 *
	 * @deprecated - used by apps/dav/lib/Connector/Sabre/Principal.php
	 *             - used by apps/files_sharing/lib/Controller/ShareAPIController.php
	 *             - used by lib/private/Share20/Manager.php
	 *
	 * Circles::detailsCircle();
	 *
	 * WARNING - This function is called by the core - WARNING
	 *                 Do not change it
	 *
	 * Returns details on the circle. If the current user is a member, the members list will be
	 * return as well.
	 *
	 */
	public static function detailsCircle(string $circleUniqueId, bool $forceAll = false): Circle {
		/** @var FederatedUserService $federatedUserService */
		$federatedUserService = \OC::$server->get(FederatedUserService::class);
		if ($forceAll) {
			$federatedUserService->bypassCurrentUserCondition($forceAll);
		} else {
			$federatedUserService->initCurrentUser();
		}

		/** @var CircleService $circleService */
		$circleService = \OC::$server->get(CircleService::class);

		return $circleService->getCircle($circleUniqueId);
	}


	/**
	 * @param string $circleUniqueId
	 * @param string $ident
	 * @param int $type
	 * @param bool $forceAll
	 *
	 * @return Member
	 *
	 * @deprecated - used by apps/files_sharing/lib/Controller/ShareAPIController.php
	 *
	 * Circles::getMember();
	 *
	 * This function will return information on a member of the circle. Current user need at least
	 * to be Member.
	 *
	 */
	public static function getMember($circleUniqueId, $ident, $type, $forceAll = false) {
		throw new \BadMethodCallException('Method is deprecated and not longer works');
	}


	/**
	 * @param array $circleUniqueIds
	 *
	 * @return string[] array of object ids or empty array if none found
	 *
	 * @deprecated - used by apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
	 *
	 * Get a list of objects which are shred with $circleUniqueId.
	 *
	 * @since 0.14.0
	 *
	 */
	public static function getFilesForCircles($circleUniqueIds) {
		throw new \BadMethodCallException('Method is deprecated and not longer works');
	}
}