Exemple #1
0
def _internal_to_api_format(internal_attrs: UserSpec) -> dict[str, Any]:
    api_attrs: dict[str, Any] = {}
    api_attrs.update(_idle_options_to_api_format(internal_attrs))
    api_attrs.update(_auth_options_to_api_format(internal_attrs))
    api_attrs.update(_contact_options_to_api_format(internal_attrs))
    api_attrs.update(_notification_options_to_api_format(internal_attrs))

    if "locked" in internal_attrs:
        api_attrs["disable_login"] = internal_attrs["locked"]

    if "alias" in internal_attrs:
        api_attrs["fullname"] = internal_attrs["alias"]

    if "pager" in internal_attrs:
        api_attrs["pager_address"] = internal_attrs["pager"]

    api_attrs.update(
        {
            k: v
            for k, v in internal_attrs.items()
            if k
            in (
                "roles",
                "contactgroups",
                "language",
                "customer",
            )
        }
    )
    return api_attrs
Exemple #2
0
def _internal_to_api_format(internal_attrs: UserSpec) -> dict[str, Any]:
    api_attrs: dict[str, Any] = {}
    api_attrs.update(_idle_options_to_api_format(internal_attrs))
    api_attrs.update(_auth_options_to_api_format(internal_attrs))
    api_attrs.update(_notification_options_to_api_format(internal_attrs))
    interface_options = _interface_options_to_api_format({  # type: ignore
        k: v
        for k, v in internal_attrs.items() if k in [
            "ui_theme",
            "ui_sidebar_position",
            "nav_hide_icons_title",
            "icons_per_item",
            "show_mode",
        ]
    })
    if interface_options:
        api_attrs["interface_options"] = interface_options

    if "email" in internal_attrs:
        api_attrs.update(_contact_options_to_api_format(internal_attrs))

    if "locked" in internal_attrs:
        api_attrs["disable_login"] = internal_attrs["locked"]

    if "alias" in internal_attrs:
        api_attrs["fullname"] = internal_attrs["alias"]

    if "pager" in internal_attrs:
        api_attrs["pager_address"] = internal_attrs["pager"]

    if "enforce_pw_change" in internal_attrs:
        api_attrs["enforce_password_change"] = internal_attrs[
            "enforce_pw_change"]

    api_attrs.update({
        k: v
        for k, v in internal_attrs.items() if k in (
            "roles",
            "contactgroups",
            "language",
            "customer",
        )
    })
    return api_attrs