示例#1
0
        def student_get_course(netid, cid):
            if not verify_student_or_staff(netid, cid):
                return abort(HTTPStatus.FORBIDDEN)

            course = db.get_course(cid)
            if verify_staff(netid, cid):
                assignments = db.get_assignments_for_course(cid)
            else:
                assignments = db.get_assignments_for_course(cid,
                                                            visible_only=True)

            now = util.now_timestamp()

            for assignment in assignments:

                num_available_runs = get_available_runs(
                    cid, assignment["assignment_id"], netid, now)
                active_extensions, num_extension_runs = get_active_extensions(
                    cid, assignment["assignment_id"], netid, now)
                total_available_runs = num_extension_runs + num_available_runs

                if verify_staff(netid, cid):
                    total_available_runs = max(total_available_runs, 1)

                assignment.update(
                    {"total_available_runs": total_available_runs})

            return render_template("student/course.html",
                                   netid=netid,
                                   course=course,
                                   assignments=assignments,
                                   now=now,
                                   tzname=str(TZ))
示例#2
0
	def switcher_endpoint(course, assignment, mode="student"):
		'''
		This function determines the correct endpoint for the student/staff
		switcher based on the currently selected course/assignment
		'''
		route = "home"
		url_args = {}

		if course:
			# ensure user is staff of current course, 
			# otherwise redirect to staff_home
			if mode == "staff":
				netid = auth.get_netid()
				if not (netid and common.verify_staff(netid, course["_id"])):
					return url_for(f'.{mode}_{route}', **url_args)

			# get urls for current assignment or course
			if assignment:
				route = "get_assignment"
				url_args = {"cid": course["_id"], "aid": assignment["assignment_id"]}
			else:
				route = "get_course"
				url_args = {"cid": course["_id"]}

		return url_for(f'.{mode}_{route}', **url_args)
示例#3
0
        def student_get_assignment(netid, cid, aid):
            if not verify_student_or_staff(netid, cid):
                return abort(HTTPStatus.FORBIDDEN)

            course = db.get_course(cid)
            assignment = db.get_assignment(cid, aid)
            runs = db.get_assignment_runs_for_student(cid, aid, netid)
            now = util.now_timestamp()

            num_available_runs = get_available_runs(cid, aid, netid, now)
            active_extensions, num_extension_runs = get_active_extensions(
                cid, aid, netid, now)

            user = db.get_user(netid)
            commit = get_latest_commit(netid, user["access_token"],
                                       course["github_org"])

            if verify_staff(netid, cid):
                num_available_runs = max(num_available_runs, 1)

            return render_template("student/assignment.html",
                                   netid=netid,
                                   course=course,
                                   assignment=assignment,
                                   commit=commit,
                                   runs=runs,
                                   num_available_runs=num_available_runs,
                                   num_extension_runs=num_extension_runs,
                                   tzname=str(TZ),
                                   broadway_api_url=BROADWAY_API_URL)
示例#4
0
 def demote_course_admin(netid, cid):
     staff_id = request.form.get('netid')
     if not verify_staff(staff_id, cid) or not verify_admin(
             staff_id, cid):
         return util.error(f"'{staff_id}' is not a admin")
     db.remove_admin_from_course(cid, staff_id)
     return util.success(
         f"Successfully removed '{staff_id}' from admin")
示例#5
0
        def staff_get_workers(netid, cid):
            if not verify_staff(netid, cid):
                return abort(HTTPStatus.FORBIDDEN)

            workers = bw_api.get_workers(cid)
            if workers is not None:
                return util.success(jsonify(workers), HTTPStatus.OK)
            return util.error("")
示例#6
0
 def promote_course_staff(netid, cid):
     staff_id = request.form.get('netid')
     if not verify_staff(staff_id, cid):
         return util.error(f"'{staff_id}' is not a staff")
     result = db.add_admin_to_course(cid, staff_id)
     if none_modified(result):
         return util.error(f"'{staff_id}' is already an admin")
     return util.success(f"Successfully made '{staff_id}' admin")
