Browse Source
Add an API endpoint to get all invites
Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/6663/head
Joas Schilling
4 years ago
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
5 changed files with
41 additions and
0 deletions
-
appinfo/routes/routesFederationController.php
-
lib/Controller/FederationController.php
-
lib/Federation/FederationManager.php
-
lib/Model/InvitationMapper.php
-
tests/php/RoomTest.php
|
|
|
@ -31,5 +31,6 @@ return [ |
|
|
|
'ocs' => [ |
|
|
|
['name' => 'Federation#acceptShare', 'url' => 'api/{apiVersion}/federation/invitation/{id}', 'verb' => 'POST', 'requirements' => $requirements], |
|
|
|
['name' => 'Federation#rejectShare', 'url' => 'api/{apiVersion}/federation/invitation/{id}', 'verb' => 'DELETE', 'requirements' => $requirements], |
|
|
|
['name' => 'Federation#getShares', 'url' => 'api/{apiVersion}/federation/invitation', 'verb' => 'GET', 'requirements' => $requirements], |
|
|
|
], |
|
|
|
]; |
|
|
|
@ -84,4 +84,18 @@ class FederationController extends OCSController { |
|
|
|
$this->federationManager->rejectRemoteRoomShare($user, $id); |
|
|
|
return new DataResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @NoAdminRequired |
|
|
|
* |
|
|
|
* @return DataResponse |
|
|
|
*/ |
|
|
|
public function getShares(): DataResponse { |
|
|
|
$user = $this->userSession->getUser(); |
|
|
|
if (!$user instanceof IUser) { |
|
|
|
throw new UnauthorizedException(); |
|
|
|
} |
|
|
|
$invitations = $this->federationManager->getRemoteRoomShares($user); |
|
|
|
return new DataResponse($invitations); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -174,6 +174,15 @@ class FederationManager { |
|
|
|
$this->notifications->sendShareDeclined($room->getRemoteServer(), $invitation->getRemoteId(), $invitation->getAccessToken()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param IUser $user |
|
|
|
* @return Invitation[] |
|
|
|
* @throws DBException |
|
|
|
*/ |
|
|
|
public function getRemoteRoomShares(IUser $user): array { |
|
|
|
return $this->invitationMapper->getInvitationsForUser($user); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @throws DBException |
|
|
|
*/ |
|
|
|
|
|
|
|
@ -32,6 +32,7 @@ use OCP\AppFramework\Db\QBMapper; |
|
|
|
use OCP\DB\Exception as DBException; |
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder; |
|
|
|
use OCP\IDBConnection; |
|
|
|
use OCP\IUser; |
|
|
|
|
|
|
|
/** |
|
|
|
* Class InvitationMapper |
|
|
|
@ -77,6 +78,21 @@ class InvitationMapper extends QBMapper { |
|
|
|
return $this->findEntities($qb); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param IUser $user |
|
|
|
* @return Invitation[] |
|
|
|
* @throws DBException |
|
|
|
*/ |
|
|
|
public function getInvitationsForUser(IUser $user): array { |
|
|
|
$qb = $this->db->getQueryBuilder(); |
|
|
|
|
|
|
|
$qb->select('*') |
|
|
|
->from($this->getTableName()) |
|
|
|
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID()))); |
|
|
|
|
|
|
|
return $this->findEntities($qb); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @throws DBException |
|
|
|
*/ |
|
|
|
|
|
|
|
@ -72,6 +72,7 @@ class RoomTest extends TestCase { |
|
|
|
'description', |
|
|
|
'passy', |
|
|
|
'', |
|
|
|
'', |
|
|
|
0, |
|
|
|
Attendee::PERMISSIONS_DEFAULT, |
|
|
|
Attendee::PERMISSIONS_DEFAULT, |
|
|
|
|