Пример #1
0
def get_project_managers(username, project_id, enable_auth):
    """
    Returns the CLA project managers from the project's ID
    :param username: The LF username
    :type username: string
    :param project_id: The project's ID.
    :type project_id: string
    :return: dict representation of the project managers.
    :rtype: dict
    """
    project = Project()
    try:
        project.load(project_id=str(project_id))
    except DoesNotExist as err:
        return {'errors': {'project_id': str(err)}}

    if enable_auth is True and username not in project.get_project_acl():
        return {
            'errors': {
                'user_id': 'You are not authorized to see the managers.'
            }
        }

    # Generate managers dict
    managers_dict = []
    for lfid in project.get_project_acl():
        user = User()
        users = user.get_user_by_username(str(lfid))
        if users is not None:
            if len(users) > 1:
                cla.log.warning(
                    f'More than one user record was returned ({len(users)}) from user '
                    f'username: {lfid} query')
            user = users[0]
            # Manager found, fill with it's information
            managers_dict.append({
                'name': user.get_user_name(),
                'email': user.get_user_email(),
                'lfid': user.get_lf_username()
            })
        else:
            # Manager not in database yet, only set the lfid
            managers_dict.append({'lfid': str(lfid)})

    return managers_dict
Пример #2
0
def get_managers_dict(signature_acl):
    # Helper function to get a list of all cla managers from a CCLA Signature ACL
    # Generate managers dict
    managers_dict = []
    for lfid in signature_acl:
        user = User()
        user = user.get_user_by_username(str(lfid))
        if user is not None:
            # Manager found, fill with it's information
            managers_dict.append({
                'name': user.get_user_name(),
                'email': user.get_user_email(),
                'lfid': user.get_lf_username()
            })
        else:
            # Manager not in database yet, only set the lfid
            managers_dict.append({'lfid': str(lfid)})

    return managers_dict
Пример #3
0
def get_user_emails(lfid):
    """ Helper function that gets user emails of given lf_username """
    user = User()
    users = user.get_user_by_username(lfid)
    return [user.get_user_email() for user in users]
Пример #4
0
    def test_get_user_email(self):
        user = User()
        user.set_lf_email(None)
        user.set_user_emails([])
        assert user.get_user_email() is None

        user.set_lf_email("*****@*****.**")
        assert user.get_user_email() == "*****@*****.**"

        user = User(user_email="*****@*****.**")
        assert user.get_user_email() == "*****@*****.**"

        user = User(user_email="*****@*****.**", preferred_email="*****@*****.**")
        assert user.get_user_email() == "*****@*****.**"
        user.set_user_emails(["*****@*****.**", "*****@*****.**"])
        user.set_lf_email("*****@*****.**")
        assert user.get_user_email() == "*****@*****.**"

        # the scenario where have multiple emails
        user = User(preferred_email="*****@*****.**")
        user.set_user_emails(["*****@*****.**", "*****@*****.**", "*****@*****.**"])
        assert user.get_user_email() == "*****@*****.**"
        assert user.get_user_email(preferred_email="*****@*****.**") == "*****@*****.**"
        assert user.get_user_email(preferred_email="*****@*****.**") != "*****@*****.**"
        user.set_lf_email("*****@*****.**")
        assert user.get_user_email() == "*****@*****.**"
        assert user.get_user_email(preferred_email="*****@*****.**") == "*****@*****.**"
        assert user.get_user_email(preferred_email="*****@*****.**") == "*****@*****.**"
        assert user.get_user_email(preferred_email="*****@*****.**") == "*****@*****.**"