Skip to content

Commit 4fa4be2

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). [skip-ci] Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
1 parent ee0f6cb commit 4fa4be2

5 files changed

Lines changed: 54 additions & 2 deletions

File tree

lib/Federation/BackendNotifier.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function sendRemoteShare(
6969
$roomName = $room->getName();
7070
$roomType = $room->getType();
7171
$roomToken = $room->getToken();
72+
$roomDefaultPermissions = $room->getDefaultPermissions();
7273

7374
try {
7475
$this->restrictionValidator->isAllowedToInvite($sharedBy, $invitedCloudId);
@@ -101,6 +102,7 @@ public function sendRemoteShare(
101102
$protocol['invitedCloudId'] = $invitedCloudId->getId();
102103
$protocol['roomName'] = $roomName;
103104
$protocol['roomType'] = $roomType;
105+
$protocol['roomDefaultPermissions'] = $roomDefaultPermissions;
104106
$protocol['name'] = FederationManager::TALK_PROTOCOL_NAME;
105107
$share->setProtocol($protocol);
106108

lib/Federation/CloudFederationProviderTalk.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public function shareReceived(ICloudFederationShare $share): string {
125125
$remoteId = $share->getProviderId();
126126
$roomToken = $share->getResourceName();
127127
$roomName = $share->getProtocol()['roomName'];
128+
$roomDefaultPermissions = $share->getProtocol()['roomDefaultPermissions'] ?? Attendee::PERMISSIONS_DEFAULT;
128129
if (isset($share->getProtocol()['invitedCloudId'])) {
129130
$localCloudId = $share->getProtocol()['invitedCloudId'];
130131
} else {
@@ -173,7 +174,7 @@ public function shareReceived(ICloudFederationShare $share): string {
173174
throw new ProviderCouldNotAddShareException('User does not exist', '', Http::STATUS_BAD_REQUEST);
174175
}
175176

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

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

lib/Federation/FederationManager.php

Lines changed: 10 additions & 0 deletions
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,7 @@ public function addRemoteRoom(
7577
int $remoteAttendeeId,
7678
int $roomType,
7779
string $roomName,
80+
int $roomDefaultPermissions,
7881
string $remoteToken,
7982
string $remoteServerUrl,
8083
#[SensitiveParameter]
@@ -91,6 +94,13 @@ public function addRemoteRoom(
9194
$room = $this->manager->createRemoteRoom($roomType, $roomName, $remoteToken, $remoteServerUrl);
9295
}
9396

97+
// Only update the room permissions if there are no participants in the
98+
// remote room. Otherwise, the room permissions would be up to date
99+
// already due to the notifications about room permission changes.
100+
if (!$this->participantService->getNumberOfActors($room)) {
101+
$this->roomService->setDefaultPermissions($room, $roomDefaultPermissions);
102+
}
103+
94104
if ($couldHaveInviteWithOtherCasing) {
95105
try {
96106
$this->invitationMapper->getInvitationForUserByLocalRoom($room, $user->getUID(), true);

tests/integration/features/federation/permissions.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,43 @@ Feature: federation/permissions
6565
| defaultPermissions | attendeePermissions | permissions |
6666
| CLM | D | CLM |
6767

68+
Scenario: set default permissions before inviting federated user
69+
Given user "participant1" creates room "room" (v4)
70+
| roomType | 2 |
71+
| roomName | room name |
72+
When user "participant1" sets default permissions for room "room" to "M" with 200 (v4)
73+
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
74+
And user "participant2" has the following invitations (v1)
75+
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
76+
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
77+
And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1)
78+
| id | name | type | remoteServer | remoteToken |
79+
| LOCAL::room | room name | 2 | LOCAL | room |
80+
Then user "participant2" is participant of room "LOCAL::room" (v4)
81+
| defaultPermissions | attendeePermissions | permissions |
82+
| CM | D | CM |
83+
84+
Scenario: set default permissions before inviting federated user again
85+
Given user "participant1" creates room "room" (v4)
86+
| roomType | 2 |
87+
| roomName | room name |
88+
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
89+
And user "participant2" has the following invitations (v1)
90+
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
91+
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
92+
And user "participant2" declines invite to room "room" of server "LOCAL" with 200 (v1)
93+
When user "participant1" sets default permissions for room "room" to "M" with 200 (v4)
94+
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
95+
And user "participant2" has the following invitations (v1)
96+
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
97+
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
98+
And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1)
99+
| id | name | type | remoteServer | remoteToken |
100+
| LOCAL::room | room name | 2 | LOCAL | room |
101+
Then user "participant2" is participant of room "LOCAL::room" (v4)
102+
| defaultPermissions | attendeePermissions | permissions |
103+
| CM | D | CM |
104+
68105
Scenario: set participant permissions after setting conversation permissions and then invite another federated user
69106
Given user "participant3" exists
70107
And user "participant1" creates room "room" (v4)

tests/php/Federation/FederationTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ public function testReceiveRemoteShare(): void {
256256
$shareType = 'user';
257257
$roomType = Room::TYPE_GROUP;
258258
$roomName = 'Room name';
259+
$roomDefaultPermissions = Attendee::PERMISSIONS_CUSTOM | Attendee::PERMISSIONS_CHAT;
259260

260261
$shareWithUser = $this->createMock(IUser::class);
261262
$shareWithUserID = '10';
@@ -277,6 +278,7 @@ public function testReceiveRemoteShare(): void {
277278
'name' => 'nctalk',
278279
'roomType' => $roomType,
279280
'roomName' => $roomName,
281+
'roomDefaultPermissions' => $roomDefaultPermissions,
280282
'options' => [
281283
'sharedSecret' => $token,
282284
],
@@ -288,7 +290,7 @@ public function testReceiveRemoteShare(): void {
288290
// Test receiving federation expectations
289291
$this->federationManager->expects($this->once())
290292
->method('addRemoteRoom')
291-
->with($shareWithUser, $providerId, $roomType, $roomName, $name, $remote, $token)
293+
->with($shareWithUser, $providerId, $roomType, $roomName, $roomDefaultPermissions, $name, $remote, $token)
292294
->willReturn($invite);
293295

294296
$this->config->method('isFederationEnabled')

0 commit comments

Comments
 (0)