Skip to content

Commit 2354752

Browse files
committed
Split start conversation capability
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 2c0b64a commit 2354752

File tree

9 files changed

+98
-4
lines changed

9 files changed

+98
-4
lines changed

docs/capabilities.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,5 @@ title: Capabilities
112112
* `recording-v1` - Call recording is available.
113113
* `config => call => breakout-rooms` - Whether breakout rooms are enabled on this instance
114114
* `config => call => recording` - Whether calls can be recorded (requires the High-performance backend server)
115+
* `config => conversations => can-create-group` - Whether the user can create group conversations, if not only one-to-one conversations are allowed
116+
* `config => conversations => can-create-public` - Whether the user can create public conversations, if not only one-to-one conversations are allowed

docs/settings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Option legend:
6161
| `allowed_groups` | string[] | `[]` | 🖌️ | List of group ids that are allowed to use Talk |
6262
| `sip_bridge_groups` | string[] | `[]` | 🖌️ | List of group ids that are allowed to enable SIP dial-in in a conversation |
6363
| `start_conversations` | string[] | `[]` | 🖌️ | List of group ids that are allowed to create conversations |
64+
| `start_group_conversation` | string[] | `[]` | 🖌️ | List of group ids that are allowed to create group conversations |
65+
| `start_public_conversation` | string[] | `[]` | 🖌️ | List of group ids that are allowed to create public conversations |
6466
| `hosted-signaling-server-account` | array | `{}` | 🖌️ | Account information of the hosted signaling server |
6567
| `stun_servers` | array[] | `[]` | 🖌💻️ | List of STUN servers, should be configured via the web interface or the OCC commands |
6668
| `turn_servers` | array[] | `[]` | 🖌️💻 | List of TURN servers, should be configured via the web interface or the OCC commands |

