Example #1
0
def return_url(signature_id, event=None):  # pylint: disable=unused-argument
    """
    Handle the GET request from the user once they have successfully signed.

    :param signature_id: The ID of the signature they have just signed.
    :type signature_id: string
    :param event: The event GET flag sent back from the signing service provider.
    :type event: string | None
    """
    try:  # Load the signature based on ID.
        signature = get_signature_instance()
        signature.load(str(signature_id))
    except DoesNotExist as err:
        cla.log.error('Invalid signature_id provided when trying to send user back to their ' + \
                      'return_url after signing: %s', signature_id)
        return {'errors': {'signature_id': str(err)}}
    # Ensure everything went well on the signing service provider's side.
    if event is not None:
        # Expired signing URL - the user was redirected back immediately but still needs to sign.
        if event == 'ttl_expired' and not signature.get_signature_signed():
            # Need to re-generate a sign_url and try again.
            cla.log.info('DocuSign URL used was expired, re-generating sign_url')
            callback_url = signature.get_signature_callback_url()
            get_signing_service().populate_sign_url(signature, callback_url)
            signature.save()
            raise falcon.HTTPFound(signature.get_signature_sign_url())
    ret_url = signature.get_signature_return_url()
    if ret_url is not None:
        cla.log.info('Signature success - sending user to return_url: %s', ret_url)
        raise falcon.HTTPFound(ret_url)
    cla.log.info('No return_url set for signature - returning success message')
    return {'success': 'Thank you for signing'}
Example #2
0
def signature_instance():
    """
    Mock signature instance
    """
    with patch(PATCH_METHOD) as req:
        req.return_value = SIGNATURE_TABLE_DATA
        instance = get_signature_instance()
        instance.set_signature_id("sig_id")
        instance.set_signature_project_id("proj_id")
        instance.set_signature_reference_id("ref_id")
        instance.set_signature_type("type")
        instance.set_signature_project_external_id("proj_id")
        instance.set_signature_company_signatory_id("comp_sig_id")
        instance.set_signature_company_signatory_name("name")
        instance.set_signature_company_signatory_email("email")
        instance.set_signature_company_initial_manager_id("manager_id")
        instance.set_signature_company_initial_manager_name("manager_name")
        instance.set_signature_company_initial_manager_email("manager_email")
        instance.set_signature_company_secondary_manager_list({"foo": "bar"})
        instance.set_signature_document_major_version(1)
        instance.set_signature_document_minor_version(2)
        instance.save()
        yield instance
PROJECT_EXTERNAL_ID1 = 'a090t0000008DEiAAM'
PROJECT_EXTERNAL_ID2 = 'a090t0000008E7iAAE'
COMPANY_EXTERNAL_ID = 'company-external-id'
USER_GITHUB_ID = 123

user = get_user_instance().get_user_by_github_id(USER_GITHUB_ID)
project1 = get_project_instance().get_projects_by_external_id(PROJECT_EXTERNAL_ID1)[0]
project2 = get_project_instance().get_projects_by_external_id(PROJECT_EXTERNAL_ID2)[0]
company = get_company_instance().get_company_by_external_id(COMPANY_EXTERNAL_ID)

# Test ICLA Agreement.
sig_id = str(uuid.uuid4())
cla.log.info('Creating ICLA signature for user %s and project %s: %s' \
             %(user.get_user_name(), project1.get_project_external_id(), sig_id))
signature = get_signature_instance()
signature.set_signature_id(sig_id)
signature.set_signature_project_id(project1.get_project_id())
signature.set_signature_signed(True)
signature.set_signature_approved(True)
signature.set_signature_type('cla')
signature.set_signature_reference_id(user.get_user_id())
signature.set_signature_reference_type('user')
signature.set_signature_document_major_version(1)
signature.set_signature_document_minor_version(0)
signature.save()

# Test CCLA Agreement with project one.
sig_id = str(uuid.uuid4())
cla.log.info('Creating CCLA signature for company %s and project %s: %s' \
             %(company.get_company_external_id(), project1.get_project_external_id(), sig_id))
Example #4
0
## Add another company with same manager ID
cla.log.info('Creating new company with manager ID: %s', manager.get_user_id())
company = get_company_instance()
company.set_company_id(str(uuid.uuid4()))
company.set_company_external_id('company-external-id')
company.set_company_manager_id(manager.get_user_id())
company.set_company_name('Test Company 2')
company.set_company_whitelist([])
company.set_company_whitelist_patterns(['*@listed.org'])
company.save()

