def update_github_username(github_user: dict, user: User): """ When provided a GitHub user model from the GitHub service, updates the CLA user record with the github username. :param github_user: the github user model as a dict from GitHub :param user: the user DB object :return: None """ # set the github username if available if 'login' in github_user: if user.get_user_github_username() is None: cla.log.debug(f'Updating user record - adding github username: {github_user["login"]}') user.set_user_github_username(github_user['login']) if user.get_user_github_username() != github_user['login']: cla.log.warning(f'Note: github user with id: {github_user["id"]}' f' has a mismatched username (gh: {github_user["id"]} ' f'vs db user record: {user.get_user_github_username}) - ' f'setting the value to: {github_user["login"]}') user.set_user_github_username(github_user['login'])
def request_company_ccla(user_id, user_email, company_id, project_id): """ Sends email to all company administrators in the company ACL to sign a CCLA for the given project. """ user = User() try: user.load(user_id) except DoesNotExist as err: return {'errors': {'user_id': str(err)}} user_name = user.get_user_name() company = Company() try: company.load(company_id) except DoesNotExist as err: return {'errors': {'company_id': str(err)}} company_name = company.get_company_name() project = Project() try: project.load(project_id) except DoesNotExist as err: return {'errors': {'company_id': str(err)}} project_name = project.get_project_name() # Send an email to sign the ccla for the project for every member in the company ACL # account_exists=True since company already exists. for admin in company.get_managers(): send_email_to_cla_manager(project, user_name, user_email, admin.get_user_name(), admin.get_lf_email(), project_name, company_name, True) # Audit event event_data = f'Sent email to sign ccla for {project.get_project_name()}' Event.create_event( event_data=event_data, event_summary=event_data, event_type=EventType.RequestCCLA, event_user_id=user_id, event_company_id=company_id, contains_pii=False, ) msg = (f'user github_id {user.get_user_github_id()}' f'user github_username {user.get_user_github_username()}' f'user email {user_email}' f'for project {project_name}' f'for company {company_name}') cla.log.debug(f'creating CCLA approval request table entry for {msg}') # Add an entry into the CCLA request table ccla_whitelist_request = CCLAWhitelistRequest() ccla_whitelist_request.set_request_id(str(uuid.uuid4())) ccla_whitelist_request.set_company_name(company_name) ccla_whitelist_request.set_project_name(project_name) ccla_whitelist_request.set_user_github_id(user.get_user_github_id()) ccla_whitelist_request.set_user_github_username( user.get_user_github_username()) ccla_whitelist_request.set_user_emails({user_email}) ccla_whitelist_request.set_request_status("pending") ccla_whitelist_request.save() cla.log.debug(f'created CCLA approval request table entry for {msg}')