Skip to content

Commit

Permalink
Add ability to invite groups
Browse files Browse the repository at this point in the history
  • Loading branch information
mario committed Oct 25, 2018
1 parent de4050e commit a08bdb7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
5 changes: 3 additions & 2 deletions docs/api-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
### 5.0
* `invite-by-mail` - Guests can be invited with their email address
* `notification-levels` - Users can select when they want to be notified in conversations
* `invite-group` - Groups can now be added to conversations via the add participant API

## Room management

Expand Down Expand Up @@ -312,14 +313,14 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`

field | type | Description
------|------|------------
`newParticipant` | string | User to add
`newParticipant` | string | User or group to add

* Response:
- Header:
+ `200 OK`
+ `403 Forbidden` When the current user is not a moderator/owner
+ `404 Not Found` When the room could not be found for the participant
+ `404 Not Found` When the user to add could not be found
+ `404 Not Found` When the user or group to add could not be found

- Data:

Expand Down
2 changes: 1 addition & 1 deletion js/views/participantview.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
search: term,
itemType: 'call',
itemId: this.room.get('token'),
shareTypes: [OC.Share.SHARE_TYPE_USER, OC.Share.SHARE_TYPE_EMAIL]
shareTypes: [OC.Share.SHARE_TYPE_USER, OC.Share.SHARE_TYPE_GROUP, OC.Share.SHARE_TYPE_EMAIL]
};
}.bind(this),
results: function (response) {
Expand Down
1 change: 1 addition & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function getCapabilities(): array {
'in-call-flags',
'invite-by-mail',
'notification-levels',
'invite-group'
],
],
];
Expand Down
32 changes: 26 additions & 6 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,14 +746,14 @@ public function getParticipants(string $token): DataResponse {
public function addParticipantToRoom(string $token, string $newParticipant): DataResponse {
try {
$room = $this->manager->getRoomForParticipantByToken($token, $this->userId);
$participant = $room->getParticipant($this->userId);
$currentUser = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

if (!$participant->hasModeratorPermissions(false)) {
if (!$currentUser->hasModeratorPermissions(false)) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}

Expand All @@ -769,7 +769,11 @@ public function addParticipantToRoom(string $token, string $newParticipant): Dat

$newUser = $this->userManager->get($newParticipant);
if (!$newUser instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
$newUser = $this->groupManager->get($newParticipant);
if (!$newUser instanceof IGroup) {
return new DataResponse([], Http::STATUS_NOT_FOUND);

}
}

$data = [];
Expand All @@ -780,9 +784,25 @@ public function addParticipantToRoom(string $token, string $newParticipant): Dat
$data = ['type' => $room->getType()];
}

$room->addUsers([
'userId' => $newUser->getUID(),
]);
if ($newUser instanceof IGroup) {
$usersInGroup = $newUser->getUsers();
$participantsToAdd = [];
foreach ($usersInGroup as $user) {
if (isset($participants['users'][$user->getUID()])) {
continue;
}

$participantsToAdd[] = [
'userId' => $user->getUID(),
];
}

\call_user_func_array([$room, 'addUsers'], $participantsToAdd);
} else {
$room->addUsers([
'userId' => $newUser->getUID(),
]);
}

return new DataResponse($data);
}
Expand Down
1 change: 1 addition & 0 deletions tests/php/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function testGetCapabilities() {
'in-call-flags',
'invite-by-mail',
'notification-levels',
'invite-group'
],
],
], $capabilities->getCapabilities());
Expand Down

0 comments on commit a08bdb7

Please sign in to comment.