示例#7
0
        def staff_get_run_log(netid, cid, aid, run_id):
            if not verify_staff(netid, cid):
                return abort(HTTPStatus.FORBIDDEN)

            log = bw_api.get_grading_run_log(cid, run_id)
            if log:
                return util.success(jsonify(log), HTTPStatus.OK)
            return util.error("")
示例#8
0
        def staff_get_assignment_config(netid, cid, aid):
            if not verify_staff(netid, cid):
                return abort(HTTPStatus.FORBIDDEN)

            config = bw_api.get_assignment_config(cid, aid)

            if config is None:
                return abort(404)

            return jsonify(config)
示例#9
0
        def staff_get_course(netid, cid):
            if not verify_staff(netid, cid):
                return abort(HTTPStatus.FORBIDDEN)

            course = db.get_course(cid)
            assignments = db.get_assignments_for_course(cid)
            is_admin = verify_admin(netid, cid)
            now = util.now_timestamp()
            return render_template("staff/course.html",
                                   netid=netid,
                                   course=course,
                                   assignments=assignments,
                                   tzname=str(TZ),
                                   is_admin=is_admin,
                                   now=now,
                                   visibility=db.Visibility,
                                   error=None)
示例#10
0
        def student_grade_assignment(netid, cid, aid):
            if not verify_student_or_staff(netid, cid):
                return abort(HTTPStatus.FORBIDDEN)
            if not verify_csrf_token(request.form.get("csrf_token")):
                return abort(HTTPStatus.BAD_REQUEST)

            now = util.now_timestamp()
            ext_to_use = None
            current_csrf_token = request.form.get("csrf_token")

            if not verify_staff(netid, cid):
                # not a staff member; perform quota checks
                num_available_runs = get_available_runs(cid, aid, netid, now)
                active_extensions, num_extension_runs = get_active_extensions(
                    cid, aid, netid, now)

                if num_available_runs + num_extension_runs <= 0:
                    restore_csrf_token(current_csrf_token)
                    return util.error("No grading runs available.")
                if num_available_runs <= 0:
                    # find the extension that is closest to expiration
                    ext_to_use = min(active_extensions,
                                     key=lambda ext: ext["end"])

            now_rounded = util.timestamp_round_up_minute(now)

            run_id = bw_api.start_grading_run(cid, aid, [netid], now_rounded)
            if run_id is None:
                restore_csrf_token(current_csrf_token)
                return util.error(
                    "Failed to start grading run. Please try again.")

            db.add_grading_run(cid,
                               aid,
                               netid,
                               now,
                               run_id,
                               extension_used=ext_to_use)
            return util.success("")
示例#11
0
        def staff_get_assignment(netid, cid, aid):
            if not verify_staff(netid, cid):
                return abort(HTTPStatus.FORBIDDEN)

            course = db.get_course(cid)
            assignment = db.get_assignment(cid, aid)
            student_runs = list(db.get_assignment_runs(cid, aid))
            scheduled_runs = list(db.get_scheduled_runs(cid, aid))
            is_admin = verify_admin(netid, cid)

            return render_template(
                "staff/assignment.html",
                netid=netid,
                course=course,
                assignment=assignment,
                student_runs=student_runs,
                scheduled_runs=scheduled_runs,
                sched_run_status=sched_api.ScheduledRunStatus,
                tzname=str(TZ),
                is_admin=is_admin,
                visibility=db.Visibility,
                broadway_api_url=BROADWAY_API_URL)
示例#12
0
 def wrapper(*args, **kwargs):
     netid = kwargs[UID_KEY]
     cid = kwargs[CID_KEY]
     if not verify_staff(netid, cid) or not verify_admin(netid, cid):
         return abort(HTTPStatus.FORBIDDEN)
     return func(*args, **kwargs)