def get_company(company_id): try: company = Company() company.load(company_id) except DoesNotExist as err: raise DoesNotExist('errors: {company_id: %s}' % str(err)) return company
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. :param signature_acl: a list with the signature access control list values :type signature_acl: list of strings :rtype: dict """ signature: Signature = cla.utils.get_signature_instance() signature.set_signature_id(str(uuid.uuid4())) project: Project = cla.utils.get_project_instance() 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 = cla.utils.get_user_instance() 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 = cla.utils.get_company_instance() 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() event_data = f'Signature added. Signature_id - {signature.get_signature_id()} for Project - {project.get_project_name()}' Event.create_event( event_data=event_data, event_summary=event_data, event_type=EventType.CreateSignature, event_project_id=signature_project_id, contains_pii=False, ) return signature.to_dict()
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()