@classmethod<EOL><INDENT>def _enroll_users(<EOL>cls,<EOL>request,<EOL>enterprise_customer,<EOL>emails,<EOL>mode,<EOL>course_id=None,<EOL>program_details=None,<EOL>notify=True<EOL>):<DEDENT>
pending_messages = []<EOL>if course_id:<EOL><INDENT>succeeded, pending, failed = cls.enroll_users_in_course(<EOL>enterprise_customer=enterprise_customer,<EOL>course_id=course_id,<EOL>course_mode=mode,<EOL>emails=emails,<EOL>)<EOL>all_successes = succeeded + pending<EOL>if notify:<EOL><INDENT>enterprise_customer.notify_enrolled_learners(<EOL>catalog_api_user=request.user,<EOL>course_id=course_id,<EOL>users=all_successes,<EOL>)<EOL><DEDENT>if succeeded:<EOL><INDENT>pending_messages.append(cls.get_success_enrollment_message(succeeded, course_id))<EOL><DEDENT>if failed:<EOL><INDENT>pending_messages.append(cls.get_failed_enrollment_message(failed, course_id))<EOL><DEDENT>if pending:<EOL><INDENT>pending_messages.append(cls.get_pending_enrollment_message(pending, course_id))<EOL><DEDENT><DEDENT>if program_details:<EOL><INDENT>succeeded, pending, failed = cls.enroll_users_in_program(<EOL>enterprise_customer=enterprise_customer,<EOL>program_details=program_details,<EOL>course_mode=mode,<EOL>emails=emails,<EOL>)<EOL>all_successes = succeeded + pending<EOL>if notify:<EOL><INDENT>cls.notify_program_learners(<EOL>enterprise_customer=enterprise_customer,<EOL>program_details=program_details,<EOL>users=all_successes<EOL>)<EOL><DEDENT>program_identifier = program_details.get('<STR_LIT:title>', program_details.get('<STR_LIT>', _('<STR_LIT>')))<EOL>if succeeded:<EOL><INDENT>pending_messages.append(cls.get_success_enrollment_message(succeeded, program_identifier))<EOL><DEDENT>if failed:<EOL><INDENT>pending_messages.append(cls.get_failed_enrollment_message(failed, program_identifier))<EOL><DEDENT>if pending:<EOL><INDENT>pending_messages.append(cls.get_pending_enrollment_message(pending, program_identifier))<EOL><DEDENT><DEDENT>cls.send_messages(request, pending_messages)<EOL>
Enroll the users with the given email addresses to the courses specified, either specifically or by program.

Args:
    cls (type): The EnterpriseCustomerManageLearnersView class itself
    request: The HTTP request the enrollment is being created by
    enterprise_customer: The instance of EnterpriseCustomer whose attached users we're enrolling
    emails: An iterable of strings containing email addresses to enroll in a course
    mode: The enrollment mode the users will be enrolled in the course with
    course_id: The ID of the course in which we want to enroll
    program_details: Details about a program in which we want to enroll
    notify: Whether to notify (by email) the users that have been enrolled