コード例 #1
0
ファイル: github.py プロジェクト: wanyaland/easycla
def notify_project_managers(repositories):
    if repositories is None:
        return

    project_repos = {}
    for ghrepo in repositories:
        project_id = ghrepo.get_repository_project_id()
        if project_id in project_repos:
            project_repos[project_id].append(ghrepo.get_repository_url())
        else:
            project_repos[project_id] = [ghrepo.get_repository_url()]

    for project_id in project_repos:
        managers = cla.controllers.project.get_project_managers("", project_id, enable_auth=False)
        project = get_project_instance()
        try:
            project.load(project_id=str(project_id))
        except DoesNotExist as err:
            cla.log.warning('notify_project_managers - unable to load project (cla_group) by '
                            f'project_id: {project_id}, error: {err}')
            return {'errors': {'project_id': str(err)}}
        repositories = project_repos[project_id]
        subject, body, recipients = unable_to_do_cla_check_email_content(
            project, managers, repositories)
        get_email_service().send(subject, body, recipients)
        cla.log.debug('github.activity - sending unable to perform CLA Check email'
                      f' to managers: {recipients}'
                      f' for project {project} with '
                      f' repositories: {repositories}')
コード例 #2
0
ファイル: github.py プロジェクト: wanyaland/easycla
def notify_project_managers_auto_enabled(organization_name, repositories):
    if repositories is None:
        return

    project_repos = {}
    for repo in repositories:
        project_id = repo.get_repository_project_id()
        if project_id in project_repos:
            project_repos[project_id].append(repo.get_repository_url())
        else:
            project_repos[project_id] = [repo.get_repository_url()]

    for project_id in project_repos:
        managers = cla.controllers.project.get_project_managers("", project_id, enable_auth=False)
        project = get_project_instance()
        try:
            project.load(project_id=str(project_id))
        except DoesNotExist as err:
            cla.log.warning('notify_project_managers_auto_enabled - unable to load project (cla_group) by '
                            f'project_id: {project_id}, error: {err}')
            return {'errors': {'project_id': str(err)}}

        repositories = project_repos[project_id]
        subject, body, recipients = auto_enabled_repository_email_content(
            project, managers, organization_name, repositories)
        get_email_service().send(subject, body, recipients)
        cla.log.debug('notify_project_managers_auto_enabled - sending auto-enable email '
                      f' to managers: {recipients}'
                      f' for project {project} for '
                      f' GitHub Organization {organization_name} with '
                      f' repositories: {repositories}')
コード例 #3
0
def add_cla_manager(auth_user, signature_id, lfid):
    """
    Adds the LFID to the signature ACL and returns a new list of CLA Managers.

    :param username: username of the user
    :type username: string
    :param signature_id: The ID of the project
    :type signature_id: UUID
    :param lfid: the lfid (manager username) to be added to the project acl
    :type lfid: string
    """

    # Find project
    signature = Signature()
    try:
        signature.load(str(signature_id))
    except DoesNotExist as err:
        return {'errors': {'project_id': str(err)}}

    # Get Signature ACL
    signature_acl = signature.get_signature_acl()

    if auth_user.username not in signature_acl:
        return {'errors': {'user_id': 'You are not authorized to see the managers.'}}

    company.add_permission(auth_user, lfid, signature.get_signature_reference_id(), ignore_auth_user=True)
    # Get Company and Project instances
    try:
        project = get_project(signature.get_signature_project_id())
    except DoesNotExist as err:
        return err
    try:
        company_instance = get_company(signature.get_signature_reference_id())
    except DoesNotExist as err:
        return err

    # get cla managers for email content
    managers = get_cla_managers(auth_user.username, signature_id)

    # Add lfid to acl
    signature.add_signature_acl(lfid)
    signature.save()

    # send email to newly added CLA manager
    try:
        subject, body, recipients = add_cla_manager_email_content(lfid, project, company_instance, managers)
        get_email_service().send(subject, body, recipients)
    except Exception as err:
        return {'errors': {'Failed to send email for lfid: %s , %s ' % (lfid, err)}}

    event_data = f'{lfid} added as cla manager to Signature ACL for {signature.get_signature_id()}'
    Event.create_event(
        event_data=event_data,
        event_summary=event_data,
        event_type=EventType.AddCLAManager,
        contains_pii=True,
    )

    return get_managers_dict(signature_acl)
