Skip to content

Commit

Permalink
Merge pull request #431 from xmtp/cv/invalid-permission-refactor-errors
Browse files Browse the repository at this point in the history
Adds custom policy type, fixes invalid policy error
  • Loading branch information
cameronvoell authored Jun 25, 2024
2 parents 018a965 + 74ddcf1 commit 86652bc
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 20 deletions.
20 changes: 10 additions & 10 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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('<PATH TO XMTP-ANDROID>/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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -711,7 +711,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: a4e1c78fd1b174c56b764e96eff70e39c46c2499
LibXMTP: c0f992e33c4ac95bdf2652f9429b3999890b6ab3
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: 506311d0494023c2f7e0b62cc1f31b7370fa3cfb
Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions example/src/tests/groupPermissionsTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
2 changes: 2 additions & 0 deletions ios/Wrappers/GroupWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct GroupWrapper {
"all_members"
case .adminOnly:
"admin_only"
case .customPolicy:
"custom_policy"
}
return [
"clientAddress": client.address,
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 86652bc

Please sign in to comment.