Пример #1
0
def new_user_template(connection_id: str) -> UserSpec:
    new_user = UserSpec(
        serial=0,
        connector=connection_id,
    )

    # Apply the default user profile
    new_user.update(config.default_user_profile)
    return new_user
Пример #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(_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
Пример #3
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
Пример #4
0
def _show_custom_user_attr(user_spec: UserSpec, custom_attr) -> None:
    for name, attr in custom_attr:
        if attr.user_editable():
            vs = attr.valuespec()
            forms.section(_u(vs.title()))
            value = user_spec.get(name, vs.default_value())
            if not attr.permission() or user.may(attr.permission()):
                vs.render_input("ua_" + name, value)
                html.help(_u(vs.help()))
            else:
                html.write_text(vs.value_to_html(value))
Пример #5
0
def make_default_user_profile() -> UserSpec:
    return UserSpec(
        contactgroups=[],
        roles=["user"],
        force_authuser=False,
    )
Пример #6
0
def add_internal_attributes(usr: UserSpec) -> int:
    return usr.setdefault("user_scheme_serial", USER_SCHEME_SERIAL)