Browse Source

Add ability to invite groups

Fix a missing ,

Move to tabs
pull/1268/head
Mario Danic 7 years ago
committed by Joas Schilling
parent
commit
9c74620453
No known key found for this signature in database GPG Key ID: 7076EA9751AACDDA
  1. 6
      docs/api-v1.md
  2. 2
      js/views/participantview.js
  3. 1
      lib/Capabilities.php
  4. 51
      lib/Controller/RoomController.php
  5. 1
      tests/php/CapabilitiesTest.php

6
docs/api-v1.md

@ -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
@ -312,14 +313,15 @@ 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
`isGroup` | bool | Define if you're adding a group (default is false)
* 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:

2
js/views/participantview.js

@ -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) {

1
lib/Capabilities.php

@ -47,6 +47,7 @@ class Capabilities implements IPublicCapability {
'in-call-flags',
'invite-by-mail',
'notification-levels',
'invite-group',
],
],
];

51
lib/Controller/RoomController.php

@ -743,22 +743,22 @@ class RoomController extends OCSController {
* @param string $newParticipant
* @return DataResponse
*/
public function addParticipantToRoom(string $token, string $newParticipant): DataResponse {
public function addParticipantToRoom(string $token, string $newParticipant, bool $isGroup = false): 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);
}
$participants = $room->getParticipants();
if (isset($participants['users'][$newParticipant])) {
if (!$isGroup && isset($participants['users'][$newParticipant])) {
return new DataResponse([]);
}
@ -767,23 +767,46 @@ class RoomController extends OCSController {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$newUser = $this->userManager->get($newParticipant);
if (!$newUser instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
$participantsToAdd = [];
if (!$isGroup) {
$newUser = $this->userManager->get($newParticipant);
if (!$newUser instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$room->addUsers([
'userId' => $newUser->getUID(),
]);
} else {
$newUser = $this->groupManager->get($newParticipant);
if (!$newUser instanceof IGroup) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$usersInGroup = $newUser->getUsers();
foreach ($usersInGroup as $user) {
if (isset($participants['users'][$user->getUID()])) {
continue;
}
$participantsToAdd[] = [
'userId' => $user->getUID(),
];
}
\call_user_func_array([$room, 'addUsers'], $participantsToAdd);
}
$data = [];
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
// In case a user is added to a one2one call, we change the call to a group call
$room->changeType(Room::GROUP_CALL);
$data = ['type' => $room->getType()];
if (!$isGroup || count($participantsToAdd) > 0) {
$room->changeType(Room::GROUP_CALL);
$data = ['type' => $room->getType()];
}
}
$room->addUsers([
'userId' => $newUser->getUID(),
]);
return new DataResponse($data);
}

1
tests/php/CapabilitiesTest.php

@ -51,6 +51,7 @@ class CapabilitiesTest extends TestCase {
'in-call-flags',
'invite-by-mail',
'notification-levels',
'invite-group',
],
],
], $capabilities->getCapabilities());

Loading…
Cancel
Save