def user_icla_check(user: User, project_id: str, signature: Signature, latest_major_version=True) -> bool: cla.log.debug(f'ICLA signature found for user: {user} on project: {project_id}, ' f'signature_id: {signature.get_signature_id()}') # Here's our logic to determine if the signature is valid if latest_major_version: # Ensure it's latest signature. project = get_project_instance() project.load(str(project_id)) document_models = project.get_project_individual_documents() major, _ = get_last_version(document_models) if signature.get_signature_document_major_version() != major: cla.log.debug(f'User: {user} only has an old document version signed ' f'(v{signature.get_signature_document_major_version()}) - needs a new version') return False if signature.get_signature_signed() and signature.get_signature_approved(): # Signature found and signed/approved. cla.log.debug(f'User: {user} has ICLA signed and approved signature_id: {signature.get_signature_id()} ' f'for project: {project_id}') return True elif signature.get_signature_signed(): # Not approved yet. cla.log.debug(f'User: {user} has ICLA signed with signature_id: {signature.get_signature_id()}, ' f'project: {project_id}, but has not been approved yet') return False else: # Not signed or approved yet. cla.log.debug(f'User: {user} has ICLA with signature_id: {signature.get_signature_id()}, ' f'project: {project_id}, but has not been signed or approved yet') return False
def create_bot_signature(bot_user: User, signature: Signature) -> Optional[Signature]: cla.log.debug(f'create_bot_signature - locating Bot Signature for: {bot_user.get_user_name()}...') project: Project = cla.utils.get_project_instance() try: project.load(signature.get_signature_project_id()) except DoesNotExist as err: cla.log.warning(f'create_bot_signature - unable to load project by id: {signature.get_signature_project_id()}' f' Unable to create bot: {bot_user}') return None the_company: Company = cla.utils.get_company_instance() try: the_company.load(signature.get_signature_reference_id()) except DoesNotExist as err: cla.log.warning(f'create_bot_signature - unable to load company by id: {signature.get_signature_reference_id()}' f' Unable to create bot: {bot_user}') return None bot_sig: Signature = cla.utils.get_signature_instance() # First, before we create a new one, grab a list of employee signatures for this company/project existing_sigs: List[Signature] = bot_sig.get_employee_signatures_by_company_project_model( company_id=bot_user.get_user_company_id(), project_id=signature.get_signature_project_id()) # Check to see if we have an existing signature for this user/company/project combo for sig in existing_sigs: if sig.get_signature_reference_id() == bot_user.get_user_id(): cla.log.debug('create_bot_signature - found existing bot signature ' f'for user: {bot_user} ' f'with company: {the_company} ' f'for project: {project}') return sig # Didn't find an existing signature, let's create a new one cla.log.debug(f'create_bot_signature - creating Bot Signature: {bot_user.get_user_name()}...') bot_sig.set_signature_id(str(uuid.uuid4())) bot_sig.set_signature_project_id(signature.get_signature_project_id()) bot_sig.set_signature_reference_id(bot_user.get_user_id()) bot_sig.set_signature_document_major_version(signature.get_signature_document_major_version()) bot_sig.set_signature_document_minor_version(signature.get_signature_document_minor_version()) bot_sig.set_signature_approved(True) bot_sig.set_signature_signed(True) bot_sig.set_signature_type('cla') bot_sig.set_signature_reference_type('user') bot_sig.set_signature_user_ccla_company_id(bot_user.get_user_company_id()) bot_sig.set_note(f'{datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")} Added as part of ' f'{project.get_project_name()}, approval list by ' f'{the_company.get_company_name()}') bot_sig.save() cla.log.debug(f'create_bot_signature - created Bot Signature: {bot_sig}') return bot_sig