Skip to content

Commit e6db057

Browse files
committed
fix: Propagate permissions to new federated conversations
Besides propagating the permissions to federated servers when modified the existing permissions need to be set when creating the federated conversation (or if a federated user is added again to the conversation when all the previous federated users left it already). Signed-off-by: Daniel Calviño Sánchez <[email protected]>
1 parent e8c51ce commit e6db057

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

lib/Federation/BackendNotifier.php

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function sendRemoteShare(
6969
$roomName = $room->getName();
7070
$roomType = $room->getType();
7171
$roomToken = $room->getToken();
72+
$roomCallPermissions = $room->getCallPermissions();
73+
$roomDefaultPermissions = $room->getDefaultPermissions();
7274

7375
try {
7476
$this->restrictionValidator->isAllowedToInvite($sharedBy, $invitedCloudId);
@@ -101,6 +103,8 @@ public function sendRemoteShare(
101103
$protocol['invitedCloudId'] = $invitedCloudId->getId();
102104
$protocol['roomName'] = $roomName;
103105
$protocol['roomType'] = $roomType;
106+
$protocol['roomCallPermissions'] = $roomCallPermissions;
107+
$protocol['roomDefaultPermissions'] = $roomDefaultPermissions;
104108
$protocol['name'] = FederationManager::TALK_PROTOCOL_NAME;
105109
$share->setProtocol($protocol);
106110

lib/Federation/CloudFederationProviderTalk.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public function shareReceived(ICloudFederationShare $share): string {
125125
$remoteId = $share->getProviderId();
126126
$roomToken = $share->getResourceName();
127127
$roomName = $share->getProtocol()['roomName'];
128+
$roomCallPermissions = $share->getProtocol()['roomCallPermissions'];
129+
$roomDefaultPermissions = $share->getProtocol()['roomDefaultPermissions'];
128130
if (isset($share->getProtocol()['invitedCloudId'])) {
129131
$localCloudId = $share->getProtocol()['invitedCloudId'];
130132
} else {
@@ -173,7 +175,7 @@ public function shareReceived(ICloudFederationShare $share): string {
173175
throw new ProviderCouldNotAddShareException('User does not exist', '', Http::STATUS_BAD_REQUEST);
174176
}
175177

176-
$invite = $this->federationManager->addRemoteRoom($shareWithUser, (int) $remoteId, $roomType, $roomName, $roomToken, $remote, $shareSecret, $sharedByFederatedId, $sharedByDisplayName, $localCloudId);
178+
$invite = $this->federationManager->addRemoteRoom($shareWithUser, (int) $remoteId, $roomType, $roomName, $roomCallPermissions, $roomDefaultPermissions, $roomToken, $remote, $shareSecret, $sharedByFederatedId, $sharedByDisplayName, $localCloudId);
177179

178180
$this->notifyAboutNewShare($shareWithUser, (string) $invite->getId(), $sharedByFederatedId, $sharedByDisplayName, $roomName, $roomToken, $remote);
179181
return (string) $invite->getId();

lib/Federation/FederationManager.php

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCA\Talk\Participant;
2020
use OCA\Talk\Room;
2121
use OCA\Talk\Service\ParticipantService;
22+
use OCA\Talk\Service\RoomService;
2223
use OCP\AppFramework\Db\DoesNotExistException;
2324
use OCP\AppFramework\Http;
2425
use OCP\Federation\Exceptions\ProviderCouldNotAddShareException;
@@ -50,6 +51,7 @@ class FederationManager {
5051
public function __construct(
5152
private Manager $manager,
5253
private ParticipantService $participantService,
54+
private RoomService $roomService,
5355
private InvitationMapper $invitationMapper,
5456
private BackendNotifier $backendNotifier,
5557
private IManager $notificationManager,
@@ -75,6 +77,8 @@ public function addRemoteRoom(
7577
int $remoteAttendeeId,
7678
int $roomType,
7779
string $roomName,
80+
int $roomCallPermissions,
81+
int $roomDefaultPermissions,
7882
string $remoteToken,
7983
string $remoteServerUrl,
8084
#[SensitiveParameter]
@@ -91,6 +95,14 @@ public function addRemoteRoom(
9195
$room = $this->manager->createRemoteRoom($roomType, $roomName, $remoteToken, $remoteServerUrl);
9296
}
9397

98+
// Only update the room permissions if there are no participants in the
99+
// remote room. Otherwise the room permissions would be up to date
100+
// already due to the notifications about room permission changes.
101+
if (empty($participant = $this->participantService->getParticipantsForRoom($room))) {
102+
$this->roomService->setPermissions($room, 'call', Attendee::PERMISSIONS_MODIFY_SET, $roomCallPermissions, true);
103+
$this->roomService->setPermissions($room, 'default', Attendee::PERMISSIONS_MODIFY_SET, $roomDefaultPermissions, true);
104+
}
105+
94106
if ($couldHaveInviteWithOtherCasing) {
95107
try {
96108
$this->invitationMapper->getInvitationForUserByLocalRoom($room, $user->getUID(), true);

tests/integration/features/federation/permissions.feature

+55
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ Feature: federation/permissions
4040
| permissions |
4141
| CLM |
4242

43+
Scenario: change permissions for all attendees before inviting federated user
44+
Given user "participant1" creates room "room" (v4)
45+
| roomType | 2 |
46+
| roomName | room name |
47+
When user "participant1" sets permissions for all attendees in room "room" to "SM" with 200 (v4)
48+
And user "participant1" removes permissions for all attendees in room "room" to "S" with 200 (v4)
49+
And user "participant1" adds permissions for all attendees in room "room" to "L" with 200 (v4)
50+
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
51+
And user "participant2" has the following invitations (v1)
52+
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
53+
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
54+
And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1)
55+
| id | name | type | remoteServer | remoteToken |
56+
| LOCAL::room | room name | 2 | LOCAL | room |
57+
Then user "participant2" is participant of room "LOCAL::room" (v4)
58+
| permissions |
59+
| CLM |
60+
4361
Scenario: change permissions for all attendees before federated user accepts invitation
4462
Given user "participant1" creates room "room" (v4)
4563
| roomType | 2 |
@@ -74,6 +92,43 @@ Feature: federation/permissions
7492
| permissions |
7593
| CM |
7694

95+
Scenario: set conversation permissions before inviting federated user
96+
Given user "participant1" creates room "room" (v4)
97+
| roomType | 2 |
98+
| roomName | room name |
99+
When user "participant1" sets default permissions for room "room" to "M" with 200 (v4)
100+
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
101+
And user "participant2" has the following invitations (v1)
102+
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
103+
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
104+
And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1)
105+
| id | name | type | remoteServer | remoteToken |
106+
| LOCAL::room | room name | 2 | LOCAL | room |
107+
Then user "participant2" is participant of room "LOCAL::room" (v4)
108+
| permissions |
109+
| CM |
110+
111+
Scenario: set conversation permissions before inviting federated user again
112+
Given user "participant1" creates room "room" (v4)
113+
| roomType | 2 |
114+
| roomName | room name |
115+
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
116+
And user "participant2" has the following invitations (v1)
117+
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
118+
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
119+
And user "participant2" declines invite to room "room" of server "LOCAL" with 200 (v1)
120+
When user "participant1" sets default permissions for room "room" to "M" with 200 (v4)
121+
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
122+
And user "participant2" has the following invitations (v1)
123+
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
124+
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
125+
And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1)
126+
| id | name | type | remoteServer | remoteToken |
127+
| LOCAL::room | room name | 2 | LOCAL | room |
128+
Then user "participant2" is participant of room "LOCAL::room" (v4)
129+
| permissions |
130+
| CM |
131+
77132
Scenario: set conversation permissions before federated user accepts invitation
78133
Given user "participant1" creates room "room" (v4)
79134
| roomType | 2 |

0 commit comments

Comments
 (0)