コード例 #1
0
ファイル: test_docusign_models.py プロジェクト: geva/easycla
def test_populate_signature_from_icla_callback():
    tree = ET.fromstring(content_icla_agreement_date)

    agreement_date = "2020-12-21T08:29:20.51"

    signature = Signature()
    populate_signature_from_icla_callback(content_icla_agreement_date, tree,
                                          signature)
    assert signature.get_user_docusign_name() == "Example FullName"
    assert signature.get_user_docusign_date_signed() == agreement_date
    assert signature.get_user_docusign_raw_xml() == content_icla_agreement_date
    assert "user_docusign_name" in signature.to_dict(), ""
    assert "user_docusign_date_signed" in signature.to_dict()
    assert "user_docusign_raw_xml" not in signature.to_dict()
    assert "user_docusign_name" in str(signature)
    assert "user_docusign_date_signed" in str(signature)
    assert "user_docusign_raw_xml" not in str(signature)
コード例 #2
0
ファイル: signature.py プロジェクト: geva/easycla
def get_signature(signature_id):
    """
    Returns the CLA signature requested by UUID.

    :param signature_id: The signature UUID.
    :type signature_id: UUID
    :return: dict representation of the signature object.
    :rtype: dict
    """
    signature = Signature()
    try:
        signature.load(signature_id=str(signature_id))
    except DoesNotExist as err:
        return {'errors': {'signature_id': str(err)}}
    return signature.to_dict()
