def get_course(): if not _cas.is_logged_in(): return redirect(url_for('landing')) netid = _cas.authenticate() netid = netid.rstrip() if _db.is_blacklisted(netid): _db._add_admin_log( f'blacklisted user {netid} attempted to access the app') return make_response(render_template('blacklisted.html')) courseid = request.args.get('courseid') query = request.args.get('query') _db._add_system_log('user', { 'message': f'course page {courseid} visited by user {netid}' }, netid=netid) if query is None: query = '' if len(query) > 100: query = query[:100] search_res, new_query = do_search(query, _db) course_details, classes_list = pull_course(courseid, _db) curr_waitlists = _db.get_user(netid, 'waitlists') num_full = sum(class_data['isFull'] for class_data in classes_list) term_code, term_name = _db.get_current_term_code() section_names = _db.get_section_names_in_course(courseid) current_section = _db.get_current_section(netid, courseid) current_sectionname = _db.classid_to_sectionname( current_section) if current_section is not None else '' trade_unavailable = False if not section_names or len(section_names) < 2: trade_unavailable = True # change to check if updateSearch == 'false' # if updateSearch is None: html = render_template('base.html', is_dashboard=False, is_admin=False, user_is_admin=is_admin(netid, _db), netid=netid, current_section=current_section, current_sectionname=current_sectionname, courseid=courseid, course_details=course_details, classes_list=classes_list, trade_unavailable=trade_unavailable, curr_waitlists=curr_waitlists, search_res=search_res, num_full=num_full, section_names=section_names, term_code=term_code, term_name=term_name, last_query=quote_plus(new_query), last_query_unquoted=unquote_plus(new_query), notifs_online=_db.get_cron_notification_status()) return make_response(html)
def clear_by_course(courseid): netid = _cas.authenticate() netid = netid.strip() try: if not is_admin(netid, _db): return redirect(url_for('landing')) except: return redirect(url_for('landing')) return jsonify({'isSuccess': _db.clear_course_waitlists(courseid, netid)})
def clear_all_user_logs(): netid = _cas.authenticate() netid = netid.strip() try: if not is_admin(netid, _db): return redirect(url_for('landing')) except: return redirect(url_for('landing')) return jsonify({'isSuccess': _db.clear_all_user_logs(netid)})
def remove_from_blacklist(user): netid = _cas.authenticate() netid = netid.strip() try: if not is_admin(netid, _db): return redirect(url_for('landing')) except: return redirect(url_for('landing')) return jsonify({'isSuccess': _db.remove_from_blacklist(user.strip(), netid)})
def get_user_data(netid, isTrade): netid_ = _cas.authenticate() netid_.strip() try: if not is_admin(netid_, _db): return redirect(url_for('landing')) except: return redirect(url_for('landing')) return jsonify({'data': _db.get_waited_sections(netid.strip(), trades=isTrade == 'true')})
def set_notifications_status(status): netid = _cas.authenticate() netid = netid.strip() try: if not is_admin(netid, _db): return redirect(url_for('landing')) except: return redirect(url_for('landing')) _db.set_cron_notification_status(status == 'true', admin_netid=netid) return jsonify({})
def update_all_courses(): netid = _cas.authenticate() netid = netid.strip() try: if not is_admin(netid, _db): return redirect(url_for('landing')) except: return redirect(url_for('landing')) do_update_async(netid) # CAUTION: hard reset and update return jsonify({})
def tutorial(): if redirect_landing(): html = render_template('tutorial.html', loggedin=False) return make_response(html) term_name = _db.get_current_term_code()[1] html = render_template('tutorial.html', user_is_admin=is_admin(_cas.authenticate(), _db), loggedin=True, notifs_online=_db.get_cron_notification_status(), term_name=term_name) return make_response(html)
def get_notifications_status(): if redirect_landing(): return redirect(url_for('landing')) netid = _cas.authenticate() netid = netid.strip() try: if not is_admin(netid, _db): return redirect(url_for('landing')) except: return redirect(url_for('landing')) return jsonify({'isOn': _db.get_cron_notification_status()})
def dashboard(): if redirect_landing(): return redirect(url_for('landing')) netid = _cas.authenticate() netid = netid.rstrip() if _db.is_blacklisted(netid): _db._add_admin_log( f'blacklisted user {netid} attempted to access the app') return make_response(render_template('blacklisted.html')) data = _db.get_dashboard_data(netid) email = _db.get_user(netid, 'email') query = request.args.get('query') new_email = request.form.get('new_email') if query is None: query = '' if len(query) > 100: query = query[:100] search_res, new_query = do_search(query, _db) if new_email is not None: if '<' in new_email or '>' in new_email or 'script' in new_email: print('HTML code detected in', new_email, file=stderr) return redirect(url_for('dashboard')) _db.update_user(netid, new_email.strip()) return redirect(url_for('dashboard')) curr_sections = _db.get_current_sections(netid) term_name = _db.get_current_term_code()[1] html = render_template('base.html', is_dashboard=True, is_admin=False, netid=netid, user_is_admin=is_admin(netid, _db), search_res=search_res, last_query=quote_plus(new_query), last_query_unquoted=unquote_plus(new_query), username=netid.rstrip(), data=data, email=email, curr_sections=curr_sections, notifs_online=_db.get_cron_notification_status(), term_name=term_name) return make_response(html)
def admin(): netid = _cas.authenticate() netid = netid.strip() try: if not is_admin(netid, _db): return redirect(url_for('')) except: return redirect(url_for('')) _db._add_system_log('admin', { 'message': f'admin {netid} viewed admin panel' }, netid=netid) admin_logs = _db.get_admin_logs() try: admin_logs = admin_logs['logs'] except: admin_logs = None query = request.args.get('query-netid') if query is None: query = '' if len(query) > 100: query = query[:100] search_res, new_query = _db.search_for_user(query) term_code, term_name = _db.get_current_term_code() html = render_template('base.html', is_dashboard=False, is_admin=True, user_is_admin=True, search_res=search_res, last_query=quote_plus(new_query), last_query_unquoted=unquote_plus(new_query), username=netid.rstrip(), admin_logs=admin_logs, blacklist=_db.get_blacklist(), notifs_online=_db.get_cron_notification_status(), current_term_code=term_code, term_name=term_name) return make_response(html)
def activity(): if redirect_landing(): return redirect(url_for('landing')) netid = _cas.authenticate() waitlist_logs = _db.get_user_waitlist_log(netid) trade_logs = _db.get_user_trade_log(netid) term_name = _db.get_current_term_code()[1] html = render_template('activity.html', user_is_admin=is_admin(_cas.authenticate(), _db), loggedin=True, waitlist_logs=waitlist_logs, trade_logs=trade_logs, notifs_online=_db.get_cron_notification_status(), term_name=term_name) return make_response(html)
def fill_section(classid): netid = _cas.authenticate() netid = netid.strip() try: if not is_admin(netid, _db): return redirect(url_for('landing')) except: return redirect(url_for('landing')) try: curr_enrollment = _db.get_class_enrollment(classid) _db.update_enrollment( classid, curr_enrollment['capacity'], curr_enrollment['capacity']) _db._add_admin_log(f'manually filled enrollments for class {classid}') _db._add_system_log('admin', { 'message': f'manually filled enrollments for class {classid}' }, netid=netid) except: return jsonify({'isSuccess': False}) return jsonify({'isSuccess': True})
def get_course_info(courseid): netid = _cas.authenticate() netid = netid.rstrip() _db._add_system_log('user', { 'message': f'course page {courseid} visited by user {netid}' }, netid=netid) course_details, classes_list = pull_course(courseid, _db) curr_waitlists = _db.get_user(netid, 'waitlists') section_names = _db.get_section_names_in_course(courseid) current_section = _db.get_current_section(netid, courseid) current_sectionname = _db.classid_to_sectionname( current_section) if current_section is not None else '' trade_unavailable = False if not section_names or len(section_names) < 2: trade_unavailable = True num_full = sum(class_data['isFull'] for class_data in classes_list) term_code, term_name = _db.get_current_term_code() html = render_template('course/course.html', netid=netid, user_is_admin=is_admin(netid, _db), courseid=courseid, course_details=course_details, classes_list=classes_list, trade_unavailable=trade_unavailable, num_full=num_full, current_section=current_section, current_sectionname=current_sectionname, term_code=term_code, term_name=term_name, curr_waitlists=curr_waitlists, section_names=section_names, notifs_online=_db.get_cron_notification_status()) return make_response(html)