lib/Capabilities.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ public function getCapabilities(): array {
130130
'read-privacy' => Participant::PRIVACY_PUBLIC,
131131
],
132132
'conversations' => [
133-
'can-create' => $user instanceof IUser && !$this->talkConfig->isNotAllowedToCreateConversations($user)
133+
'can-create' => $user instanceof IUser && !$this->talkConfig->isNotAllowedToCreateConversations($user),
134+
'can-create-group' => $user instanceof IUser
135+
&& !$this->talkConfig->isNotAllowedToCreateGroupConversations($user),
136+
'can-create-public' => $user instanceof IUser
137+
&& !$this->talkConfig->isNotAllowedToCreatePublicConversations($user),
134138
],
135139
'previews' => [
136140
'max-gif-size' => (int)$this->serverConfig->getAppValue('spreed', 'max-gif-size', '3145728'),

lib/Config.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,24 @@ public function getAllowedConversationsGroupIds(): array {
180180
return \is_array($groups) ? $groups : [];
181181
}
182182

183+
/**
184+
* @return string[]
185+
*/
186+
public function getAllowedGroupConversationsGroupIds(): array {
187+
$groups = $this->config->getAppValue('spreed', 'start_group_conversations', '[]');
188+
$groups = json_decode($groups, true);
189+
return \is_array($groups) ? $groups : [];
190+
}
191+
192+
/**
193+
* @return string[]
194+
*/
195+
public function getAllowedPublicConversationsGroupIds(): array {
196+
$groups = $this->config->getAppValue('spreed', 'start_public_conversations', '[]');
197+
$groups = json_decode($groups, true);
198+
return \is_array($groups) ? $groups : [];
199+
}
200+
183201
public function isNotAllowedToCreateConversations(IUser $user): bool {
184202
$allowedGroups = $this->getAllowedConversationsGroupIds();
185203
if (empty($allowedGroups)) {
@@ -190,6 +208,26 @@ public function isNotAllowedToCreateConversations(IUser $user): bool {
190208
return empty(array_intersect($allowedGroups, $userGroups));
191209
}
192210

211+
public function isNotAllowedToCreateGroupConversations(IUser $user): bool {
212+
$allowedGroups = $this->getAllowedGroupConversationsGroupIds();
213+
if (empty($allowedGroups)) {
214+
return false;
215+
}
216+
217+
$userGroups = $this->groupManager->getUserGroupIds($user);
218+
return empty(array_intersect($allowedGroups, $userGroups));
219+
}
220+
221+
public function isNotAllowedToCreatePublicConversations(IUser $user): bool {
222+
$allowedGroups = $this->getAllowedGroupConversationsGroupIds();
223+
if (empty($allowedGroups)) {
224+
return false;
225+
}
226+
227+
$userGroups = $this->groupManager->getUserGroupIds($user);
228+
return empty(array_intersect($allowedGroups, $userGroups));
229+
}
230+
193231
public function getDefaultPermissions(): int {
194232
// Admin configured default permissions
195233
$configurableDefault = $this->config->getAppValue('spreed', 'default_permissions');

lib/Controller/RoomController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ protected function getTalkHashHeader(): array {
169169
$this->config->getAppValue('spreed', 'allowed_groups', '') . '#' .
170170
$this->config->getAppValue('spreed', 'start_calls', '') . '#' .
171171
$this->config->getAppValue('spreed', 'start_conversations', '') . '#' .
172+
$this->config->getAppValue('spreed', 'start_group_conversations', '') . '#' .
173+
$this->config->getAppValue('spreed', 'start_public_conversations', '') . '#' .
172174
$this->config->getAppValue('spreed', 'has_reference_id', '') . '#' .
173175
$this->config->getAppValue('spreed', 'sip_bridge_groups', '[]') . '#' .
174176
$this->config->getAppValue('spreed', 'sip_bridge_dialin_info') . '#' .

lib/Listener/GroupDeletedListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public function handle(Event $event): void {
5858

5959
$this->removeGroupFromConfig('sip_bridge_groups', $gid);
6060
$this->removeGroupFromConfig('start_conversations', $gid);
61+
$this->removeGroupFromConfig('start_group_conversations', $gid);
62+
$this->removeGroupFromConfig('start_public_conversations', $gid);
6163
$this->removeGroupFromConfig('allowed_groups', $gid);
6264

6365
// Remove the group itself from being a participant

lib/Settings/Admin/AdminSettings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ protected function initAllowedGroups(): void {
109109

110110
$groups = $this->getGroupDetailsArray($this->talkConfig->getAllowedConversationsGroupIds(), 'start_conversations');
111111
$this->initialState->provideInitialState('start_conversations', $groups);
112+
$groups = $this->getGroupDetailsArray($this->talkConfig->getAllowedConversationsGroupIds(), 'start_group_conversations');
113+
$this->initialState->provideInitialState('start_group_conversations', $groups);
114+
$groups = $this->getGroupDetailsArray($this->talkConfig->getAllowedConversationsGroupIds(), 'start_public_conversations');
115+
$this->initialState->provideInitialState('start_public_conversations', $groups);
112116

113117
$groups = $this->getGroupDetailsArray($this->talkConfig->getAllowedTalkGroupIds(), 'allowed_groups');
114118
$this->initialState->provideInitialState('allowed_groups', $groups);

lib/TInitialState.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ protected function publishInitialStateForUser(IUser $user, IRootFolder $rootFold
105105
!$this->talkConfig->isNotAllowedToCreateConversations($user)
106106
);
107107

108+
$this->initialState->provideInitialState(
109+
'start_group_conversations',
110+
!$this->talkConfig->isNotAllowedToCreateGroupConversations($user)
111+
);
112+
113+
$this->initialState->provideInitialState(
114+
'start_public_conversations',
115+
!$this->talkConfig->isNotAllowedToCreatePublicConversations($user)
116+
);
117+
108118
$this->initialState->provideInitialState(
109119
'circles_enabled',
110120
$appManager->isEnabledForUser('circles', $user)
@@ -173,6 +183,16 @@ protected function publishInitialStateForGuest(): void {
173183
false
174184
);
175185

186+
$this->initialState->provideInitialState(
187+
'start_group_conversations',
188+
false
189+
);
190+
191+
$this->initialState->provideInitialState(
192+
'start_public_conversations',
193+
false
194+
);
195+
176196
$this->initialState->provideInitialState(
177197
'circles_enabled',
178198
false

tests/php/CapabilitiesTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ public function testGetCapabilitiesGuest(): void {
178178
],
179179
'conversations' => [
180180
'can-create' => false,
181+
'can-create-group' => false,
182+
'can-create-public' =>false,
181183
],
182184
'previews' => [
183185
'max-gif-size' => 200000,
@@ -193,8 +195,8 @@ public function testGetCapabilitiesGuest(): void {
193195

194196
public function dataGetCapabilitiesUserAllowed(): array {
195197
return [
196-
[true, false, Participant::PRIVACY_PRIVATE],
197-
[false, true, Participant::PRIVACY_PUBLIC],
198+
[true, false, false, false, Participant::PRIVACY_PRIVATE],
199+
[false, true, true, true, Participant::PRIVACY_PUBLIC],
198200
];
199201
}
200202

@@ -204,7 +206,13 @@ public function dataGetCapabilitiesUserAllowed(): array {
204206
* @param bool $canCreate
205207
* @param int $readPrivacy
206208
*/
207-
public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCreate, int $readPrivacy): void {
209+
public function testGetCapabilitiesUserAllowed(
210+
bool $isNotAllowed,
211+
bool $canCreate,
212+
bool $canCreateGroup,
213+
bool $canCreatePublic,
214+
int $readPrivacy
215+
): void {
208216
$capabilities = new Capabilities(
209217
$this->serverConfig,
210218
$this->talkConfig,
@@ -240,6 +248,16 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea
240248
->with($user)
241249
->willReturn($isNotAllowed);
242250

251+
$this->talkConfig->expects($this->once())
252+
->method('isNotAllowedToCreateGroupConversations')
253+
->with($user)
254+
->willReturn($isNotAllowed);
255+
256+
$this->talkConfig->expects($this->once())
257+
->method('isNotAllowedToCreatePublicConversations')
258+
->with($user)
259+
->willReturn($isNotAllowed);
260+
243261
$this->talkConfig->expects($this->once())
244262
->method('getUserReadPrivacy')
245263
->with('uid')
@@ -280,6 +298,8 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea
280298
],
281299
'conversations' => [
282300
'can-create' => $canCreate,
301+
'can-create-group' => $canCreateGroup,
302+
'can-create-public' => $canCreatePublic,
283303
],
284304
'previews' => [
285305
'max-gif-size' => 200000,

0 commit comments

Comments
 (0)