コード例 #3
0
ファイル: signature.py プロジェクト: geva/easycla
def update_signature(
        signature_id,  # pylint: disable=too-many-arguments,too-many-return-statements,too-many-branches
        auth_user,
        signature_project_id=None,
        signature_reference_id=None,
        signature_reference_type=None,
        signature_type=None,
        signature_approved=None,
        signature_signed=None,
        signature_return_url=None,
        signature_sign_url=None,
        domain_whitelist=None,
        email_whitelist=None,
        github_whitelist=None,
        github_org_whitelist=None):
    """
    Updates an signature and returns the newly updated signature in dict format.
    A value of None means the field should not be updated.

    :param signature_id: ID of the signature.
    :type signature_id: ID | None
    :param auth_user: the authenticated user
    :type auth_user: string
    :param signature_project_id: Project ID for this signature.
    :type signature_project_id: string | None
    :param signature_reference_id: Reference ID for this signature.
    :type signature_reference_id: string | None
    :param signature_reference_type: Reference type for this signature.
    :type signature_reference_type: ['user' | 'company'] | None
    :param signature_type: New signature type ('cla' or 'dco').
    :type signature_type: string | None
    :param signature_signed: Whether this signature is signed or not.
    :type signature_signed: boolean | None
    :param signature_approved: Whether this signature is approved or not.
    :type signature_approved: boolean | None
    :param signature_return_url: The URL the user will be sent to after signing.
    :type signature_return_url: string | None
    :param signature_sign_url: The URL the user must visit to sign the signature.
    :type signature_sign_url: string | None
    :param domain_whitelist:  the domain whitelist
    :param email_whitelist:  the email whitelist
    :param github_whitelist:  the github username whitelist
    :param github_org_whitelist:  the github org whitelist
    :return: dict representation of the signature object.
    :rtype: dict
    """
    fn = 'controllers.signature.update_signature'
    cla.log.debug(f'{fn} - loading signature by id: {str(signature_id)}')
    signature = Signature()
    try:  # Try to load the signature to update.
        signature.load(str(signature_id))
        old_signature = copy.deepcopy(signature)
    except DoesNotExist as err:
        return {'errors': {'signature_id': str(err)}}
    update_str = f'signature {signature_id} updates: \n '
    if signature_project_id is not None:
        # make a note if the project id is set and doesn't match
        if signature.get_signature_project_id() != str(signature_project_id):
            cla.log.warning(
                f'{fn} - project IDs do not match => '
                f'record project id: {signature.get_signature_project_id()} != '
                f'parameter project id: {str(signature_project_id)}')
        try:
            signature.set_signature_project_id(str(signature_project_id))
            update_str += f'signature_project_id updated to {signature_project_id} \n'
        except DoesNotExist as err:
            return {'errors': {'signature_project_id': str(err)}}
    # TODO: Ensure signature_reference_id exists.
    if signature_reference_id is not None:
        if signature.get_signature_reference_id() != str(
                signature_reference_id):
            cla.log.warning(
                f'{fn} - signature reference IDs do not match => '
                f'record signature ref id: {signature.get_signature_reference_id()} != '
                f'parameter signature ref id: {str(signature_reference_id)}')
        signature.set_signature_reference_id(signature_reference_id)
    if signature_reference_type is not None:
        signature.set_signature_reference_type(signature_reference_type)
        update_str += f'signature_reference_type updated to {signature_reference_type} \n'
    if signature_type is not None:
        if signature_type in ['cla', 'dco']:
            signature.set_signature_type(signature_type)
            update_str += f'signature_type updated to {signature_type} \n'
        else:
            return {
                'errors': {
                    'signature_type':
                    'Invalid value passed. The accepted values are: (cla|dco)'
                }
            }
    if signature_signed is not None:
        try:
            val = hug.types.smart_boolean(signature_signed)
            signature.set_signature_signed(val)
            update_str += f'signature_signed updated to {signature_signed} \n'
        except KeyError:
            return {
                'errors': {
                    'signature_signed':
                    'Invalid value passed in for true/false field'
                }
            }
    if signature_approved is not None:
        try:
            val = hug.types.smart_boolean(signature_approved)
            update_signature_approved(signature, val)
            update_str += f'signature_approved updated to {val} \n'
        except KeyError:
            return {
                'errors': {
                    'signature_approved':
                    'Invalid value passed in for true/false field'
                }
            }
    if signature_return_url is not None:
        try:
            val = cla.hug_types.url(signature_return_url)
            signature.set_signature_return_url(val)
            update_str += f'signature_return_url updated to {val} \n'
        except KeyError:
            return {
                'errors': {
                    'signature_return_url':
                    'Invalid value passed in for URL field'
                }
            }
    if signature_sign_url is not None:
        try:
            val = cla.hug_types.url(signature_sign_url)
            signature.set_signature_sign_url(val)
            update_str += f'signature_sign_url updated to {val} \n'
        except KeyError:
            return {
                'errors': {
                    'signature_sign_url':
                    'Invalid value passed in for URL field'
                }
            }

    if domain_whitelist is not None:
        try:
            domain_whitelist = hug.types.multiple(domain_whitelist)
            signature.set_domain_whitelist(domain_whitelist)
            update_str += f'domain_whitelist updated to {domain_whitelist} \n'
        except KeyError:
            return {
                'errors': {
                    'domain_whitelist':
                    'Invalid value passed in for the domain whitelist'
                }
            }

    if email_whitelist is not None:
        try:
            email_whitelist = hug.types.multiple(email_whitelist)
            signature.set_email_whitelist(email_whitelist)
            update_str += f'email_whitelist updated to {email_whitelist} \n'
        except KeyError:
            return {
                'errors': {
                    'email_whitelist':
                    'Invalid value passed in for the email whitelist'
                }
            }

    if github_whitelist is not None:
        try:
            github_whitelist = hug.types.multiple(github_whitelist)
            signature.set_github_whitelist(github_whitelist)

            # A little bit of special logic to for GitHub whitelists that have bots
            bot_list = [
                github_user for github_user in github_whitelist
                if is_github_bot(github_user)
            ]
            if bot_list is not None:
                handle_bots(bot_list, signature)
            update_str += f'github_whitelist updated to {github_whitelist} \n'
        except KeyError:
            return {
                'errors': {
                    'github_whitelist':
                    'Invalid value passed in for the github whitelist'
                }
            }

    if github_org_whitelist is not None:
        try:
            github_org_whitelist = hug.types.multiple(github_org_whitelist)
            signature.set_github_org_whitelist(github_org_whitelist)
            update_str += f'github_org_whitelist updated to {github_org_whitelist} \n'
        except KeyError:
            return {
                'errors': {
                    'github_org_whitelist':
                    'Invalid value passed in for the github org whitelist'
                }
            }

    event_data = update_str
    Event.create_event(
        event_data=event_data,
        event_summary=event_data,
        event_type=EventType.UpdateSignature,
        contains_pii=True,
    )

    signature.save()
    notify_whitelist_change(auth_user=auth_user,
                            old_signature=old_signature,
                            new_signature=signature)
    return signature.to_dict()