コード例 #4
0
def update_signature_approved(signature, value):
    """Helper function to update the signature approval status and send emails if necessary."""
    previous = signature.get_signature_approved()
    signature.set_signature_approved(value)
    email_approval = cla.conf['EMAIL_ON_SIGNATURE_APPROVED']
    if email_approval and not previous and value:  # Just got approved.
        subject, body, recipients = get_signature_approved_email_content(signature)
        get_email_service().send(subject, body, recipients)
コード例 #5
0
ファイル: signature.py プロジェクト: AkivaGubbay/easycla
def notify_whitelist_change_to_contributors(email_added, email_removed,
                                            github_users_added,
                                            github_users_removed, company_name,
                                            project_name, cla_manager_name):
    for email in email_added:
        subject, body, recipients = get_contributor_whitelist_update_email_content(
            'added', company_name, project_name, cla_manager_name, email)
        get_email_service().send(subject, body, recipients)
    for email in email_removed:
        subject, body, recipients = get_contributor_whitelist_update_email_content(
            'deleted', company_name, project_name, cla_manager_name, email)
        get_email_service().send(subject, body, recipients)
    for github_username in github_users_added:
        user = cla.utils.get_user_instance()
        users = user.get_user_by_github_username(github_username)
        if users is not None:
            user = users[0]
            email = user.get_user_email()
            subject, body, recipients = get_contributor_whitelist_update_email_content(
                'added', company_name, project_name, cla_manager_name, email)
            get_email_service().send(subject, body, recipients)
    for github_username in github_users_removed:
        user = cla.utils.get_user_instance()
        users = user.get_user_by_github_username(github_username)
        if users is not None:
            user = users[0]
            email = user.get_user_email()
            subject, body, recipients = get_contributor_whitelist_update_email_content(
                'deleted', company_name, project_name, cla_manager_name, email)
            get_email_service().send(subject, body, recipients)
コード例 #6
0
ファイル: github.py プロジェクト: wanyaland/easycla
def webhook_secret_failed_email(event_type: str, req_body: dict, maintainers: List[str]):
    """
    sends the notification email for the failing webhook secret validation
    :param event_type:
    :param req_body:
    :param maintainers:
    :return:
    """
    if maintainers is None or type(maintainers) is not list:
        cla.log.warning(f'webhook_secret_failed_email - unable to emails - no maintainers defined.')
        return

    subject, body, maintainers = webhook_secret_failed_email_content(event_type, req_body, maintainers)
    get_email_service().send(subject, body, maintainers)
    cla.log.debug('webhook_secret_failed_email - sending notification email '
                  f' to maintainers: {maintainers}')
コード例 #7
0
def notify_project_managers(repositories):
    if repositories is None:
        return
    project_repos = {}
    for ghrepo in repositories:
        project_id = ghrepo.get_repository_project_id()
        if project_id in project_repos:
            project_repos[project_id].append(ghrepo.get_repository_url())
        else:
            project_repos[project_id] = [ghrepo.get_repository_url()]
    for project_id in project_repos:
        managers = cla.controllers.project.get_project_managers("",project_id,enable_auth = False)
        project = cla.controllers.project.get_project(project_id)
        repositories = project_repos[project_id]
        subject, body, recipients = unable_to_do_cla_check_email_content(managers, project["project_name"], repositories)
        get_email_service().send(subject, body, recipients)
コード例 #8
0
def request_company_admin_access(user_id, company_id):
    """
    Send Email to company admins to inform that that a user is requesting to be a CLA Manager for their company.
    """

    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)}}

    subject = 'CLA: Request for Access to Corporate Console'

    # Send emails to every CLA manager
    for admin in company.get_managers():
        body = '''Hello {admin_name},

The following user is requesting CLA Manager access for your organization: {company_name}

    {user_name} <{user_email}>

Navigate to the EasyCLA Corporate Console using the link below and add this user to your Organization's Company Access Control List. Please notify the user once they are added so that they may log in to the EasyCLA Corporate Console with their LFID.

{corporate_console_url}

- EasyCLA System
'''.format(admin_name=admin.get_user_name(),
           user_name=user_name,
           company_name=company.get_company_name(),
           user_email=user_email,
           corporate_console_url='https://{}'.format(
               cla.conf['CORPORATE_BASE_URL']))
        recipient = admin.get_lf_email()
        email_service = get_email_service()
        email_service.send(subject, body, recipient)