## Signature: Corporate
corporate_signature_id = str(uuid.uuid4())
cla.log.info('Creating CCLA signature for company %s and project %s: %s' \
             %(company.get_company_external_id(), project.get_project_external_id(), corporate_signature_id))
corporate_signature = get_signature_instance()
corporate_signature.set_signature_id(corporate_signature_id)
corporate_signature.set_signature_project_id(project.get_project_id())
corporate_signature.set_signature_signed(True)
corporate_signature.set_signature_approved(True)
corporate_signature.set_signature_type('cla')
corporate_signature.set_signature_reference_id(company.get_company_id())
corporate_signature.set_signature_reference_type('company')
corporate_signature.set_signature_document_major_version(1)
corporate_signature.set_signature_document_minor_version(0)
corporate_signature.save()

## Create CCLA Document
individual_template = CNCFTemplate(document_type='Individual',
                                   major_version=1,
                                   minor_version=0)
Example #5
0
def return_url(signature_id, event=None):  # pylint: disable=unused-argument
    """
    Handle the GET request from the user once they have successfully signed.

    :param signature_id: The ID of the signature they have just signed.
    :type signature_id: string
    :param event: The event GET flag sent back from the signing service provider.
    :type event: string | None
    """
    fn = 'return_url'
    try:  # Load the signature based on ID.
        signature = get_signature_instance()
        signature.load(str(signature_id))
    except DoesNotExist as err:
        cla.log.error('%s - Invalid signature_id provided when trying to send user back to their ' + \
                      'return_url after signing: %s', fn, signature_id)
        return {'errors': {'signature_id': str(err)}}
    # Ensure everything went well on the signing service provider's side.
    if event is not None:
        # Expired signing URL - the user was redirected back immediately but still needs to sign.
        if event == 'ttl_expired' and not signature.get_signature_signed():
            # Need to re-generate a sign_url and try again.
            cla.log.info(
                'DocuSign URL used was expired, re-generating sign_url')
            callback_url = signature.get_signature_callback_url()
            get_signing_service().populate_sign_url(signature, callback_url)
            signature.save()
            raise falcon.HTTPFound(signature.get_signature_sign_url())
        if event == 'cancel':
            return canceled_signature_html(signature=signature)
    ret_url = signature.get_signature_return_url()
    if ret_url is not None:
        cla.log.info('%s- Signature success - sending user to return_url: %s',
                     fn, ret_url)
        try:
            project = get_project_instance()
            project.load(str(signature.get_signature_project_id()))
        except DoesNotExist as err:
            cla.log.error('%s - Invalid project_id provided when trying to send user back to'\
                        'their return_url : %s', fn, signature.get_signature_project_id())

        if project.get_version() == 'v2':
            if signature.get_signature_reference_type() == 'company':
                cla.log.info('%s - Getting company instance : %s ', fn,
                             signature.get_signature_reference_id())
                try:
                    company = get_company_instance()
                    company.load(str(signature.get_signature_reference_id()))
                except DoesNotExist as err:
                    cla.log.error('%s - Invalid company_id provided : err: %s',
                                  fn, signature.get_signature_reference_id)
                user_service = UserService
                cla.log.info(
                    '%s - Checking if cla managers have cla-manager role permission',
                    fn)
                num_tries = 10
                i = 1
                cla.log.info(
                    f'{fn} - checking if managers:{signature.get_signature_acl()} have roles with {num_tries} tries'
                )
                while i <= num_tries:
                    cla.log.info(f'{fn} - check try #: {i}')
                    assigned = {}
                    for manager in signature.get_signature_acl():
                        cla.log.info(
                            f'{fn}- Checking {manager} for {CLA_MANAGER_ROLE} for company: {company.get_company_external_id()}, cla_group_id: {signature.get_signature_project_id()}'
                        )
                        assigned[manager] = user_service.has_role(
                            manager, CLA_MANAGER_ROLE,
                            company.get_company_external_id(),
                            signature.get_signature_project_id())
                    cla.log.info(f'{fn} - Assigned status : {assigned}')
                    #Ensure that assigned list doesnt have any False values -> All Managers have role assigned
                    if all(list(assigned.values())):
                        cla.log.info(
                            f'All managers have cla-manager role for company: {company.get_company_external_id()} and cla_group_id: {signature.get_signature_project_id()}'
                        )
                        break
                    time.sleep(0.5)
                    i += 1

        raise falcon.HTTPFound(ret_url)
    cla.log.info('No return_url set for signature - returning success message')
    return {'success': 'Thank you for signing'}