Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
['name' => 'Remote#circles', 'url' => '/circles/', 'verb' => 'GET'],
['name' => 'Remote#circle', 'url' => '/circle/{circleId}/', 'verb' => 'GET'],
['name' => 'Remote#members', 'url' => '/members/{circleId}/', 'verb' => 'GET'],
['name' => 'Remote#member', 'url' => '/member/{type}/{userId}/', 'verb' => 'GET']
['name' => 'Remote#member', 'url' => '/member/{type}/{userId}/', 'verb' => 'GET'],
['name' => 'Remote#inherited', 'url' => '/inherited/{circleId}/', 'verb' => 'GET'],
['name' => 'Remote#memberships', 'url' => '/memberships/{circleId}/', 'verb' => 'GET']
]
];
79 changes: 65 additions & 14 deletions lib/Controller/RemoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException;
use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidOriginException;
use ArtificialOwl\MySmallPhpTools\Exceptions\ItemNotFoundException;
use ArtificialOwl\MySmallPhpTools\Exceptions\JsonNotRequestedException;
use ArtificialOwl\MySmallPhpTools\Exceptions\MalformedArrayException;
use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException;
Expand Down Expand Up @@ -61,6 +62,7 @@
use OCA\Circles\Service\FederatedUserService;
use OCA\Circles\Service\InterfaceService;
use OCA\Circles\Service\MemberService;
use OCA\Circles\Service\MembershipService;
use OCA\Circles\Service\RemoteDownstreamService;
use OCA\Circles\Service\RemoteStreamService;
use OCP\AppFramework\Controller;
Expand Down Expand Up @@ -97,6 +99,9 @@ class RemoteController extends Controller {
/** @var MemberService */
private $memberService;

/** @var MembershipService */
private $membershipService;

/** @var InterfaceService */
private $interfaceService;

Expand All @@ -115,6 +120,7 @@ class RemoteController extends Controller {
* @param FederatedUserService $federatedUserService
* @param CircleService $circleService
* @param MemberService $memberService
* @param MembershipService $membershipService
* @param InterfaceService $interfaceService
* @param ConfigService $configService
*/
Expand All @@ -127,6 +133,7 @@ public function __construct(
FederatedUserService $federatedUserService,
CircleService $circleService,
MemberService $memberService,
MembershipService $membershipService,
InterfaceService $interfaceService,
ConfigService $configService
) {
Expand All @@ -137,6 +144,7 @@ public function __construct(
$this->federatedUserService = $federatedUserService;
$this->circleService = $circleService;
$this->memberService = $memberService;
$this->membershipService = $membershipService;
$this->interfaceService = $interfaceService;
$this->configService = $configService;

Expand Down Expand Up @@ -357,14 +365,63 @@ public function member(string $type, string $userId): DataResponse {
}


/**
* @PublicPage
* @NoCSRFRequired
*
* @param string $circleId
*
* @return DataResponse
*/
public function inherited(string $circleId): DataResponse {
try {
$this->extractDataFromFromRequest();
} catch (Exception $e) {
return $this->exceptionResponse($e, Http::STATUS_UNAUTHORIZED);
}

try {
$circle = $this->circleService->getCircle($circleId);

return new DataResponse($circle->getInheritedMembers());
} catch (Exception $e) {
return $this->exceptionResponse($e);
}
}


/**
* @PublicPage
* @NoCSRFRequired
*
* @param string $circleId
*
* @return DataResponse
*/
public function memberships(string $circleId): DataResponse {
try {
$this->extractDataFromFromRequest();
} catch (Exception $e) {
return $this->exceptionResponse($e, Http::STATUS_UNAUTHORIZED);
}

try {
$circle = $this->circleService->getCircle($circleId);

return new DataResponse($circle->getMemberships());
} catch (Exception $e) {
return $this->exceptionResponse($e);
}
}


/**
* @return FederatedEvent
* @throws InvalidItemException
* @throws InvalidOriginException
* @throws MalformedArrayException
* @throws SignatoryException
* @throws SignatureException
* @throws InvalidItemException
* @throws UnknownInterfaceException
*/
private function extractEventFromRequest(): FederatedEvent {
$signed = $this->remoteStreamService->incomingSignedRequest();
Expand Down Expand Up @@ -402,28 +459,22 @@ private function extractDataFromFromRequest(): SimpleDataStore {
try {
/** @var FederatedUser $initiator */
$initiator = $store->gObj('initiator', FederatedUser::class);
if (!is_null($initiator)) {
$this->federatedUserService->setCurrentUser($initiator);
}
} catch (InvalidItemException $e) {
$this->federatedUserService->setCurrentUser($initiator);
} catch (InvalidItemException | ItemNotFoundException $e) {
}

try {
/** @var FederatedUser $initiator */
$filterMember = $store->gObj('filterMember', Member::class);
if (!is_null($filterMember)) {
$data->aObj('filterMember', $filterMember);
}
} catch (InvalidItemException $e) {
$data->aObj('filterMember', $filterMember);
} catch (InvalidItemException | ItemNotFoundException $e) {
}

try {
/** @var FederatedUser $initiator */
$filterCircle = $store->gObj('filterCircle', Circle::class);
if (!is_null($filterCircle)) {
$data->aObj('filterCircle', $filterCircle);
}
} catch (InvalidItemException $e) {
$data->aObj('filterCircle', $filterCircle);
} catch (InvalidItemException | ItemNotFoundException $e) {
}

return $data;
Expand Down
50 changes: 50 additions & 0 deletions lib/Model/Federated/RemoteInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class RemoteInstance extends NC22Signatory implements INC22QueryRow, JsonSeriali
public const CIRCLE = 'circle';
public const MEMBERS = 'members';
public const MEMBER = 'member';
public const MEMBERSHIPS = 'memberships';
public const INHERITED = 'inherited';


/** @var int */
Expand Down Expand Up @@ -105,6 +107,12 @@ class RemoteInstance extends NC22Signatory implements INC22QueryRow, JsonSeriali
/** @var string */
private $member = '';

/** @var string */
private $inherited = '';

/** @var string */
private $memberships = '';

/** @var string */
private $uid = '';

Expand Down Expand Up @@ -324,6 +332,44 @@ public function setMembers(string $members): self {
}


/**
* @return string
*/
public function getInherited(): string {
return $this->inherited;
}

/**
* @param string $inherited
*
* @return self
*/
public function setInherited(string $inherited): self {
$this->inherited = $inherited;

return $this;
}


/**
* @return string
*/
public function getMemberships(): string {
return $this->memberships;
}

/**
* @param string $memberships
*
* @return self
*/
public function setMemberships(string $memberships): self {
$this->memberships = $memberships;

return $this;
}


/**
* @return string
*/
Expand Down Expand Up @@ -441,6 +487,8 @@ public function import(array $data): NC22Signatory {
->setCircle($this->get('circle', $data))
->setMembers($this->get('members', $data))
->setMember($this->get('member', $data))
->setInherited($this->get('inherited', $data))
->setMemberships($this->get('memberships', $data))
->setUid($this->get('uid', $data));

$algo = '';
Expand Down Expand Up @@ -470,6 +518,8 @@ public function jsonSerialize(): array {
'circle' => $this->getCircle(),
'members' => $this->getMembers(),
'member' => $this->getMember(),
'inherited' => $this->getInherited(),
'memberships' => $this->getMemberships()
];

if ($this->getAuthSigned() !== '') {
Expand Down
71 changes: 71 additions & 0 deletions lib/Service/RemoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use OCA\Circles\Model\Federated\RemoteInstance;
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\Membership;

/**
* Class RemoteService
Expand Down Expand Up @@ -204,6 +205,76 @@ public function getMembersFromInstance(string $circleId, string $instance, array
}


/**
* @param string $circleId
* @param string $instance
* @param array $data
*
* @return Member[]
* @throws FederatedItemException
* @throws RemoteInstanceException
* @throws RemoteNotFoundException
* @throws RemoteResourceNotFoundException
* @throws UnknownRemoteException
*/
public function getInheritedFromInstance(string $circleId, string $instance, array $data = []): array {
$result = $this->remoteStreamService->resultRequestRemoteInstance(
$instance,
RemoteInstance::INHERITED,
Request::TYPE_GET,
new SimpleDataStore($data),
['circleId' => $circleId]
);

$members = [];
foreach ($result as $item) {
try {
$member = new Member();
$member->import($item);
$members[] = $member;
} catch (InvalidItemException $e) {
}
}

return $members;
}


/**
* @param string $circleId
* @param string $instance
* @param array $data
*
* @return Membership[]
* @throws FederatedItemException
* @throws RemoteInstanceException
* @throws RemoteNotFoundException
* @throws RemoteResourceNotFoundException
* @throws UnknownRemoteException
*/
public function getMembershipsFromInstance(string $circleId, string $instance, array $data = []): array {
$result = $this->remoteStreamService->resultRequestRemoteInstance(
$instance,
RemoteInstance::MEMBERSHIPS,
Request::TYPE_GET,
new SimpleDataStore($data),
['circleId' => $circleId]
);

$members = [];
foreach ($result as $item) {
try {
$member = new Membership();
$member->import($item);
$members[] = $member;
} catch (InvalidItemException $e) {
}
}

return $members;
}


/**
* @param Circle $circle
*
Expand Down
19 changes: 18 additions & 1 deletion lib/Service/RemoteStreamService.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,24 @@ public function getAppSignatory(bool $generate = true, string $confirmKey = ''):
$app->setMember(
urldecode(
$this->interfaceService->getCloudPath(
'circles.Remote.member', ['type' => '{type}', 'userId' => '{userId}']
'circles.Remote.member',
['type' => '{type}', 'userId' => '{userId}']
)
)
);
$app->setInherited(
urldecode(
$this->interfaceService->getCloudPath(
'circles.Remote.inherited',
['circleId' => '{circleId}']
)
)
);
$app->setMemberships(
urldecode(
$this->interfaceService->getCloudPath(
'circles.Remote.memberships',
['circleId' => '{circleId}']
)
)
);
Expand Down