Пример #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 test_add_project_manager(mock_event, project):
    """ Tests event logging where LFID is added to the project ACL """
    event_type = EventType.AddProjectManager
    username = '******'
    lfid = 'manager'
    Project.load = Mock()
    Project.get_project_name = Mock(return_value=project.get_project_name())
    Project.save = Mock()
    user = User()
    user.set_user_name('foo')
    Project.get_managers_by_project_acl = Mock(return_value=[user])
    Project.add_project_acl = Mock()
    Project.get_project_acl = Mock(return_value=('foo'))

    project_controller.add_project_manager(
        username,
        project.get_project_id(),
        lfid
    )
    event_data = '{} added {} to project {}'.format(username,lfid,project.get_project_name())

    mock_event.assert_called_with(
        event_type=event_type,
        event_data=event_data,
        event_summary=event_data,
        event_project_id=project.get_project_id(),
        contains_pii=True,
    )
Пример #3
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
Пример #4
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
Пример #5
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
Пример #6
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]