def test_append_email_help_sign_off_content(): body = "hello John," new_bod = append_email_help_sign_off_content(body, "v2") assert body in new_bod assert get_email_help_content(True) in new_bod assert get_email_sign_off_content() in new_bod new_body_v1 = append_email_help_sign_off_content(body, "v1") assert body in new_body_v1 assert get_email_help_content(False) in new_body_v1 assert get_email_sign_off_content() in new_body_v1
def unable_to_do_cla_check_email_content(project, managers, repositories): """Helper function to get unable to do cla check email subject, body, recipients""" cla_group_name = project.get_project_name() subject = f'EasyCLA: Unable to check GitHub Pull Requests for CLA Group: {cla_group_name}' pronoun = "this repository" if len(repositories) > 1: pronoun = "these repositories" repo_content = "<ul>" for repo in repositories: repo_content += "<li>" + repo + "</li>" repo_content += "</ul>" body = f""" <p>Hello Project Manager,</p> <p>This is a notification email from EasyCLA regarding the CLA Group {cla_group_name}.</p> <p>EasyCLA is unable to check PRs on {pronoun} due to permissions issue.</p> {repo_content} <p>Please contact the repository admin/owner to enable CLA checks.</p> <p>Provide the Owner/Admin the following instructions:</p> <ul> <li>Go into the "Settings" tab of the GitHub Organization</li> <li>Click on "installed GitHub Apps" vertical navigation</li> <li>Then click "Configure" associated with the EasyCLA App</li> <li>Finally, click the "All Repositories" radio button option</li> </ul> """ body = append_email_help_sign_off_content(body, project.get_version()) # body = '<p>' + body.replace('\n', '<br>') + '</p>' recipients = [] for manager in managers: recipients.append(manager["email"]) return subject, body, recipients
def remove_cla_manager_email_content(lfid, project, company, managers): """ Helper function to send email to newly added CLA Manager """ # Get emails of newly added Manager recipients = get_user_emails(lfid) if not recipients: raise Exception('Issue getting emails for lfid : %s', lfid) subject = f'CLA: Access to Corporate CLA for Project {project.get_project_name()}' manager_list = [ '%s <%s>' % (mgr.get('name', ' '), mgr.get('email', ' ')) for mgr in managers ] manager_list_str = '-'.join(manager_list) + '\n' body = f""" <p> Hello {lfid}, </p> \ <p>This is a notification email from EasyCLA regarding the project {project.get_project_name()}.</p> \ <p>You have been removed as a CLA Manager from the project: {project.get_project_name()} for the organization \ {company.get_company_name()} </p> \ <p> If you have further questions, please contact one of the existing CLA Managers: </p> \ {manager_list_str} """ body = '<p>' + body.replace('\n', '<br>') + '</p>' body = append_email_help_sign_off_content(body, project.get_version()) return subject, body, recipients
def get_contributor_whitelist_update_email_content(project, action, company_name, project_name, cla_manager, email): subject = f'EasyCLA: Allow List Update for {project_name}' preposition = 'to' if action == 'deleted': preposition = 'from' body = f""" <p>Hello,</p> \ <p>This is a notification email from EasyCLA regarding the project {project_name}.</p> \ <p>You have been {action} {preposition} the Allow List of {company_name} for {project_name} by \ CLA Manager {cla_manager}. This means that you are now authorized to contribute to {project_name} \ on behalf of {company_name}.</p> \ <p>If you had previously submitted one or more pull requests to {project_name} that had failed, you should \ close and re-open the pull request to force a recheck by the EasyCLA system.</p> """ body = '<p>' + body.replace('\n', '<br>') + '</p>' body = append_email_help_sign_off_content(body, project.get_version()) recipients = [email] return subject, body, recipients
def auto_enabled_repository_email_content(project, managers, organization_name, repositories): """Helper function to update managers about auto-enabling of repositories""" cla_group_name = project.get_project_name() subject = f'EasyCLA: Auto-Enable Repository for CLA Group: {cla_group_name}' repo_pronoun_upper = "Repository" repo_pronoun = "repository" pronoun = "this " + repo_pronoun repo_was_were = repo_pronoun + " was" if len(repositories) > 1: repo_pronoun_upper = "Repositories" repo_pronoun = "repositories" pronoun = "these " + repo_pronoun repo_was_were = repo_pronoun + " were" repo_content = "<ul>" for repo in repositories: repo_content += "<li>" + repo + "<ul>" repo_content += "</ul>" body = f""" <p>Hello Project Manager,</p> <p>This is a notification email from EasyCLA regarding the CLA Group {cla_group_name}.</p> <p>EasyCLA was notified that the following {repo_was_were} added to the {organization_name} GitHub Organization.\ Since auto-enable was configured within EasyCLA for GitHub Organization, the {pronoun} will now start enforcing \ CLA checks.</p> <p>Please verify the repository settings to ensure EasyCLA is a required check for merging Pull Requests. \ See: GitHub Repository -> Settings -> Branches -> Branch Protection Rules -> Add/Edit the default branch, \ and confirm that 'Require status checks to pass before merging' is enabled and that EasyCLA is a required check.\ Additionally, consider selecting the 'Include administrators' option to enforce all configured restrictions for \ contributors, maintainers, and administrators.</p> <p>For more information on how to setup GitHub required checks, please consult the About required status checks\ <a href="https://docs.github.com/en/github/administering-a-repository/about-required-status-checks"> \ in the GitHub Online Help Pages</a>.</p> <p>{repo_pronoun_upper}:</p> {repo_content} """ body = '<p>' + body.replace('\n', '<br>') + '</p>' body = append_email_help_sign_off_content(body, project.get_version()) recipients = [] for manager in managers: recipients.append(manager["email"]) return subject, body, recipients
def approval_list_change_email_content(project, company_name, project_name, cla_managers, changes): """Helper function to get whitelist change email subject, body, recipients""" subject = f'EasyCLA: Allow List Update for {project_name}' # Append suffix / prefix to strings in list changes = ["<li>" + txt + "</li>" for txt in changes] change_string = "<ul>\n" + "\n".join(changes) + "\n</ul>\n" body = f""" <p>Hello,</p> \ <p>This is a notification email from EasyCLA regarding the project {project_name}.</p> \ <p>The EasyCLA approval list for {company_name} for project {project_name} was modified.</p> \ <p>The modification was as follows:</p> \ {change_string} \ <p>Contributors with previously failed pull requests to {project_name} can close \ and re-open the pull request to force a recheck by the EasyCLA system.</p> """ body = append_email_help_sign_off_content(body, project.get_version()) recipients = [] for manager in cla_managers: email = manager.get_user_email() if email is not None: recipients.append(email) return subject, body, recipients
def request_company_whitelist(user_id: str, company_id: str, user_name: str, user_email: str, project_id: str, message: str = None, recipient_name: str = None, recipient_email: str = None): """ Sends email to the specified company manager notifying them that a user has requested to be added to their approval list. :param user_id: The ID of the user requesting to be added to the company's approval list. :type user_id: string :param company_id: The ID of the company that the request is going to. :type company_id: string :param user_name: The name hat this user wants to be approved :type user_name: string :param user_email: The email address that this user wants to be approved. Must exist in the user's list of emails. :type user_email: string :param project_id: The ID of the project that the request is going to. :type project_id: string :param message: A custom message to add to the email sent out to the manager. :type message: string :param recipient_name: An optional recipient name for requesting the company approval list :type recipient_name: string :param recipient_email: An optional recipient email for requesting the company approval list :type recipient_email: string """ if project_id is None: return { 'errors': { 'project_id': 'Project ID is missing from the request' } } if company_id is None: return { 'errors': { 'company_id': 'Company ID is missing from the request' } } if user_id is None: return {'errors': {'user_id': 'User ID is missing from the request'}} if user_name is None: return { 'errors': { 'user_name': 'User Name is missing from the request' } } if user_email is None: return { 'errors': { 'user_email': 'User Email is missing from the request' } } if recipient_name is None: return { 'errors': { 'recipient_name': 'Recipient Name is missing from the request' } } if recipient_email is None: return { 'errors': { 'recipient_email': 'Recipient Email is missing from the request' } } if message is None: return {'errors': {'message': 'Message is missing from the request'}} user = User() try: user.load(user_id) except DoesNotExist as err: return {'errors': {'user_id': str(err)}} if user_email not in user.get_user_emails(): return { 'errors': { 'user_email': 'User\'s email must match one of the user\'s existing emails in their profile' } } company = Company() try: company.load(company_id) except DoesNotExist as err: return {'errors': {'company_id': str(err)}} project = Project() try: project.load(project_id) except DoesNotExist as err: return {'errors': {'project_id': str(err)}} company_name = company.get_company_name() project_name = project.get_project_name() msg = '' if message is not None: msg += f'<p>{user_name} included the following message in the request:</p>' msg += f'<p>{message}</p>' subject = f'EasyCLA: Request to Authorize {user_name} for {project_name}' body = f''' <p>Hello {recipient_name},</p> \ <p>This is a notification email from EasyCLA regarding the project {project_name}.</p> \ <p>{user_name} ({user_email}) has requested to be added to the Approved List as an authorized contributor from \ {company_name} to the project {project_name}. You are receiving this message as a CLA Manager from {company} for \ {project_name}.</p> \ {msg} \ <p>If you want to add them to the Approved List, please \ <a href="https://{cla.conf['CORPORATE_BASE_URL']}#/company/{company_id}" target="_blank">log into the EasyCLA Corporate \ Console</a>, where you can approve this user's request by selecting the 'Manage Approved List' and adding the \ contributor's email, the contributor's entire email domain, their GitHub ID or the entire GitHub Organization for the \ repository. This will permit them to begin contributing to {project_name} on behalf of {company}.</p> \ <p>If you are not certain whether to add them to the Approved List, please reach out to them directly to discuss.</p> ''' body = append_email_help_sign_off_content(body, project.get_version()) cla.log.debug(f'request_company_approval_list - sending email ' f'to recipient {recipient_name}/{recipient_email} ' f'for user {user_name}/{user_email} ' f'for project {project_name} ' f'assigned to company {company_name}') email_service = get_email_service() email_service.send(subject, body, recipient_email) # Create event event_data = ( f'CLA: contributor {user_name} requests to be Approved for the ' f'project: {project_name} ' f'organization: {company_name} ' f'as {user_name} <{user_email}>') Event.create_event( event_user_id=user_id, event_project_id=project_id, event_company_id=company_id, event_type=EventType.RequestCompanyWL, event_data=event_data, event_summary=event_data, contains_pii=True, )