Esempio n. 1
0
def get_project_companies(project_id):
    """
    Get a project's associated companies (via CCLA link).

    :param project_id: The ID of the project.
    :type project_id: string
    """
    project = get_project_instance()
    try:
        project.load(str(project_id))
    except DoesNotExist as err:
        return {'errors': {'project_id': str(err)}}

    # Get all reference_ids of signatures that match project_id AND are of reference type 'company'.
    # Return all the companies matching those reference_ids.
    signature = Signature()
    signatures = signature.get_signatures_by_project(str(project_id),
                                                     signature_signed=True,
                                                     signature_approved=True,
                                                     signature_reference_type='company')
    company_ids = list(set([signature.get_signature_reference_id() for signature in signatures]))
    company = Company()
    all_companies = [comp.to_dict() for comp in company.all(company_ids)]
    all_companies = sorted(all_companies, key=lambda i: i['company_name'].casefold())

    return all_companies
Esempio n. 2
0
def get_user_project_signatures(user_id, project_id, signature_type=None):
    """
    Get all signatures for user filtered by a project.

    :param user_id: The ID of the user in question.
    :type user_id: string
    :param project_id: The ID of the project to filter by.
    :type project_id: string
    :param signature_type: The signature type to filter by.
    :type signature_type: string (one of 'individual', 'employee')
    :return: The list of signatures requested.
    :rtype: [cla.models.model_interfaces.Signature]
    """
    sig = Signature()
    signatures = sig.get_signatures_by_project(
        str(project_id),
        signature_reference_type='user',
        signature_reference_id=str(user_id))
    ret = []
    for signature in signatures:
        if signature_type is not None:
            if signature_type == 'individual' and \
                    signature.get_signature_user_ccla_employee_id() is not None:
                continue
            elif signature_type == 'employee' and \
                    signature.get_signature_user_ccla_employee_id() is None:
                continue
        ret.append(signature.to_dict())
    return ret