Skip to content

Commit d95deef

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

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 @@
112112
* `config => call => recording` - Whether calls can be recorded (requires the High-performance backend server)
113113
* `single-conversation-status` - When the response of a single conversation can also return the user status
114114
* `chat-keep-notifications` - Whether messages can be retrieved without marking notifications as read
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
@@ -133,7 +133,11 @@ public function getCapabilities(): array {
133133
//'legacy' => true, // Temporary A-B switch to opt-out of the new context loading
134134
],
135135
'conversations' => [
136-
'can-create' => $user instanceof IUser && !$this->talkConfig->isNotAllowedToCreateConversations($user)
136+
'can-create' => $user instanceof IUser && !$this->talkConfig->isNotAllowedToCreateConversations($user),
137+
'can-create-group' => $user instanceof IUser
138+
&& !$this->talkConfig->isNotAllowedToCreateGroupConversations($user),
139+
'can-create-public' => $user instanceof IUser
140+
&& !$this->talkConfig->isNotAllowedToCreatePublicConversations($user),
137141
],
138142
'previews' => [
139143
'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
@@ -208,6 +208,24 @@ public function getAllowedConversationsGroupIds(): array {
208208
return \is_array($groups) ? $groups : [];
209209
}
210210

211+
/**
212+
* @return string[]
213+
*/
214+
public function getAllowedGroupConversationsGroupIds(): array {
215+
$groups = $this->config->getAppValue('spreed', 'start_group_conversations', '[]');
216+
$groups = json_decode($groups, true);
217+
return \is_array($groups) ? $groups : [];
218+
}
219+
220+
/**
221+
* @return string[]
222+
*/
223+
public function getAllowedPublicConversationsGroupIds(): array {
224+
$groups = $this->config->getAppValue('spreed', 'start_public_conversations', '[]');
225+
$groups = json_decode($groups, true);
226+
return \is_array($groups) ? $groups : [];
227+
}
228+
211229
public function isNotAllowedToCreateConversations(IUser $user): bool {
212230
$allowedGroups = $this->getAllowedConversationsGroupIds();
213231
if (empty($allowedGroups)) {
@@ -218,6 +236,26 @@ public function isNotAllowedToCreateConversations(IUser $user): bool {
218236
return empty(array_intersect($allowedGroups, $userGroups));
219237
}
220238

239+
public function isNotAllowedToCreateGroupConversations(IUser $user): bool {
240+
$allowedGroups = $this->getAllowedGroupConversationsGroupIds();
241+
if (empty($allowedGroups)) {
242+
return false;
243+
}
244+
245+
$userGroups = $this->groupManager->getUserGroupIds($user);
246+
return empty(array_intersect($allowedGroups, $userGroups));
247+
}
248+
249+
public function isNotAllowedToCreatePublicConversations(IUser $user): bool {
250+
$allowedGroups = $this->getAllowedGroupConversationsGroupIds();
251+
if (empty($allowedGroups)) {
252+
return false;
253+
}
254+
255+
$userGroups = $this->groupManager->getUserGroupIds($user);
256+
return empty(array_intersect($allowedGroups, $userGroups));
257+
}
258+
221259
public function getDefaultPermissions(): int {
222260
// Admin configured default permissions
223261
$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
@@ -156,6 +156,8 @@ protected function getTalkHashHeader(): array {
156156
$this->config->getAppValue('spreed', 'allowed_groups', '') . '#' .
157157
$this->config->getAppValue('spreed', 'start_calls', '') . '#' .
158158
$this->config->getAppValue('spreed', 'start_conversations', '') . '#' .
159+
$this->config->getAppValue('spreed', 'start_group_conversations', '') . '#' .
160+
$this->config->getAppValue('spreed', 'start_public_conversations', '') . '#' .
159161
$this->config->getAppValue('spreed', 'has_reference_id', '') . '#' .
160162
$this->config->getAppValue('spreed', 'sip_bridge_groups', '[]') . '#' .
161163
$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
@@ -110,6 +110,10 @@ protected function initAllowedGroups(): void {
110110

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

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

lib/TInitialState.php

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

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

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

tests/php/CapabilitiesTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ public function testGetCapabilitiesGuest(): void {
180180
],
181181
'conversations' => [
182182
'can-create' => false,
183+
'can-create-group' => false,
184+
'can-create-public' => false,
183185
],
184186
'previews' => [
185187
'max-gif-size' => 200000,
@@ -195,8 +197,8 @@ public function testGetCapabilitiesGuest(): void {
195197

196198
public function dataGetCapabilitiesUserAllowed(): array {
197199
return [
198-
[true, false, Participant::PRIVACY_PRIVATE],
199-
[false, true, Participant::PRIVACY_PUBLIC],
200+
[true, false, false, false, Participant::PRIVACY_PRIVATE],
201+
[false, true, true, true, Participant::PRIVACY_PUBLIC],
200202
];
201203
}
202204

@@ -206,7 +208,13 @@ public function dataGetCapabilitiesUserAllowed(): array {
206208
* @param bool $canCreate
207209
* @param int $readPrivacy
208210
*/
209-
public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCreate, int $readPrivacy): void {
211+
public function testGetCapabilitiesUserAllowed(
212+
bool $isNotAllowed,
213+
bool $canCreate,
214+
bool $canCreateGroup,
215+
bool $canCreatePublic,
216+
int $readPrivacy
217+
): void {
210218
$capabilities = new Capabilities(
211219
$this->serverConfig,
212220
$this->talkConfig,
@@ -242,6 +250,16 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea
242250
->with($user)
243251
->willReturn($isNotAllowed);
244252

253+
$this->talkConfig->expects($this->once())
254+
->method('isNotAllowedToCreateGroupConversations')
255+
->with($user)
256+
->willReturn($isNotAllowed);
257+
258+
$this->talkConfig->expects($this->once())
259+
->method('isNotAllowedToCreatePublicConversations')
260+
->with($user)
261+
->willReturn($isNotAllowed);
262+
245263
$this->talkConfig->expects($this->once())
246264
->method('getUserReadPrivacy')
247265
->with('uid')
@@ -282,6 +300,8 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea
282300
],
283301
'conversations' => [
284302
'can-create' => $canCreate,
303+
'can-create-group' => $canCreateGroup,
304+
'can-create-public' => $canCreatePublic,
285305
],
286306
'previews' => [
287307
'max-gif-size' => 200000,

0 commit comments

Comments
 (0)