Back

Filter team membership by role

  • 0
  • Auth
Ernest
15 Nov, 2024, 18:23

Is there a way to filter team membership by role? I can't seem to find any information regarding it in the docs. There's listMemberships but it doesn't seem to provide a way to specify roles. Any help will be greatly appreciated.

TL;DR
Developers discussing filtering team memberships by role in an admin dashboard. Filtering by roles currently not possible; a feature request should be created on Github. Use the attributes provided in the Appwrite documentation for filtering. The current workaround is filtering locally, albeit insecure.
ZachHandley
15 Nov, 2024, 18:27

you'd want to Query for it, so

TypeScript
const result = await teams.listMemberships(
    '<TEAM_ID>', // teamId
    [
      Query.contains("roles", "your_role"),
    ], // queries (optional)
    '<SEARCH>' // search (optional)
);
Ernest
15 Nov, 2024, 18:28

Already tried that it doesn't work. I get attribute not found.

ZachHandley
15 Nov, 2024, 18:29

roles?

Ernest
15 Nov, 2024, 18:30

Yes

ZachHandley
15 Nov, 2024, 18:30

I assume you tried the search attribute too?

Ernest
15 Nov, 2024, 18:30

Yes I did. It returns empty response.

ZachHandley
15 Nov, 2024, 18:31

Sometimes the attributes aren't exactly as they are written, it might be labels in the backend

I know for me, I pull the memberships of the team and then filter, but that's because my teams won't be that big, so I just store the value client-side in a local store

Ernest
15 Nov, 2024, 18:33

My teams can have a great number of members so it's not feasible for me to fetch all the team members then filter

Ernest
15 Nov, 2024, 18:37

Guess I'd have to use a collection to keep track of the teamId+userId+roles I'm interested in filtering. 🤦‍♂️ I'd prefer not to go with this approach so I'd wait for a bit if anyone has any idea.

ZachHandley
15 Nov, 2024, 18:57

what's the usecase you have?

ZachHandley
15 Nov, 2024, 18:57

@Steven what's the best approach here?

Ernest
15 Nov, 2024, 19:07

For my use case every team has an owner, moderators and members. In an admin dashboard, there's a page where I have to show only the moderators for each team and perform some actions.

Steven
15 Nov, 2024, 20:39

The docs tell you want attributes you can filter on: https://appwrite.io/docs/references/cloud/server-nodejs/teams#listMemberships

Steven
15 Nov, 2024, 20:40

it would be best to create a feature request and make sure to include this use case in the github issue

Ernest
15 Nov, 2024, 20:48

Yes I checked, filtering by roles is not possible atm

Ernest
15 Nov, 2024, 20:48

Noted, thanks

ZachHandley
15 Nov, 2024, 22:00

I did this, but I pulled them all and filtered locally, it's insecure technically if you view the network request, but it shouldn't be an issue overall, it just might take a second if they have > 1000 members

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