コード例 #9
0
ファイル: user.py プロジェクト: prasannamahajan/easycla
def send_email_to_cla_manager(project, contributor_name, contributor_email,
                              cla_manager_name, cla_manager_email,
                              company_name, account_exists):
    """
    Helper function to send an email to a prospective CLA Manager.

    :param project: The project (CLA Group) data model
    :param contributor_name: The name of the user sending the email.
    :param contributor_email: The email address that this user wants to be added to the approval list. Must exist in the
           user's list of emails.
    :param cla_manager_name: The name of the CLA manager
    :param cla_manager_email: The email address of the CLA manager
    :param company_name: The name of the organization/company
    :param account_exists: boolean to check whether the email is being sent to a proposed admin(false), or an admin for
           an existing company(true).
     """

    # account_exists=True send email to the CLA Manager of the existing company
    # account_exists=False send email to a proposed CLA Manager who needs to register the company through
    # the Corporate Console.
    subject = f'EasyCLA: Request to start CLA signature process for {project.get_project_name()}'
    body = f'''
<p>Hello {cla_manager_name},</p>
<p>This is a notification email from EasyCLA regarding the project {project.get_project_name()}.</p>
<p>{project.get_project_name()} uses EasyCLA to ensure that before a contribution is accepted, the contributor is
covered under a signed CLA.</p>
<p>{contributor_name} ({contributor_email}) has designated you as the proposed initial CLA Manager for contributions
from {company_name if company_name else 'your company'} to {project.get_project_name()}. This would mean that, after the
CLA is signed, you would be able to maintain the list of employees allowed to contribute to {project.get_project_name()}
on behalf of your company, as well as the list of your company’s CLA Managers for {project.get_project_name()}.</p>
<p>If you can be the initial CLA Manager from your company for {project.get_project_name()}, please log into the EasyCLA
Corporate Console at {cla.conf['CLA_LANDING_PAGE']} to begin the CLA signature process. You might not be authorized to
sign the CLA yourself on behalf of your company; if not, the signature process will prompt you to designate somebody
else who is authorized to sign the CLA.</p>
{get_email_help_content(project.get_version() == 'v2')}
{get_email_sign_off_content()}
'''
    recipient = cla_manager_email
    email_service = get_email_service()
    email_service.send(subject, body, recipient)
コード例 #10
0
def send_email_to_admin(user_name, user_email, admin_name, admin_email,
                        project_name, account_exists):
    """
    Helper function to send an email to a company admin.

    :param user_name: The name of the user sending the email.
    :param user_email: The email address that this user wants to be whitelisted. Must exist in the user's list of emails.
    :param admin_name: The name of the CLA manager or ACL
    :param admin_email: The email address of the CLA manager or ACL
    :param company_name: The name of the company
    :param project_name: The name of the project
    :param account_exists: boolean to check whether the email is being sent to a proposed admin(false), or an admin for an existing company(true).
     """

    # account_exists=True send email to an admin of an existing company
    # account_exists=False send email to a proposed admin who needs to register the company through the Corporate Console.
    message = 'Please click the following link to sign in to the EasyCLA Corporate Console.' if account_exists else 'Please click the following link to create an account in the CLA Corporate Console.'

    subject = 'CLA: Invitation to Sign the {} Corporate CLA'.format(
        project_name)
    body = '''Hello {admin_name},

The following contributor would like to submit a contribution to {project_name} and is requesting to be whitelisted as a contributor for your organization:

    {user_name} <{user_email}>

Before the contribution can be accepted, your organization must sign a CLA. {account_exists} Complete the CLA for the {project_name} project, and add this contributor to the CLA whitelist. Please notify the contributor once they are added so that they may complete the contribution process.

{corporate_console_url}

- EasyCLA System
'''.format(admin_name=admin_name,
           project_name=project_name,
           user_name=user_name,
           user_email=user_email,
           account_exists=message,
           corporate_console_url=cla.conf['CLA_LANDING_PAGE'])
    recipient = admin_email
    email_service = get_email_service()
    email_service.send(subject, body, recipient)
