Пример #1
0
def get_or_create_user(auth_user):
    user = User()

    # Returns None or List[User] objects - could be more than one
    users = user.get_user_by_username(str(auth_user.username))

    if users is None:
        user.set_user_id(str(uuid.uuid4()))
        user.set_user_name(auth_user.name)
        user.set_lf_email(auth_user.email.lower())
        user.set_lf_username(auth_user.username)
        user.set_lf_sub(auth_user.sub)

        user.save()

        event_data = f'CLA user added for {auth_user.username}'
        Event.create_event(
            event_data=event_data,
            event_type=EventType.CreateUser,
            contains_pii=True,
        )

        return user

    # Just return the first matching record
    return users[0]
Пример #2
0
def user(user_table):
    """ create user """
    with patch(PATCH_METHOD) as req:
        req.return_value = {}
        user_instance = User()
        user_instance.set_user_id("user_foo_id")
        user_instance.set_user_email("*****@*****.**")
        user_instance.set_user_name("foo_username")
        user_instance.save()
        yield user_instance
Пример #3
0
def user_instance():
    """
    Mock user instance
    """
    with patch(PATCH_METHOD) as req:
        req.return_value = USER_TABLE_DATA
        instance = User()
        instance.set_user_id("foo")
        instance.set_user_name("username")
        instance.set_user_external_id("bar")
        instance.save()
        yield instance
Пример #4
0
def get_or_create_user(auth_user):
    user = User()

    existing_user = user.get_user_by_username(str(auth_user.username))

    if existing_user is None:
        user.set_user_id(str(uuid.uuid4()))
        user.set_user_name(auth_user.name)
        user.set_lf_email(auth_user.email.lower())
        user.set_lf_username(auth_user.username)
        user.set_lf_sub(auth_user.sub)

        user.save()

        return user

    return existing_user
Пример #5
0
def get_or_create_user(auth_user):
    user = User()

    # Returns None or List[User] objects - could be more than one
    users = user.get_user_by_username(str(auth_user.username))

    if users is None:
        user.set_user_id(str(uuid.uuid4()))
        user.set_user_name(auth_user.name)
        user.set_lf_email(auth_user.email.lower())
        user.set_lf_username(auth_user.username)
        user.set_lf_sub(auth_user.sub)

        user.save()

        return user

    # Just return the first matching record
    return users[0]