Source code for tdw_catalog.team_member

from tdw_catalog import Catalog
import tdw_catalog.team as team
import tdw_catalog.user as user
from tdw_catalog.entity import Entity, Property, EntityBase
from tdw_catalog.errors import _convert_error, _raise_error
from datetime import datetime


[docs]@Entity([ Property("group_id", str, display_key="team_id", relation="tdw_catalog.team.Team", serialize=True), Property("permission", 'team.TeamMemberPermissionLevel', writable=True), Property("created_at", datetime), Property("updated_at", datetime), ]) class TeamMember(user.User): """ A :class:`.TeamMember` reflects a relationship between :class:`.User` and :class:`.Team`, where the :class:`.User` has been invited to the :class:`.Team` and been granted specific privileges within the :class:`.Team`. Attributes ---------- team : team.Team The :class:`.Team` that relates to the team_id of the model team_id : str The unique ID of the :class:`.Team` to which this :class:`.TeamMember` belongs permission: TeamMemberPermissionLevel The permission level the :class:`.User` has within the :class:`.Team` created_at : datetime The timestamp this :class:`.TeamMember` was added to the :class:`.Team` updated_at : datetime The timestamp this :class:`.TeamMember` permission was changed """ _client: 'Catalog' team: 'team.Team' team_id: str permission: 'team.TeamMemberPermissionLevel' created_at: datetime updated_at: datetime def __str__(self) -> str: return f'<TeamMember id={self.user_id} group={self.team_id} permission={self.permission}>' def __eq__(self, other) -> bool: return isinstance( other, TeamMember ) and self.user_id == other.user_id and self.team_id == other.team_id
[docs] @classmethod def get(cls, client: 'Catalog', team_id: str, id: str): """ Retrieve an :class:`.TeamMember` Parameters ---------- client : Catalog The :class:`.Catalog` client team_id : str The unique ID of the :class:`.Team` id : str The unique ID of the :class:`.TeamMember` Returns ------- TeamMember The :class:`.TeamMember` associated with the given ID Raises ------ CatalogInternalException If call to the :class:`.Catalog` server fails CatalogNotFoundException If no :class:`.TeamMember` is found matching the provided ID CatalogPermissionDeniedException If the caller is not allowed to retrieve this :class:`.TeamMember` """ try: res = client._get_group_member(group_id=team_id, user_id=id) return TeamMember(client, **res) except Exception as e: err = _raise_error(e, "Unable to fetch TeamMember {}".format(id))
[docs] def save(self) -> None: """ Update this :class:`.TeamMember`, saving any changes to its permission level Parameters ---------- None Returns ------- None Raises ------ CatalogPermissionDeniedException If the caller is not allowed to update this :class:`.TeamMember` CatalogInvalidArgumentException If the caller supplies an invalid permission level before saving this :class:`.TeamMember` CatalogException If call to the :class:`.Catalog` server fails """ try: self._client._update_group_member(member=self.serialize()) except Exception as e: raise _convert_error(e)
[docs] def delete(self) -> None: """ Remove this :class:`.TeamMember` from the :class:`.Team`. This :class:`.TeamMember` object should not be used after `delete()` returns successfully. Parameters ---------- None Returns ------- None Raises ------ CatalogPermissionDeniedException If the caller is not allowed to delete this :class:`.TeamMember`, or if the caller is attempting to delete themselves CatalogException If call to the :class:`.Catalog` server fails """ try: self._client._remove_group_member(member=self.serialize()) except Exception as e: raise _convert_error(e)