Ejemplo n.º 1
0
def add_cla_manager(auth_user, signature_id, lfid):
    """
    Adds the LFID to the signature ACL and returns a new list of CLA Managers. 

    :param username: username of the user
    :type username: string
    :param signature_id: The ID of the project
    :type signature_id: UUID
    :param lfid: the lfid (manager username) to be added to the project acl
    :type lfid: string
    """
    # Find project
    signature = Signature()
    try:
        signature.load(str(signature_id))
    except DoesNotExist as err:
        return {'errors': {'project_id': str(err)}}

    # Get Signature ACL
    signature_acl = signature.get_signature_acl()

    if auth_user.username not in signature_acl:
        return {'errors': {'user_id': 'You are not authorized to see the managers.'}}

    company.add_permission(auth_user, lfid, signature.get_signature_reference_id(), ignore_auth_user=True)

    # Add lfid to acl
    signature.add_signature_acl(lfid)
    signature.save()

    return get_managers_dict(signature_acl)
Ejemplo n.º 2
0
def add_cla_manager(auth_user, signature_id, lfid):
    """
    Adds the LFID to the signature ACL and returns a new list of CLA Managers.

    :param username: username of the user
    :type username: string
    :param signature_id: The ID of the project
    :type signature_id: UUID
    :param lfid: the lfid (manager username) to be added to the project acl
    :type lfid: string
    """

    # Find project
    signature = Signature()
    try:
        signature.load(str(signature_id))
    except DoesNotExist as err:
        return {'errors': {'project_id': str(err)}}

    # Get Signature ACL
    signature_acl = signature.get_signature_acl()

    if auth_user.username not in signature_acl:
        return {'errors': {'user_id': 'You are not authorized to see the managers.'}}

    company.add_permission(auth_user, lfid, signature.get_signature_reference_id(), ignore_auth_user=True)
    # Get Company and Project instances
    try:
        project = get_project(signature.get_signature_project_id())
    except DoesNotExist as err:
        return err
    try:
        company_instance = get_company(signature.get_signature_reference_id())
    except DoesNotExist as err:
        return err

    # get cla managers for email content
    managers = get_cla_managers(auth_user.username, signature_id)

    # Add lfid to acl
    signature.add_signature_acl(lfid)
    signature.save()

    # send email to newly added CLA manager
    try:
        subject, body, recipients = add_cla_manager_email_content(lfid, project, company_instance, managers)
        get_email_service().send(subject, body, recipients)
    except Exception as err:
        return {'errors': {'Failed to send email for lfid: %s , %s ' % (lfid, err)}}

    event_data = f'{lfid} added as cla manager to Signature ACL for {signature.get_signature_id()}'
    Event.create_event(
        event_data=event_data,
        event_summary=event_data,
        event_type=EventType.AddCLAManager,
        contains_pii=True,
    )

    return get_managers_dict(signature_acl)
Ejemplo n.º 3
0
def test_add_permission(mock_event, create_event_company, auth_user, company):
    """ Test add permission event """
    event_type = EventType.AddCompanyPermission
    Company.load = Mock()
    Company.add_company_acl = Mock()
    auth_user.username = '******'
    username = '******'
    company_controller.add_permission(auth_user,
                                      username,
                                      company.get_company_id(),
                                      ignore_auth_user=True)
    event_data = f'Added to user {username} to Company {company.get_company_name()} permissions list.'
    mock_event.assert_called_once_with(
        event_data=event_data,
        event_summary=event_data,
        event_type=event_type,
        event_company_id=company.get_company_id(),
        contains_pii=True,
    )