コード例 #4
0
ファイル: test_docusign_models.py プロジェクト: geva/easycla
def test_populate_signature_from_ccla_callback():
    content = """<?xml version="1.0" encoding="utf-8"?>
<DocuSignEnvelopeInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xmlns="http://www.docusign.net/API/3.0">
    <EnvelopeStatus>
        <RecipientStatuses>
            <RecipientStatus>
                <Type>Signer</Type>
                <Email>[email protected]</Email>
                <UserName>Example Username</UserName>
                <RoutingOrder>1</RoutingOrder>
                <Sent>2020-12-17T07:43:56.203</Sent>
                <Delivered>2020-12-17T07:44:08.52</Delivered>
                <Signed>2020-12-17T07:44:30.673</Signed>
                <DeclineReason xsi:nil="true"/>
                <Status>Completed</Status>
                <RecipientIPAddress>108.168.239.94</RecipientIPAddress>
                <ClientUserId>74dd08c2-9c4b-41ee-b65f-cf243abf65e6</ClientUserId>
                <CustomFields/>
                <TabStatuses>
                    <TabStatus>
                        <TabType>Custom</TabType>
                        <Status>Signed</Status>
                        <XPosition>304</XPosition>
                        <YPosition>170</YPosition>
                        <TabLabel>signatory_name</TabLabel>
                        <TabName>Signatory Name</TabName>
                        <TabValue>Example Signatory</TabValue>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                        <OriginalValue>Example Signatory</OriginalValue>
                        <CustomTabType>Text</CustomTabType>
                    </TabStatus>
                    <TabStatus>
                        <TabType>Custom</TabType>
                        <Status>Signed</Status>
                        <XPosition>304</XPosition>
                        <YPosition>229</YPosition>
                        <TabLabel>signatory_email</TabLabel>
                        <TabName>Signatory E-mail</TabName>
                        <TabValue>[email protected]</TabValue>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                        <OriginalValue>[email protected]</OriginalValue>
                        <CustomTabType>Text</CustomTabType>
                    </TabStatus>
                    <TabStatus>
                        <TabType>Custom</TabType>
                        <Status>Signed</Status>
                        <XPosition>320</XPosition>
                        <YPosition>343</YPosition>
                        <TabLabel>corporation_name</TabLabel>
                        <TabName>Corporation Name</TabName>
                        <TabValue>The Linux Foundation</TabValue>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                        <OriginalValue>The Linux Foundation</OriginalValue>
                        <CustomTabType>Text</CustomTabType>
                    </TabStatus>
                    <TabStatus>
                        <TabType>Custom</TabType>
                        <Status>Signed</Status>
                        <XPosition>412</XPosition>
                        <YPosition>575</YPosition>
                        <TabLabel>cla_manager_name</TabLabel>
                        <TabName>Initial CLA Manager Name</TabName>
                        <TabValue>Example Signatory</TabValue>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                        <OriginalValue>Example Signatory</OriginalValue>
                        <CustomTabType>Text</CustomTabType>
                    </TabStatus>
                    <TabStatus>
                        <TabType>Custom</TabType>
                        <Status>Signed</Status>
                        <XPosition>412</XPosition>
                        <YPosition>631</YPosition>
                        <TabLabel>cla_manager_email</TabLabel>
                        <TabName>Initial CLA Manager Email</TabName>
                        <TabValue>[email protected]</TabValue>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                        <OriginalValue>[email protected]</OriginalValue>
                        <CustomTabType>Text</CustomTabType>
                    </TabStatus>
                    <TabStatus>
                        <TabType>SignHere</TabType>
                        <Status>Signed</Status>
                        <XPosition>264</XPosition>
                        <YPosition>22</YPosition>
                        <TabLabel>sign</TabLabel>
                        <TabName>Please Sign</TabName>
                        <TabValue/>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                    </TabStatus>
                    <TabStatus>
                        <TabType>Custom</TabType>
                        <Status>Signed</Status>
                        <XPosition>304</XPosition>
                        <YPosition>285</YPosition>
                        <TabLabel>signatory_title</TabLabel>
                        <TabName>Signatory Title</TabName>
                        <TabValue>CEO</TabValue>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                        <CustomTabType>Text</CustomTabType>
                    </TabStatus>
                    <TabStatus>
                        <TabType>Custom</TabType>
                        <Status>Signed</Status>
                        <XPosition>327</XPosition>
                        <YPosition>397</YPosition>
                        <TabLabel>corporation_address1</TabLabel>
                        <TabName>Corporation Address1</TabName>
                        <TabValue>113</TabValue>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                        <CustomTabType>Text</CustomTabType>
                    </TabStatus>
                    <TabStatus>
                        <TabType>Custom</TabType>
                        <Status>Signed</Status>
                        <XPosition>116</XPosition>
                        <YPosition>452</YPosition>
                        <TabLabel>corporation_address2</TabLabel>
                        <TabName>Corporation Address2</TabName>
                        <TabValue>adsfasdf</TabValue>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                        <CustomTabType>Text</CustomTabType>
                    </TabStatus>
                    <TabStatus>
                        <TabType>Custom</TabType>
                        <Status>Signed</Status>
                        <XPosition>116</XPosition>
                        <YPosition>512</YPosition>
                        <TabLabel>corporation_address3</TabLabel>
                        <TabName>Corporation Address3</TabName>
                        <TabValue>asdfadf</TabValue>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                        <CustomTabType>Text</CustomTabType>
                    </TabStatus>
                    <TabStatus>
                        <TabType>DateSigned</TabType>
                        <Status>Signed</Status>
                        <XPosition>735</XPosition>
                        <YPosition>110</YPosition>
                        <TabLabel>date</TabLabel>
                        <TabName>Date</TabName>
                        <TabValue>12/17/2020</TabValue>
                        <DocumentID>47977</DocumentID>
                        <PageNumber>3</PageNumber>
                    </TabStatus>
                </TabStatuses>
                <RecipientAttachment>
                    <Attachment>
                        <Data>redacted by example as it looks to be a base64 encoded string</Data>
                        <Label>DSXForm</Label>
                    </Attachment>
                </RecipientAttachment>
                <AccountStatus>Active</AccountStatus>
                <EsignAgreementInformation>
                    <AccountEsignId>f78e337a-a9c7-47e6-bc20-6f75a84706ba</AccountEsignId>
                    <UserEsignId>d8b49626-cf1d-41dc-bc3f-9478a57036ff</UserEsignId>
                    <AgreementDate>2020-12-17T07:44:08.503</AgreementDate>
                </EsignAgreementInformation>
                <FormData>
                    <xfdf>
                        <fields>
                            <field name="signatory_name">
                                <value>Example Signatory</value>
                            </field>
                            <field name="signatory_email">
                                <value>[email protected]</value>
                            </field>
                            <field name="corporation_name">
                                <value>The Linux Foundation</value>
                            </field>
                            <field name="cla_manager_name">
                                <value>Example Signatory</value>
                            </field>
                            <field name="cla_manager_email">
                                <value>[email protected]</value>
                            </field>
                            <field name="signatory_title">
                                <value>CEO</value>
                            </field>
                            <field name="corporation_address1">
                                <value>113</value>
                            </field>
                            <field name="corporation_address2">
                                <value>adsfasdf</value>
                            </field>
                            <field name="corporation_address3">
                                <value>asdfadf</value>
                            </field>
                            <field name="DateSigned">
                                <value>12/17/2020</value>
                            </field>
                        </fields>
                    </xfdf>
                </FormData>
                <RecipientId>dac1279d-7cc7-4a34-84ae-be0bff04af9b</RecipientId>
            </RecipientStatus>
        </RecipientStatuses>
        <TimeGenerated>2020-12-17T07:44:53.0177631</TimeGenerated>
        <EnvelopeID>c915984a-f761-4c28-ac2c-767253ba3362</EnvelopeID>
        <Subject>EasyCLA: CLA Signature Request for CommonTraceFormat</Subject>
        <UserName>Example Signatory</UserName>
        <Email>[email protected]</Email>
        <Status>Completed</Status>
        <Created>2020-12-17T07:43:55.687</Created>
        <Sent>2020-12-17T07:43:56.233</Sent>
        <Delivered>2020-12-17T07:44:08.707</Delivered>
        <Signed>2020-12-17T07:44:30.673</Signed>
        <Completed>2020-12-17T07:44:30.673</Completed>
        <ACStatus>Original</ACStatus>
        <ACStatusDate>2020-12-17T07:43:55.687</ACStatusDate>
        <ACHolder>Example Signatory</ACHolder>
        <ACHolderEmail>[email protected]</ACHolderEmail>
        <ACHolderLocation>DocuSign</ACHolderLocation>
        <SigningLocation>Online</SigningLocation>
        <SenderIPAddress>3.237.106.64</SenderIPAddress>
        <EnvelopePDFHash/>
        <CustomFields>
            <CustomField>
                <Name>AccountId</Name>
                <Show>false</Show>
                <Required>false</Required>
                <Value>10406522</Value>
                <CustomFieldType>Text</CustomFieldType>
            </CustomField>
            <CustomField>
                <Name>AccountName</Name>
                <Show>false</Show>
                <Required>false</Required>
                <Value>Linux Foundation</Value>
                <CustomFieldType>Text</CustomFieldType>
            </CustomField>
            <CustomField>
                <Name>AccountSite</Name>
                <Show>false</Show>
                <Required>false</Required>
                <Value>demo</Value>
                <CustomFieldType>Text</CustomFieldType>
            </CustomField>
        </CustomFields>
        <AutoNavigation>true</AutoNavigation>
        <EnvelopeIdStamping>true</EnvelopeIdStamping>
        <AuthoritativeCopy>false</AuthoritativeCopy>
        <DocumentStatuses>
            <DocumentStatus>
                <ID>47977</ID>
                <Name>Apache Style</Name>
                <TemplateName/>
                <Sequence>1</Sequence>
            </DocumentStatus>
        </DocumentStatuses>
    </EnvelopeStatus>
    <TimeZone>Pacific Standard Time</TimeZone>
    <TimeZoneOffset>-8</TimeZoneOffset>
</DocuSignEnvelopeInformation> 
    """
    tree = ET.fromstring(content)

    signature = Signature()
    populate_signature_from_ccla_callback(content, tree, signature)
    assert signature.get_user_docusign_name() == "Example Signatory"
    assert signature.get_user_docusign_date_signed(
    ) == "2020-12-17T07:44:08.503"
    assert signature.get_user_docusign_raw_xml() == content
    assert signature.get_signing_entity_name() == "The Linux Foundation"
    assert "user_docusign_name" in signature.to_dict()
    assert "signing_entity_name" in signature.to_dict()
    assert "user_docusign_date_signed" in signature.to_dict()
    assert "user_docusign_raw_xml" not in signature.to_dict()
    assert "user_docusign_name" in str(signature)
    assert "user_docusign_date_signed" in str(signature)
    assert "user_docusign_raw_xml" not in str(signature)
