def test_is_whitelisted_for_github_org(self) -> None: """ Test given github user passes github org check against ccla_signature """ self.mock_get.return_value.ok = True github_orgs = [{ 'login': '******', }] self.mock_get.return_value = Mock() self.mock_get.return_value.json.return_value = github_orgs signature = Signature() signature.get_github_org_whitelist = Mock(return_value=['foo-org']) self.assertTrue(utils.is_whitelisted(signature, github_username='******'))
def notify_whitelist_change(auth_user, old_signature: Signature, new_signature: Signature): company_name = new_signature.get_signature_reference_name() project = cla.utils.get_project_instance() project.load(new_signature.get_signature_project_id()) project_name = project.get_project_name() changes = [] domain_msg_added = 'The domain {} was added to the domain approval list.' domain_msg_deleted = 'The domain {} was removed from the domain approval list.' domain_changes, _, _ = change_in_list( old_list=old_signature.get_domain_whitelist(), new_list=new_signature.get_domain_whitelist(), msg_added=domain_msg_added, msg_deleted=domain_msg_deleted) changes = changes + domain_changes email_msg_added = 'The email address {} was added to the email approval list.' email_msg_deleted = 'The email address {} was removed from the email approval list.' email_changes, email_added, email_deleted = change_in_list( old_list=old_signature.get_email_whitelist(), new_list=new_signature.get_email_whitelist(), msg_added=email_msg_added, msg_deleted=email_msg_deleted) changes = changes + email_changes github_msg_added = 'The GitHub user {} was added to the GitHub approval list.' github_msg_deleted = 'The GitHub user {} was removed from the github approval list.' github_changes, github_added, github_deleted = change_in_list( old_list=old_signature.get_github_whitelist(), new_list=new_signature.get_github_whitelist(), msg_added=github_msg_added, msg_deleted=github_msg_deleted) changes = changes + github_changes github_org_msg_added = 'The GitHub organization {} was added to the GitHub organization approval list.' github_org_msg_deleted = 'The GitHub organization {} was removed from the GitHub organization approval list.' github_org_changes, _, _ = change_in_list( old_list=old_signature.get_github_org_whitelist(), new_list=new_signature.get_github_org_whitelist(), msg_added=github_org_msg_added, msg_deleted=github_org_msg_deleted) changes = changes + github_org_changes if len(changes) > 0: # send email to cla managers about change cla_managers = new_signature.get_managers() subject, body, recipients = approval_list_change_email_content( project, company_name, project_name, cla_managers, changes) if len(recipients) > 0: get_email_service().send(subject, body, recipients) cla_manager_name = auth_user.name # send email to contributors notify_whitelist_change_to_contributors( project=project, email_added=email_added, email_removed=email_deleted, github_users_added=github_added, github_users_removed=github_deleted, company_name=company_name, project_name=project_name, cla_manager_name=cla_manager_name) event_data = " ,".join(changes) Event.create_event( event_data=event_data, event_summary=event_data, event_type=EventType.NotifyWLChange, event_company_name=company_name, event_project_name=project_name, contains_pii=True, )