Source code for pydelfini.delfini_core.models.user_admin

import datetime
from typing import Any
from typing import cast
from typing import Dict
from typing import List
from typing import Type
from typing import TypeVar
from typing import Union

from attrs import define as _attrs_define
from dateutil.parser import isoparse

from ..models.user_admin_group_roles import UserAdminGroupRoles
from ..types import UNSET
from ..types import Unset


T = TypeVar("T", bound="UserAdmin")


[docs] @_attrs_define class UserAdmin: """User administrative settings Attributes: has_password (bool): True if the user can sign in with a username and password disabled_on (Union[None, Unset, datetime.datetime]): group_roles (Union[Unset, UserAdminGroupRoles]): The user's role in each of their groups, keyed by group id providers (Union[Unset, List[str]]): External sign-in providers linked to the user, such as google """ has_password: bool disabled_on: Union[None, Unset, datetime.datetime] = UNSET group_roles: Union[Unset, "UserAdminGroupRoles"] = UNSET providers: Union[Unset, List[str]] = UNSET
[docs] def to_dict(self) -> Dict[str, Any]: """Convert to a dict""" has_password = self.has_password disabled_on: Union[None, Unset, str] if isinstance(self.disabled_on, Unset): disabled_on = UNSET elif isinstance(self.disabled_on, datetime.datetime): disabled_on = self.disabled_on.isoformat() else: disabled_on = self.disabled_on group_roles: Union[Unset, Dict[str, Any]] = UNSET if not isinstance(self.group_roles, Unset): group_roles = self.group_roles.to_dict() providers: Union[Unset, List[str]] = UNSET if not isinstance(self.providers, Unset): providers = self.providers field_dict: Dict[str, Any] = {} field_dict.update( { "has_password": has_password, } ) if disabled_on is not UNSET: field_dict["disabled_on"] = disabled_on if group_roles is not UNSET: field_dict["group_roles"] = group_roles if providers is not UNSET: field_dict["providers"] = providers return field_dict
[docs] @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: """Create an instance of :py:class:`UserAdmin` from a dict""" d = src_dict.copy() has_password = d.pop("has_password") def _parse_disabled_on(data: object) -> Union[None, Unset, datetime.datetime]: if data is None: return data if isinstance(data, Unset): return data try: if not isinstance(data, str): raise TypeError() disabled_on_type_0 = isoparse(data) return disabled_on_type_0 except: # noqa: E722 pass return cast(Union[None, Unset, datetime.datetime], data) disabled_on = _parse_disabled_on(d.pop("disabled_on", UNSET)) _group_roles = d.pop("group_roles", UNSET) group_roles: Union[Unset, UserAdminGroupRoles] if isinstance(_group_roles, Unset): group_roles = UNSET else: group_roles = UserAdminGroupRoles.from_dict(_group_roles) providers = cast(List[str], d.pop("providers", UNSET)) user_admin = cls( has_password=has_password, disabled_on=disabled_on, group_roles=group_roles, providers=providers, ) return user_admin