| @@ 186-207 (lines=22) @@ | ||
| 183 | * @return DataResponse |
|
| 184 | * @throws OCSException |
|
| 185 | */ |
|
| 186 | public function memberAdd(string $emulated, string $circleId, string $userId, int $type): DataResponse { |
|
| 187 | try { |
|
| 188 | $this->setLocalFederatedUser($emulated); |
|
| 189 | ||
| 190 | // exception in Contact |
|
| 191 | if ($type === Member::TYPE_CONTACT) { |
|
| 192 | $currentUser = $this->federatedUserService->getCurrentUser(); |
|
| 193 | if (!$this->configService->isLocalInstance($currentUser->getInstance())) { |
|
| 194 | throw new OCSException('works only from local instance', 404); |
|
| 195 | } |
|
| 196 | ||
| 197 | $userId = $currentUser->getUserId() . '/' . $userId; |
|
| 198 | } |
|
| 199 | ||
| 200 | $federatedUser = $this->federatedUserService->generateFederatedUser($userId, $type); |
|
| 201 | $result = $this->memberService->addMember($circleId, $federatedUser); |
|
| 202 | ||
| 203 | return new DataResponse($this->serializeArray($result)); |
|
| 204 | } catch (Exception $e) { |
|
| 205 | throw new OCSException($e->getMessage(), $e->getCode()); |
|
| 206 | } |
|
| 207 | } |
|
| 208 | ||
| 209 | ||
| 210 | /** |
|
| @@ 219-240 (lines=22) @@ | ||
| 216 | * @return DataResponse |
|
| 217 | * @throws OCSException |
|
| 218 | */ |
|
| 219 | public function memberAdd(string $circleId, string $userId, int $type): DataResponse { |
|
| 220 | try { |
|
| 221 | $this->setCurrentFederatedUser(); |
|
| 222 | ||
| 223 | // exception in Contact |
|
| 224 | if ($type === Member::TYPE_CONTACT) { |
|
| 225 | $currentUser = $this->federatedUserService->getCurrentUser(); |
|
| 226 | if (!$this->configService->isLocalInstance($currentUser->getInstance())) { |
|
| 227 | throw new OCSException('works only from local instance', 404); |
|
| 228 | } |
|
| 229 | ||
| 230 | $userId = $currentUser->getUserId() . '/' . $userId; |
|
| 231 | } |
|
| 232 | ||
| 233 | $federatedUser = $this->federatedUserService->generateFederatedUser($userId, $type); |
|
| 234 | $result = $this->memberService->addMember($circleId, $federatedUser); |
|
| 235 | ||
| 236 | return new DataResponse($this->serializeArray($result)); |
|
| 237 | } catch (Exception $e) { |
|
| 238 | throw new OCSException($e->getMessage(), $e->getCode()); |
|
| 239 | } |
|
| 240 | } |
|
| 241 | ||
| 242 | ||
| 243 | /** |
|