Example #1
0
def _get_user_public_base_field_names(fields: Iterable['UserField'],
                                      write_once: bool = False) -> List[str]:
    default_field_names = [f.name for f in fields]
    email_field_name = get_user_email_field_name()
    hidden_field_names = set(get_user_setting('HIDDEN_FIELDS'))
    _public_field_names = get_user_setting(
        'PUBLIC_FIELDS')  # type: Optional[Iterable[str]]
    public_field_names = set_or_none(_public_field_names)

    base_field_names = default_field_names
    if public_field_names is not None:
        allowed_field_names = public_field_names | {
            'password', email_field_name
        }
        base_field_names = [
            f for f in base_field_names if f in allowed_field_names
        ]
    else:
        base_field_names = [
            f for f in base_field_names if f not in hidden_field_names
        ]

    if not write_once:
        base_field_names = [f for f in base_field_names if f != 'password']

    return base_field_names
Example #2
0
def _get_user_public_read_only_field_names(fields: Iterable['UserField'],
                                           write_once: bool = False
                                           ) -> List[str]:
    pk_name = _get_pk_name(fields)
    base_field_names = _get_user_public_base_field_names(fields,
                                                         write_once=write_once)
    email_field_name = get_user_email_field_name()
    _editable_field_names = get_user_setting(
        'EDITABLE_FIELDS')  # type: Optional[Iterable[str]]
    editable_field_names = set_or_none(_editable_field_names)
    if write_once:
        excludes = {'last_login', pk_name}
    else:
        excludes = {'last_login', email_field_name, pk_name}
    field_names_rw = [f for f in base_field_names if f not in excludes]

    if not write_once and editable_field_names is not None:
        field_names_rw = [
            f for f in field_names_rw if f in editable_field_names
        ]

    return [f for f in base_field_names if f not in field_names_rw]