Back

Team permission not working since the new update (1.3.1)

  • 0
  • Databases
  • Apple
DjeBen
20 Apr, 2023, 12:57

Create:

TypeScript
let babyResult: Baby = try await database.createDocument(
            databaseId: R.Database.babyBottleDbId,
            collectionId: R.Database.babyCollectionId,
            documentId: babyId,
            data: data,
            permissions: [
                Permission.read(Role.team(babyId)),
                Permission.write(Role.team(babyId)),
                Permission.delete(Role.team(babyId)),
                Permission.update(Role.team(babyId))
            ], nestedType: Baby.self).data
TL;DR
Issue: Team permissions are not working since the new update (1.3.1). There is some funky behavior with permissions and a query limit value needs to be added to fix the issue. Solution: Add a query limit of 100 to the listDocuments query. Additionally, check if the user has specific permissions for the document and try redoing the database migration if necessary. Please Note: The solution code provided is in Swift and TypeScript.
DjeBen
20 Apr, 2023, 12:58

Get:

TypeScript
func fetchBabies() async throws -> [Baby] {
        try await database.listDocuments(
                databaseId: Constants.Database.babyBottleDbId,
                collectionId: Constants.Database.babyCollectionId,
                nestedType: Baby.self
        ).documents.map { $0.data }
    }
DjeBen
20 Apr, 2023, 13:00

I can see the document and the permission are ok in the console

DjeBen
20 Apr, 2023, 13:00

And my user has membership of the team of course

Hearstgo
20 Apr, 2023, 13:10

is it normal that the document ID is the same as the team ID ? (babyId)

DjeBen
20 Apr, 2023, 13:12

Yeah creating a baby also create a team with the same id (easier for me)

DjeBen
20 Apr, 2023, 13:12

(this allow users to manage the same baby if they are member of the same team)

Hearstgo
20 Apr, 2023, 13:14
TypeScript

func fetchBabies() async throws -> [Baby] {
        let response = await database.listDocuments(
                databaseId: Constants.Database.babyBottleDbId,
                collectionId: Constants.Database.babyCollectionId,
                nestedType: Baby.self
        )
        console.log(response)
    }

Can you try this instead ? I think that the problem might be coming from the .map

DjeBen
20 Apr, 2023, 13:15

Sorry, I proxy the request and I have printed the network response and Document is empty but total is 1 (see my first message)

Hearstgo
20 Apr, 2023, 13:15

Oh okk weird 🤔

DjeBen
20 Apr, 2023, 13:16

maybe a bad migration? I can re-run the database migration just to see

Hearstgo
20 Apr, 2023, 13:16

maybe yeah, before that can you try to add user permission for this document ? see if it change anything ?

Hearstgo
20 Apr, 2023, 13:16

(in addition as the team permission)

DjeBen
20 Apr, 2023, 13:18

yeah I've tried to add permission to my specific user, it didn't changed anything

Hearstgo
20 Apr, 2023, 13:18

well I have no idea sorry, maybe try to redo a migration

DjeBen
20 Apr, 2023, 13:21

no effects 😦

DjeBen
20 Apr, 2023, 13:29

Looks like Document Security is ignored only collection permission works

DjeBen
20 Apr, 2023, 13:41

Update: adding a query limit fix the issue:

DjeBen
20 Apr, 2023, 13:42

solution:

TypeScript
func fetchBabies() async throws -> [Baby] {
        try await database.listDocuments(
                databaseId: Constants.Database.babyBottleDbId,
                collectionId: Constants.Database.babyCollectionId,
                queries: [
                    Query.limit(100) // otherwise document are empty!
                ],
                nestedType: Baby.self
        ).documents.map { $0.data }
    }
Hearstgo
20 Apr, 2023, 13:49

That's super weird

DjeBen
20 Apr, 2023, 13:56

Ok what is super weird is that I have another listDocument query with a limit, and if I don't put the same query limit value for the both request, it doesn't works

DjeBen
20 Apr, 2023, 13:56

I think there is a really issue somewhere

Drake
20 Apr, 2023, 18:08

Ya, there's some funky behavior with permissions at the moment. We're working through them ASAP

DjeBen
20 Apr, 2023, 18:11

Thanks @Steven I’m using the query limite as workaround for now

Drake
27 Apr, 2023, 20:49
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more