コード例 #11
0
def send_authority_email(company_name, project_name, authority_name, authority_email):
    """
    Sends email to the specified corporate authority to sign the CCLA Docusign file. 
    """

    subject = 'CLA: Invitation to Sign a Corporate Contributor License Agreement'
    body = '''Hello %s, 
    
Your organization: %s, 
    
has requested a Corporate Contributor License Agreement Form to be signed for the following project:

%s

Please read the agreement carefully and sign the attached file. 
    

- Linux Foundation CLA System
''' % (authority_name, company_name, project_name)
    recipient = authority_email
    email_service = get_email_service()
    email_service.send(subject, body, recipient)
コード例 #12
0
ファイル: user.py プロジェクト: prasannamahajan/easycla
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 Allow 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 Allow 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 Allow List, please reach out to them directly to discuss.</p>
{get_email_help_content(project.get_version() == 'v2')}
{get_email_sign_off_content()}
'''

    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,
        contains_pii=True,
    )
コード例 #13
0
ファイル: signature.py プロジェクト: geva/easycla
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,
    )
コード例 #14
0
ファイル: signature.py プロジェクト: geva/easycla
def remove_cla_manager(username, signature_id, lfid):
    """
    Removes the LFID from the project ACL

    :param username: username of the user
    :type username: string
    :param project_id: The ID of the project
    :type project_id: UUID
    :param lfid: the lfid (manager username) to be removed to the project acl
    :type lfid: string
    """
    # Find project
    signature = Signature()
    try:
        signature.load(str(signature_id))
    except DoesNotExist as err:
        return {'errors': {'signature_id': str(err)}}

    # Validate user is the manager of the project
    signature_acl = signature.get_signature_acl()
    if username not in signature_acl:
        return {
            'errors': {
                'user': "******"
            }
        }

    # Avoid to have an empty acl
    if len(signature_acl) == 1 and username == lfid:
        return {
            'errors': {
                'user':
                "******"
            }
        }
    # Remove LFID from the acl
    signature.remove_signature_acl(lfid)
    signature.save()

    # get cla managers for email content
    managers = get_cla_managers(username, signature_id)

    # Get Company and Project instances
    try:
        project = get_project(signature.get_signature_project_id())
    except DoesNotExist as err:
        return err
    try:
        company_instance = get_company(signature.get_signature_reference_id())
    except DoesNotExist as err:
        return err

    # Send email to removed CLA manager
    # send email to newly added CLA manager
    try:
        subject, body, recipients = remove_cla_manager_email_content(
            lfid, project, company_instance, managers)
        get_email_service().send(subject, body, recipients)
    except Exception as err:
        return {
            'errors':
            {'Failed to send email for lfid: %s , %s ' % (lfid, err)}
        }

    event_data = f'User with lfid {lfid} removed from project ACL with signature {signature.get_signature_id()}'

    Event.create_event(
        event_data=event_data,
        event_summary=event_data,
        event_type=EventType.RemoveCLAManager,
        contains_pii=True,
    )

    # Return modified managers
    return get_managers_dict(signature_acl)
コード例 #15
0
def request_company_whitelist(user_id: str,
                              company_id: 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 whitelist.

    :param user_id: The ID of the user requesting to be added to the company's whitelist.
    :type user_id: string
    :param company_id: The ID of the company that the request is going to.
    :type company_id: string
    :param user_email: The email address that this user wants to be whitelisted. 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 whitelist
    :type recipient_name: string
    :param recipient_email: An optional recipient email for requesting the company whitelist
    :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_email is None:
        return {
            'errors': {
                'user_email': 'User 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)}}

    emails = user.get_user_emails()
    if user_email not in emails:
        return {
            'errors': {
                'user_email': 'Must provide one of the user\'s existing emails'
            }
        }

    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)}}

    user_name = user.get_user_name()
    company_name = company.get_company_name()
    project_name = project.get_project_name()

    # If provided, we will use the parameter for the recipient name and email - if not provided, then we will use the
    # default company manager's email
    if not recipient_name and not recipient_email:
        cla.log.debug(
            'request_company_whitelist - recipient name and email missing from request - '
            'using the company manager as the recipient')
        manager_id = company.get_company_manager_id()
        manager = get_user_instance()
        try:
            manager.load(manager_id)
        except DoesNotExist as err:
            return {
                'errors': {
                    'company_id':
                    'No CLA Manager exists for this company - can not send email'
                }
            }

        recipient_name = manager.get_user_name()
        if manager.get_lf_email() is not None:
            recipient_email = manager.get_lf_email()
        else:
            emails = manager.get_user_emails()
            if len(emails) > 0:
                recipient_email = emails[0]
            else:
                return {
                    'errors': {
                        'manager_email':
                        'Manager email is missing - unable to send to recipient'
                    }
                }

    subject = (
        f'CLA: {user_name} is requesting to be whitelisted for {project_name} project '
        f'as a {company_name} employee')

    body = f'''Hello {recipient_name},

