From 74ddcf1b12ada08fa45dea69387310ab1b7213e0 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Tue, 25 Jun 2024 11:17:32 -0700 Subject: [PATCH] fix: invalid policy error when adding new metadata. new test for admin only remove --- android/build.gradle | 20 ++++++------ .../wrappers/GroupWrapper.kt | 1 + example/ios/Podfile.lock | 14 ++++---- example/src/tests/groupPermissionsTests.ts | 32 +++++++++++++++++++ ios/Wrappers/GroupWrapper.swift | 2 ++ ios/XMTPReactNative.podspec | 2 +- src/lib/Group.ts | 4 +-- 7 files changed, 55 insertions(+), 20 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index bb23d8911..033f02132 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -98,19 +98,19 @@ repositories { dependencies { implementation project(':expo-modules-core') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}" - implementation "org.xmtp:android:0.13.8" + implementation "org.xmtp:android:0.13.9" implementation 'com.google.code.gson:gson:2.10.1' implementation 'com.facebook.react:react-native:0.71.3' implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1" // xmtp-android local testing setup below (comment org.xmtp:android above) // implementation files('/xmtp-android/library/build/outputs/aar/library-debug.aar') - // implementation 'com.google.crypto.tink:tink-android:1.7.0' - // implementation 'io.grpc:grpc-kotlin-stub:1.3.0' - // implementation 'io.grpc:grpc-okhttp:1.51.1' - // implementation 'io.grpc:grpc-protobuf-lite:1.51.0' - // implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4' - // implementation 'org.web3j:crypto:5.0.0' - // implementation "net.java.dev.jna:jna:5.13.0@aar" - // implementation 'com.google.protobuf:protobuf-kotlin-lite:3.22.3' - // implementation 'org.xmtp:proto-kotlin:3.40.1' + // implementation 'com.google.crypto.tink:tink-android:1.8.0' + // implementation 'io.grpc:grpc-kotlin-stub:1.4.1' + // implementation 'io.grpc:grpc-okhttp:1.62.2' + // implementation 'io.grpc:grpc-protobuf-lite:1.62.2' + // implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3' + // implementation 'org.web3j:crypto:5.0.0' + // implementation "net.java.dev.jna:jna:5.14.0@aar" + // api 'com.google.protobuf:protobuf-kotlin-lite:3.22.3' + // api 'org.xmtp:proto-kotlin:3.61.1' } diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt index 94d73aa72..367bf8e6c 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt @@ -15,6 +15,7 @@ class GroupWrapper { val permissionString = when (group.permissionLevel()) { GroupPermissions.ALL_MEMBERS -> "all_members" GroupPermissions.ADMIN_ONLY -> "admin_only" + GroupPermissions.CUSTOM_POLICY -> "custom_policy" } return mapOf( "clientAddress" to client.address, diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 58c02bd8e..44d07280f 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -56,7 +56,7 @@ PODS: - hermes-engine/Pre-built (= 0.71.14) - hermes-engine/Pre-built (0.71.14) - libevent (2.1.12) - - LibXMTP (0.5.3-beta1) + - LibXMTP (0.5.3-beta2) - Logging (1.0.0) - MessagePacker (0.4.7) - MMKV (1.3.5): @@ -449,16 +449,16 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.12.3): + - XMTP (0.12.4): - Connect-Swift (= 0.12.0) - GzipSwift - - LibXMTP (= 0.5.3-beta1) + - LibXMTP (= 0.5.3-beta2) - web3.swift - XMTPReactNative (0.1.0): - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.12.3) + - XMTP (= 0.12.4) - Yoga (1.14.0) DEPENDENCIES: @@ -711,7 +711,7 @@ SPEC CHECKSUMS: GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - LibXMTP: a4e1c78fd1b174c56b764e96eff70e39c46c2499 + LibXMTP: c0f992e33c4ac95bdf2652f9429b3999890b6ab3 Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02 MMKV: 506311d0494023c2f7e0b62cc1f31b7370fa3cfb @@ -763,8 +763,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 5cf6c97a5cfc7295226b8e14dc079f975ea3a4be - XMTPReactNative: 520f9714e30d2909b14718654cc400473ab8d302 + XMTP: 7d69afe403538056efb6caf01db7248b01221c48 + XMTPReactNative: 938a95995dcd9ddf7db3872ee69c59e59105cfaa Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 diff --git a/example/src/tests/groupPermissionsTests.ts b/example/src/tests/groupPermissionsTests.ts index 81121f9b7..c0463f4ab 100644 --- a/example/src/tests/groupPermissionsTests.ts +++ b/example/src/tests/groupPermissionsTests.ts @@ -359,3 +359,35 @@ test('can commit after invalid permissions commit', async () => { return true }) + +test('group with All Members policy has remove function that is admin only', async () => { + // Create clients + const [alix, bo, caro] = await createClients(3) + + // Bo creates a group with Alix and Caro with all_members policy + const boGroup = await bo.conversations.newGroup( + [alix.address, caro.address], + { permissionLevel: 'all_members' } + ) + await alix.conversations.syncGroups() + const alixGroup = (await alix.conversations.listGroups())[0] + + // Verify that Alix cannot remove a member + try { + await alixGroup.removeMembers([caro.address]) + assert(false, 'Alix should not be able to remove a member') + } catch (error) { + // expected + } + + // Verify that Bo (admin) can remove a member + await boGroup.removeMembers([caro.address]) + await boGroup.sync() + const members = await boGroup.memberInboxIds() + assert( + !members.includes(caro.inboxId), + `Caro should have been removed from the group but is still a member` + ) + + return true +}) diff --git a/ios/Wrappers/GroupWrapper.swift b/ios/Wrappers/GroupWrapper.swift index dd98115df..688339959 100644 --- a/ios/Wrappers/GroupWrapper.swift +++ b/ios/Wrappers/GroupWrapper.swift @@ -16,6 +16,8 @@ struct GroupWrapper { "all_members" case .adminOnly: "admin_only" + case .customPolicy: + "custom_policy" } return [ "clientAddress": client.address, diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index 0bc569ecd..a0a785738 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -26,5 +26,5 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" s.dependency 'secp256k1.swift' s.dependency "MessagePacker" - s.dependency "XMTP", "= 0.12.3" + s.dependency "XMTP", "= 0.12.4" end diff --git a/src/lib/Group.ts b/src/lib/Group.ts index 9522699d6..73faf80ed 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -23,7 +23,7 @@ export class Group< version = ConversationVersion.GROUP topic: string creatorInboxId: InboxId - permissionLevel: 'all_members' | 'admin_only' + permissionLevel: 'all_members' | 'admin_only' | 'custom_policy' name: string isGroupActive: boolean imageUrlSquare: string @@ -35,7 +35,7 @@ export class Group< createdAt: number peerInboxIds: InboxId[] creatorInboxId: InboxId - permissionLevel: 'all_members' | 'admin_only' + permissionLevel: 'all_members' | 'admin_only' | 'custom_policy' topic: string name: string isGroupActive: boolean