コード例 #5
0
def update_signature(
        signature_id,  # pylint: disable=too-many-arguments,too-many-return-statements,too-many-branches
        signature_project_id=None,
        signature_reference_id=None,
        signature_reference_type=None,
        signature_type=None,
        signature_approved=None,
        signature_signed=None,
        signature_return_url=None,
        signature_sign_url=None,
        domain_whitelist=None,
        email_whitelist=None,
        github_whitelist=None,
        github_org_whitelist=None):
    """
    Updates an signature and returns the newly updated signature in dict format.
    A value of None means the field should not be updated.

    :param signature_id: ID of the signature.
    :type signature_id: ID | None
    :param signature_project_id: Project ID for this signature.
    :type signature_project_id: string | None
    :param signature_reference_id: Reference ID for this signature.
    :type signature_reference_id: string | None
    :param signature_reference_type: Reference type for this signature.
    :type signature_reference_type: ['user' | 'company'] | None
    :param signature_type: New signature type ('cla' or 'dco').
    :type signature_type: string | None
    :param signature_signed: Whether this signature is signed or not.
    :type signature_signed: boolean | None
    :param signature_approved: Whether this signature is approved or not.
    :type signature_approved: boolean | None
    :param signature_return_url: The URL the user will be sent to after signing.
    :type signature_return_url: string | None
    :param signature_sign_url: The URL the user must visit to sign the signature.
    :type signature_sign_url: string | None
    :param domain_whitelist:  the domain whitelist
    :param email_whitelist:  the email whitelist
    :param github_whitelist:  the github username whitelist
    :param github_org_whitelist:  the github org whitelist
    :return: dict representation of the signature object.
    :rtype: dict
    """
    signature = Signature()
    try:  # Try to load the signature to update.
        signature.load(str(signature_id))
    except DoesNotExist as err:
        return {'errors': {'signature_id': str(err)}}
    if signature_project_id is not None:
        # make a note if the project id is set and doesn't match
        if signature.get_signature_project_id() != str(signature_project_id):
            cla.log.warning(
                'update_signature() - project IDs do not match => '
                f'record project id: {signature.get_signature_project_id()} != '
                f'parameter project id: {str(signature_project_id)}')
        try:
            signature.set_signature_project_id(str(signature_project_id))
        except DoesNotExist as err:
            return {'errors': {'signature_project_id': str(err)}}
    # TODO: Ensure signature_reference_id exists.
    if signature_reference_id is not None:
        if signature.get_signature_reference_id() != str(
                signature_reference_id):
            cla.log.warning(
                'update_signature() - signature reference IDs do not match => '
                f'record signature ref id: {signature.get_signature_reference_id()} != '
                f'parameter signature ref id: {str(signature_reference_id)}')
        signature.set_signature_reference_id(signature_reference_id)
    if signature_reference_type is not None:
        signature.set_signature_reference_type(signature_reference_type)
    if signature_type is not None:
        if signature_type in ['cla', 'dco']:
            signature.set_signature_type(signature_type)
        else:
            return {
                'errors': {
                    'signature_type':
                    'Invalid value passed. The accepted values are: (cla|dco)'
                }
            }
    if signature_signed is not None:
        try:
            val = hug.types.smart_boolean(signature_signed)
            signature.set_signature_signed(val)
        except KeyError as err:
            return {
                'errors': {
                    'signature_signed':
                    'Invalid value passed in for true/false field'
                }
            }
    if signature_approved is not None:
        try:
            val = hug.types.smart_boolean(signature_approved)
            update_signature_approved(signature, val)
        except KeyError as err:
            return {
                'errors': {
                    'signature_approved':
                    'Invalid value passed in for true/false field'
                }
            }
    if signature_return_url is not None:
        try:
            val = cla.hug_types.url(signature_return_url)
            signature.set_signature_return_url(val)
        except KeyError as err:
            return {
                'errors': {
                    'signature_return_url':
                    'Invalid value passed in for URL field'
                }
            }
    if signature_sign_url is not None:
        try:
            val = cla.hug_types.url(signature_sign_url)
            signature.set_signature_sign_url(val)
        except KeyError as err:
            return {
                'errors': {
                    'signature_sign_url':
                    'Invalid value passed in for URL field'
                }
            }

    if domain_whitelist is not None:
        try:
            domain_whitelist = hug.types.multiple(domain_whitelist)
            signature.set_domain_whitelist(domain_whitelist)
        except KeyError as err:
            return {
                'errors': {
                    'domain_whitelist':
                    'Invalid value passed in for the domain whitelist'
                }
            }

    if email_whitelist is not None:
        try:
            email_whitelist = hug.types.multiple(email_whitelist)
            signature.set_email_whitelist(email_whitelist)
        except KeyError as err:
            return {
                'errors': {
                    'email_whitelist':
                    'Invalid value passed in for the email whitelist'
                }
            }

    if github_whitelist is not None:
        try:
            github_whitelist = hug.types.multiple(github_whitelist)
            signature.set_github_whitelist(github_whitelist)

            # A little bit of special logic to for GitHub whitelists that have bots
            bot_list = [
                github_user for github_user in github_whitelist
                if is_github_bot(github_user)
            ]
            if bot_list is not None:
                handle_bots(bot_list, signature)
        except KeyError as err:
            return {
                'errors': {
                    'github_whitelist':
                    'Invalid value passed in for the github whitelist'
                }
            }

    if github_org_whitelist is not None:
        try:
            github_org_whitelist = hug.types.multiple(github_org_whitelist)
            signature.set_github_org_whitelist(github_org_whitelist)
        except KeyError as err:
            return {
                'errors': {
                    'github_org_whitelist':
                    'Invalid value passed in for the github org whitelist'
                }
            }

    signature.save()
    return signature.to_dict()
