Skip to content

Commit 373af2f

Browse files
committed
fix(permissions): Use react-permission capability per migration guide
- Add REACT_PERMISSION feature to SpreedFeatures enum - Update hasReactPermission() to check react-permission capability first - Fall back to chat-permission/CHAT bit for older servers - Expand unit tests for all capability scenarios
1 parent 6f3fa1e commit 373af2f

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

app/src/main/java/com/nextcloud/talk/utils/CapabilitiesUtil.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ enum class SpreedFeatures(val value: String) {
6262
SENSITIVE_CONVERSATIONS("sensitive-conversations"),
6363
IMPORTANT_CONVERSATIONS("important-conversations"),
6464
THREADS("threads"),
65-
PINNED_MESSAGES("pinned-messages")
65+
PINNED_MESSAGES("pinned-messages"),
66+
REACT_PERMISSION("react-permission")
6667
}
6768

6869
@Suppress("TooManyFunctions")

app/src/main/java/com/nextcloud/talk/utils/ParticipantPermissions.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ class ParticipantPermissions(
7272
}
7373

7474
fun hasReactPermission(): Boolean {
75+
if (CapabilitiesUtil.hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.REACT_PERMISSION)) {
76+
// Server supports separate react permission - check REACT bit
77+
return hasReactPermission
78+
}
7579
if (CapabilitiesUtil.hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.CHAT_PERMISSION)) {
76-
// Server supports granular permissions - check REACT bit
77-
// Fall back to CHAT permission for backward compatibility with servers
78-
// that have chat-permission capability but not yet the REACT permission split
79-
return hasReactPermission || hasChatPermission
80+
// Older server without react-permission capability - fall back to CHAT permission
81+
// as that's what controlled reactions before the split
82+
return hasChatPermission
8083
}
8184
// if capability is not available then the spreed version doesn't support to restrict this
8285
return true

app/src/test/java/com/nextcloud/talk/utils/ParticipantPermissionsTest.kt

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ class ParticipantPermissionsTest : TestCase() {
4848
}
4949

5050
@Test
51-
fun test_reactPermissionSet() {
51+
fun test_reactPermissionWithReactCapability() {
5252
val spreedCapability = SpreedCapability()
53-
spreedCapability.features = listOf("chat-permission")
53+
spreedCapability.features = listOf("react-permission")
5454
val conversation = createConversation()
5555

56+
// With react-permission capability, only REACT bit matters
5657
conversation.permissions = ParticipantPermissions.REACT or
5758
ParticipantPermissions.CUSTOM
5859

@@ -70,12 +71,36 @@ class ParticipantPermissionsTest : TestCase() {
7071
}
7172

7273
@Test
73-
fun test_reactPermissionFallbackToChat() {
74+
fun test_reactPermissionDeniedWithReactCapability() {
75+
val spreedCapability = SpreedCapability()
76+
spreedCapability.features = listOf("react-permission")
77+
val conversation = createConversation()
78+
79+
// With react-permission capability, only CHAT but no REACT - should NOT allow reactions
80+
conversation.permissions = ParticipantPermissions.CHAT or
81+
ParticipantPermissions.CUSTOM
82+
83+
val user = User()
84+
user.id = 1
85+
86+
val attendeePermissions =
87+
ParticipantPermissions(
88+
spreedCapability,
89+
ConversationModel.mapToConversationModel(conversation, user)
90+
)
91+
92+
assertFalse(attendeePermissions.hasReactPermission())
93+
assertTrue(attendeePermissions.hasChatPermission())
94+
}
95+
96+
@Test
97+
fun test_reactPermissionFallbackToChatOnOlderServer() {
7498
val spreedCapability = SpreedCapability()
99+
// Older server without react-permission capability but with chat-permission
75100
spreedCapability.features = listOf("chat-permission")
76101
val conversation = createConversation()
77102

78-
// Only CHAT permission set, no REACT - should still allow reactions for backward compatibility
103+
// Only CHAT permission set - should allow reactions as fallback for older servers
79104
conversation.permissions = ParticipantPermissions.CHAT or
80105
ParticipantPermissions.CUSTOM
81106

@@ -92,6 +117,29 @@ class ParticipantPermissionsTest : TestCase() {
92117
assertTrue(attendeePermissions.hasChatPermission())
93118
}
94119

120+
@Test
121+
fun test_reactPermissionDeniedOnOlderServerWithoutChatPermission() {
122+
val spreedCapability = SpreedCapability()
123+
// Older server without react-permission capability but with chat-permission
124+
spreedCapability.features = listOf("chat-permission")
125+
val conversation = createConversation()
126+
127+
// No CHAT permission - should deny reactions on older servers
128+
conversation.permissions = ParticipantPermissions.CUSTOM
129+
130+
val user = User()
131+
user.id = 1
132+
133+
val attendeePermissions =
134+
ParticipantPermissions(
135+
spreedCapability,
136+
ConversationModel.mapToConversationModel(conversation, user)
137+
)
138+
139+
assertFalse(attendeePermissions.hasReactPermission())
140+
assertFalse(attendeePermissions.hasChatPermission())
141+
}
142+
95143
private fun createConversation() =
96144
Conversation(
97145
token = "test",

0 commit comments

Comments
 (0)