{user_name} is requesting to be whitelisted as a contributor for your organization ({company_name}):

    {user_name} <{user_email}>

The message that was attached to the request:

    {message}

You can whitelist {user_name} in the EasyCLA Corporate console. If the email above is the personal email of one of your employees, please request that they add their organization email to their GitHub profile and try signing the CLA again. If you are unsure about this request, it may be prudent to get in touch with {user_name} to clarify.
Please follow up with the user as necessary.

Click on the following link to navigate to the EasyCLA Corporate Console.

 https://{cla.conf['CORPORATE_BASE_URL']}

- EasyCLA System
'''

    cla.log.debug(f'request_company_whitelist - sending email '
                  f'to recipient {recipient_name}/{recipient_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: {user.get_user_name()} requests to be whitelisted for the organization {company.get_company_name}'\
                 f'{user.get_user_name()} <{user.get_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,
        contains_pii=True,
    )
コード例 #16
0
ファイル: user.py プロジェクト: zaclittleberry/easycla
def request_company_whitelist(user_id,
                              company_id,
                              user_email,
                              project_id,
                              message=None):
    """
    Sends email to the specified company manager notifying them that a user has requested to be
    added to their whitelist.

    :param user_id: The ID of the user requesting to be added to the company's whitelist.
    :type user_id: string
    :param company_id: The ID of the company that the request is going to.
    :type company_id: string
    :param user_email: The email address that this user wants to be whitelisted. Must exist in the
        user's list of emails.
    :type user_email: string
    :param messsage: A custom message to add to the email sent out to the manager.
    :type message: string
    """
    user = User()
    try:
        user.load(user_id)
    except DoesNotExist as err:
        return {'errors': {'user_id': str(err)}}
    emails = user.get_user_emails()
    if user_email not in emails:
        return {
            'errors': {
                'user_email': 'Must provide one of the user\'s existing emails'
            }
        }
    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)}}

    user_name = user.get_user_name()
    company_name = company.get_company_name()
    project_name = project.get_project_name()

    subject = '''CLA: %s is requesting to be whitelisted for %s project ''' % (
        user_name, project_name)

    body = '''%s is requesting to be whitelisted as a contributor for your organization (%s):

    %s <%s>

The message that was attached to the request:

    %s

You can whitelist %s in the CLA Corporate console. If the email above is the personal email of one of your employees, please request that they add their organization email to their GitHub profile and try signing the CLA again. If you are unsure about this request, it may be prudent to get in touch with %s to clarify.
Please follow up with the user as necessary.

Click on the following link to navigate to the CLA Corporate Console.

 %s  

- Linux Foundation CLA System
''' % (user_name, company_name, user_name, user_email, message, user_name,
       user_name, 'https://{}'.format(cla.conf['CORPORATE_BASE_URL']))

    manager_id = company.get_company_manager_id()
    manager = get_user_instance()
    try:
        manager.load(manager_id)
    except DoesNotExist as err:
        return {
            'errors': {
                'company_id':
                'No manager exists for this company - can not send email'
            }
        }
    recipient = manager.get_user_email()
    email_service = get_email_service()
    email_service.send(subject, body, recipient)