Skip to content

Commit

Permalink
Add endpoint to get user memberships and group info
Browse files Browse the repository at this point in the history
  • Loading branch information
brodokk committed Oct 15, 2024
1 parent 23f31c8 commit db850b1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
14 changes: 14 additions & 0 deletions resonitepy/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,13 @@ class ResoniteUser:
tags: Optional[List[str]] = field(default_factory=list)
"""The tags associated with the user."""

@dataclass
class ResoniteUserMembership:
id: str
groupName: str
isMigrated: bool
ownerId: str

@dataclass
class WorldId:
""" Data class representing a World ID.
Expand All @@ -543,6 +550,13 @@ class WorldId:
recordId: str
"""The record ID of the world."""

@dataclass
class ResoniteGroup:
id: str
adminUserId: str
name: str
isMigrated: bool

@dataclass
class ResoniteSessionUser:
""" Data class representing a Resonite session user.
Expand Down
24 changes: 24 additions & 0 deletions resonitepy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
OwnerType,
ResoniteCloudVarDefs,
Platform,
ResoniteUserMembership,
ResoniteGroup,
)
from .utils import getOwnerType

Expand Down Expand Up @@ -431,6 +433,28 @@ def getUserData(self, user: str = None) -> ResoniteUser:
response['supporterMetadata'] = supporterMetadatas
return to_class(ResoniteUser, response, DACITE_CONFIG)

def getMemberships(self) -> List[ResoniteUserMembership]:
""" Retrieve current connected user group memberships.
Return
List[ResoniteUserMembership]: The list of groups where the user is a member.
"""
response = self.request('get', f'/users/{self.userId}/Memberships')
return [to_class(ResoniteUserMembership, group, DACITE_CONFIG) for group in response]

def getGroup(self, groupId: str) -> ResoniteGroup:
""" Retrieve group information.
Args:
groupId (str): The group name starting with G-
Returns:
ResoniteGroup: An object with the group information
"""
response = self.request('get', f'/groups/{groupId}')
return to_class(ResoniteGroup, response, DACITE_CONFIG)

def getSessions(
self,
compatibilityHash: str = None,
Expand Down
5 changes: 4 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
)

user = client.getUserData()
user_groups = client.getMemberships()
sessions = client.getSessions()
session = client.getSession(sessions[0].sessionId)
contacts = client.getContacts()
Expand All @@ -47,7 +48,9 @@
if tested_directory and tested_link:
break
legacy_messages = client.getMessageLegacy()

owner_path_user = client.getOwnerPath(client.userId)
owner_path_group = client.getOwnerPath(user_groups[0].id)
group = client.getGroup(user_groups[0].id)

# TODO: VERY IMPORTANT I NEED TO CONTINUE THIS AND PATCH MORE STUFF IF NEEDED BEFORE DOING A RELEASE!
platform = client.platform()

0 comments on commit db850b1

Please sign in to comment.