def get_current_course_run(course, users_active_course_runs):
current_course_run = None<EOL>filtered_course_runs = []<EOL>all_course_runs = course['<STR_LIT>']<EOL>if users_active_course_runs:<EOL><INDENT>current_course_run = get_closest_course_run(users_active_course_runs)<EOL><DEDENT>else:<EOL><INDENT>for course_run in all_course_runs:<EOL><INDENT>if is_course_run_enrollable(course_run) and is_course_run_upgradeable(course_run):<EOL><INDENT>filtered_course_runs.append(course_run)<EOL><DEDENT><DEDENT>if not filtered_course_runs:<EOL><INDENT>filtered_course_runs = all_course_runs<EOL><DEDENT>if filtered_course_runs:<EOL><INDENT>current_course_run = get_closest_course_run(filtered_course_runs)<EOL><DEDENT><DEDENT>return current_course_run<EOL>
Return the current course run on the following conditions.

- If user has active course runs (already enrolled) then return course run with closest start date
Otherwise it will check the following logic:
- Course run is enrollable (see is_course_run_enrollable)
- Course run has a verified seat and the upgrade deadline has not expired.
- Course run start date is closer to now than any other enrollable/upgradeable course runs.
- If no enrollable/upgradeable course runs, return course run with most recent start date.