コード例 #6
0
ファイル: signature.py プロジェクト: zaclittleberry/easycla
def create_signature(
        signature_project_id,  # pylint: disable=too-many-arguments
        signature_reference_id,
        signature_reference_type,
        signature_type='cla',
        signature_approved=False,
        signature_signed=False,
        signature_return_url=None,
        signature_sign_url=None,
        signature_user_ccla_company_id=None,
        signature_acl=None):
    """
    Creates an signature and returns the newly created signature in dict format.

    :param signature_project_id: The project ID for this new signature.
    :type signature_project_id: string
    :param signature_reference_id: The user or company ID for this signature.
    :type signature_reference_id: string
    :param signature_reference_type: The type of reference ('user' or 'company')
    :type signature_reference_type: string
    :param signature_type: The signature type ('cla' or 'dco')
    :type signature_type: string
    :param signature_signed: Whether or not the signature has been signed.
    :type signature_signed: boolean
    :param signature_approved: Whether or not the signature has been approved.
    :type signature_approved: boolean
    :param signature_return_url: The URL the user will be redirected to after signing.
    :type signature_return_url: string
    :param signature_sign_url: The URL the user must visit to sign the signature.
    :type signature_sign_url: string
    :param signature_user_ccla_company_id: The company ID if creating an employee signature.
    :type signature_user_ccla_company_id: string
    :return: A dict of a newly created signature.
    :rtype: dict
    """
    signature = Signature()
    signature.set_signature_id(str(uuid.uuid4()))
    project = Project()
    try:
        project.load(project_id=str(signature_project_id))
    except DoesNotExist as err:
        return {'errors': {'signature_project_id': str(err)}}
    signature.set_signature_project_id(str(signature_project_id))
    if signature_reference_type == 'user':
        user = User()
        try:
            user.load(signature_reference_id)
        except DoesNotExist as err:
            return {'errors': {'signature_reference_id': str(err)}}
        try:
            document = project.get_project_individual_document()
        except DoesNotExist as err:
            return {'errors': {'signature_project_id': str(err)}}
    else:
        company = Company()
        try:
            company.load(signature_reference_id)
        except DoesNotExist as err:
            return {'errors': {'signature_reference_id': str(err)}}
        try:
            document = project.get_project_corporate_document()
        except DoesNotExist as err:
            return {'errors': {'signature_project_id': str(err)}}

    # Set username to this signature ACL
    if signature_acl is not None:
        signature.set_signature_acl(signature_acl)

    signature.set_signature_document_minor_version(
        document.get_document_minor_version())
    signature.set_signature_document_major_version(
        document.get_document_major_version())
    signature.set_signature_reference_id(str(signature_reference_id))
    signature.set_signature_reference_type(signature_reference_type)
    signature.set_signature_type(signature_type)
    signature.set_signature_signed(signature_signed)
    signature.set_signature_approved(signature_approved)
    signature.set_signature_return_url(signature_return_url)
    signature.set_signature_sign_url(signature_sign_url)
    if signature_user_ccla_company_id is not None:
        signature.set_signature_user_ccla_company_id(
            str(signature_user_ccla_company_id))
    signature.save()
    return signature.to_dict()
