Skip to content

Commit 3a608dc

Browse files
Merge pull request #12283 from skalidindi53/skalidindi53/11282/fix-DND-Status
fix: throw error when target has DND on
2 parents b3787e4 + 2a38ba1 commit 3a608dc

File tree

8 files changed

+70
-16
lines changed

8 files changed

+70
-16
lines changed

lib/Controller/CallController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function joinCall(?int $flags = null, ?int $forcePermissions = null, bool
162162
* Ring an attendee
163163
*
164164
* @param int $attendeeId ID of the attendee to ring
165-
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array<empty>, array{}>
165+
* @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_FOUND, array<empty>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: string}, array{}>
166166
*
167167
* 200: Attendee rang successfully
168168
* 400: Ringing attendee is not possible
@@ -183,8 +183,8 @@ public function ringAttendee(int $attendeeId): DataResponse {
183183

184184
try {
185185
$this->participantService->sendCallNotificationForAttendee($this->room, $this->participant, $attendeeId);
186-
} catch (\InvalidArgumentException) {
187-
return new DataResponse([], Http::STATUS_BAD_REQUEST);
186+
} catch (\InvalidArgumentException $e) {
187+
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
188188
} catch (DoesNotExistException) {
189189
return new DataResponse([], Http::STATUS_NOT_FOUND);
190190
}

lib/Service/ParticipantService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
use OCP\IUserManager;
7272
use OCP\Security\ISecureRandom;
7373
use OCP\Server;
74+
use OCP\UserStatus\IManager as IUserStatusManager;
75+
use OCP\UserStatus\IUserStatus;
7476

7577
class ParticipantService {
7678

@@ -95,6 +97,7 @@ public function __construct(
9597
private BackendNotifier $backendNotifier,
9698
private ITimeFactory $timeFactory,
9799
private ICacheFactory $cacheFactory,
100+
private IUserStatusManager $userStatusManager,
98101
) {
99102
}
100103

@@ -1181,6 +1184,11 @@ public function sendCallNotificationForAttendee(Room $room, Participant $current
11811184
throw new DoesNotExistException('Room mismatch');
11821185
}
11831186

1187+
$userStatus = $this->userStatusManager->getUserStatuses([$attendee->getActorId()]);
1188+
if (isset($userStatus[$attendee->getActorId()]) && $userStatus[$attendee->getActorId()]->getStatus() === IUserStatus::DND) {
1189+
throw new \InvalidArgumentException('status');
1190+
}
1191+
11841192
$sessions = $this->sessionMapper->findByAttendeeId($targetAttendeeId);
11851193
foreach ($sessions as $session) {
11861194
if ($session->getInCall() !== Participant::FLAG_DISCONNECTED) {

openapi-full.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,8 +4432,8 @@
44324432
}
44334433
}
44344434
},
4435-
"400": {
4436-
"description": "Ringing attendee is not possible",
4435+
"404": {
4436+
"description": "Attendee could not be found",
44374437
"content": {
44384438
"application/json": {
44394439
"schema": {
@@ -4460,8 +4460,8 @@
44604460
}
44614461
}
44624462
},
4463-
"404": {
4464-
"description": "Attendee could not be found",
4463+
"400": {
4464+
"description": "Ringing attendee is not possible",
44654465
"content": {
44664466
"application/json": {
44674467
"schema": {
@@ -4480,7 +4480,17 @@
44804480
"meta": {
44814481
"$ref": "#/components/schemas/OCSMeta"
44824482
},
4483-
"data": {}
4483+
"data": {
4484+
"type": "object",
4485+
"required": [
4486+
"error"
4487+
],
4488+
"properties": {
4489+
"error": {
4490+
"type": "string"
4491+
}
4492+
}
4493+
}
44844494
}
44854495
}
44864496
}

openapi.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4319,8 +4319,8 @@
43194319
}
43204320
}
43214321
},
4322-
"400": {
4323-
"description": "Ringing attendee is not possible",
4322+
"404": {
4323+
"description": "Attendee could not be found",
43244324
"content": {
43254325
"application/json": {
43264326
"schema": {
@@ -4347,8 +4347,8 @@
43474347
}
43484348
}
43494349
},
4350-
"404": {
4351-
"description": "Attendee could not be found",
4350+
"400": {
4351+
"description": "Ringing attendee is not possible",
43524352
"content": {
43534353
"application/json": {
43544354
"schema": {
@@ -4367,7 +4367,17 @@
43674367
"meta": {
43684368
"$ref": "#/components/schemas/OCSMeta"
43694369
},
4370-
"data": {}
4370+
"data": {
4371+
"type": "object",
4372+
"required": [
4373+
"error"
4374+
],
4375+
"properties": {
4376+
"error": {
4377+
"type": "string"
4378+
}
4379+
}
4380+
}
43714381
}
43724382
}
43734383
}

src/types/openapi/openapi-full.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,9 @@ export type operations = {
19401940
"application/json": {
19411941
ocs: {
19421942
meta: components["schemas"]["OCSMeta"];
1943-
data: unknown;
1943+
data: {
1944+
error: string;
1945+
};
19441946
};
19451947
};
19461948
};

src/types/openapi/openapi.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,9 @@ export type operations = {
17631763
"application/json": {
17641764
ocs: {
17651765
meta: components["schemas"]["OCSMeta"];
1766-
data: unknown;
1766+
data: {
1767+
error: string;
1768+
};
17671769
};
17681770
};
17691771
};

tests/integration/features/callapi/notifications.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ Feature: callapi/notifications
7676
Then user "participant2" has the following notifications
7777
| app | object_type | object_id | subject |
7878
| spreed | call | room | A group call has started in room |
79+
80+
Scenario: Calling an attendee that is in DND throws an error 'status' message with 400
81+
When user "participant1" creates room "room" (v4)
82+
| roomType | 2 |
83+
| roomName | room |
84+
And user "participant1" adds user "participant2" to room "room" with 200 (v4)
85+
Given user "participant1" joins room "room" with 200 (v4)
86+
Given user "participant2" joins room "room" with 200 (v4)
87+
Given user "participant1" loads attendees attendee ids in room "room" (v4)
88+
And user "participant2" sets status to "dnd" with 200 (v4)
89+
Given user "participant1" joins call "room" with 200 (v4)
90+
| silent | true |
91+
Then user "participant2" has the following notifications
92+
| app | object_type | object_id | subject |
93+
Given user "participant1" pings user "participant2" to join call "room" with 400 (v4)
94+
Then the request is rejected with the following error message
95+
| status | message |
96+
| 400 | status |
7997

8098
Scenario: Lobby: No call notification sent for users that are blocked by the lobby
8199
Given user "participant1" creates room "room" (v4)

tests/php/Service/ParticipantServiceTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCP\IGroupManager;
3030
use OCP\IUserManager;
3131
use OCP\Security\ISecureRandom;
32+
use OCP\UserStatus\IManager;
3233
use PHPUnit\Framework\MockObject\MockObject;
3334
use Test\TestCase;
3435

@@ -50,6 +51,7 @@ class ParticipantServiceTest extends TestCase {
5051
protected BackendNotifier&MockObject $federationBackendNotifier;
5152
protected ITimeFactory&MockObject $time;
5253
protected ICacheFactory&MockObject $cacheFactory;
54+
protected IManager&MockObject $userStatusManager;
5355
private ?ParticipantService $service = null;
5456

5557

@@ -70,6 +72,7 @@ public function setUp(): void {
7072
$this->federationBackendNotifier = $this->createMock(BackendNotifier::class);
7173
$this->time = $this->createMock(ITimeFactory::class);
7274
$this->cacheFactory = $this->createMock(ICacheFactory::class);
75+
$this->userStatusManager = $this->createMock(IManager::class);
7376
$this->service = new ParticipantService(
7477
$this->serverConfig,
7578
$this->talkConfig,
@@ -85,7 +88,8 @@ public function setUp(): void {
8588
$this->membershipService,
8689
$this->federationBackendNotifier,
8790
$this->time,
88-
$this->cacheFactory
91+
$this->cacheFactory,
92+
$this->userStatusManager,
8993
);
9094
}
9195

0 commit comments

Comments
 (0)