def test_get_full_sign_url(): p = Project() p.set_version("v1") url = get_full_sign_url("github", "1234", 456, 1, p.get_version()) assert "?version=1" in url p = Project() p.set_version("v2") url = get_full_sign_url("github", "1234", 456, 1, p.get_version()) assert "?version=2" in url p = Project() url = get_full_sign_url("github", "1234", 456, 1, p.get_version()) assert "?version=1" in url
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, )