コード例 #7
0
ファイル: signature.py プロジェクト: zaclittleberry/easycla
def update_signature(
        signature_id,  # pylint: disable=too-many-arguments,too-many-return-statements,too-many-branches
        signature_project_id=None,
        signature_reference_id=None,
        signature_reference_type=None,
        signature_type=None,
        signature_approved=None,
        signature_signed=None,
        signature_return_url=None,
        signature_sign_url=None,
        domain_whitelist=None,
        email_whitelist=None,
        github_whitelist=None):
    """
    Updates an signature and returns the newly updated signature in dict format.
    A value of None means the field should not be updated.

    :param signature_id: ID of the signature.
    :type signature_id: ID | None
    :param signature_project_id: Project ID for this signature.
    :type signature_project_id: string | None
    :param signature_reference_id: Reference ID for this signature.
    :type signature_reference_id: string | None
    :param signature_reference_type: Reference type for this signature.
    :type signature_reference_type: ['user' | 'company'] | None
    :param signature_type: New signature type ('cla' or 'dco').
    :type signature_type: string | None
    :param signature_signed: Whether this signature is signed or not.
    :type signature_signed: boolean | None
    :param signature_approved: Whether this signature is approved or not.
    :type signature_approved: boolean | None
    :param signature_return_url: The URL the user will be sent to after signing.
    :type signature_return_url: string | None
    :param signature_sign_url: The URL the user must visit to sign the signature.
    :type signature_sign_url: string | None
    :return: dict representation of the signature object.
    :rtype: dict
    """
    signature = Signature()
    try:  # Try to load the signature to update.
        signature.load(str(signature_id))
    except DoesNotExist as err:
        return {'errors': {'signature_id': str(err)}}
    if signature_project_id is not None:
        try:
            signature.set_signature_project_id(str(signature_project_id))
        except DoesNotExist as err:
            return {'errors': {'signature_project_id': str(err)}}
    # TODO: Ensure signature_reference_id exists.
    if signature_reference_id is not None:
        signature.set_signature_reference_id(signature_reference_id)
    if signature_reference_type is not None:
        signature.set_signature_reference_type(signature_reference_type)
    if signature_type is not None:
        if signature_type in ['cla', 'dco']:
            signature.set_signature_type(signature_type)
        else:
            return {'errors': {'signature_type': \
                               'Invalid value passed. The accepted values are: (cla|dco)'}}
    if signature_signed is not None:
        try:
            val = hug.types.smart_boolean(signature_signed)
            signature.set_signature_signed(val)
        except KeyError as err:
            return {
                'errors': {
                    'signature_signed':
                    'Invalid value passed in for true/false field'
                }
            }
    if signature_approved is not None:
        try:
            val = hug.types.smart_boolean(signature_approved)
            update_signature_approved(signature, val)
        except KeyError as err:
            return {
                'errors': {
                    'signature_approved':
                    'Invalid value passed in for true/false field'
                }
            }
    if signature_return_url is not None:
        try:
            val = cla.hug_types.url(signature_return_url)
            signature.set_signature_return_url(val)
        except KeyError as err:
            return {
                'errors': {
                    'signature_return_url':
                    'Invalid value passed in for URL field'
                }
            }
    if signature_sign_url is not None:
        try:
            val = cla.hug_types.url(signature_sign_url)
            signature.set_signature_sign_url(val)
        except KeyError as err:
            return {
                'errors': {
                    'signature_sign_url':
                    'Invalid value passed in for URL field'
                }
            }

    if domain_whitelist is not None:
        try:
            domain_whitelist = hug.types.multiple(domain_whitelist)
            signature.set_domain_whitelist(domain_whitelist)
        except KeyError as err:
            return {
                'errors': {
                    'domain_whitelist':
                    'Invalid value passed in for the domain whitelist'
                }
            }

    if email_whitelist is not None:
        try:
            email_whitelist = hug.types.multiple(email_whitelist)
            signature.set_email_whitelist(email_whitelist)
        except KeyError as err:
            return {
                'errors': {
                    'email_whitelist':
                    'Invalid value passed in for the email whitelist'
                }
            }

    if github_whitelist is not None:
        try:
            github_whitelist = hug.types.multiple(github_whitelist)
            signature.set_github_whitelist(github_whitelist)
        except KeyError as err:
            return {
                'errors': {
                    'github_whitelist':
                    'Invalid value passed in for the github whitelist'
                }
            }

    signature.save()
    return signature.to_dict()