Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove instant provisioning for exams #13045

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions templates/credentials/provision.html

This file was deleted.

2 changes: 1 addition & 1 deletion templates/credentials/schedule.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h5 class="p-notification__title">Error</h5>
<select id="exam-timezone" name="timezone" required>
</select>
<label class="p-heading--4" for="exam-date">Select your preferred day</label>
<p>You can schedule or reschedule your exam up to 24 hours in advance.</p>
<p>You can schedule your exam to begin 30 minutes from now or later.</p>
<input type="date" id="exam-date" name="date" value="{{date}}" min="{{min_date}}" max="{{max_date}}" required />
<label class="p-heading--4" for="exam-time">Select your preferred time</label>
<p>Your exam will take up to one hour to complete. Please make sure to plan accordingly before and after to
Expand Down
6 changes: 0 additions & 6 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
cred_cancel_exam,
cred_exam,
cred_home,
cred_provision,
cred_redeem_code,
cred_schedule,
cred_self_study,
Expand Down Expand Up @@ -1134,11 +1133,6 @@ def takeovers_index():
view_func=cred_submit_form,
methods=["GET", "POST"],
)
app.add_url_rule(
"/credentials/provision",
view_func=cred_provision,
methods=["GET", "POST"],
)
app.add_url_rule("/credentials/shop/", view_func=cred_shop)
app.add_url_rule("/credentials/shop/<p>", view_func=cred_shop)
app.add_url_rule(
Expand Down
96 changes: 2 additions & 94 deletions webapp/shop/cred/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from webapp.shop.decorators import shop_decorator, canonical_staff
from webapp.shop.utils import get_exam_contract_id, get_user_first_last_name
from webapp.login import user_info
from webapp.views import get_user_country_by_ip

from google.oauth2 import service_account
from googleapiclient.discovery import build
Expand Down Expand Up @@ -64,8 +63,8 @@ def cred_sign_up(**_):
def cred_schedule(ua_contracts_api, trueability_api, **_):
error = None
now = datetime.utcnow()
min_date = (now + timedelta(days=1)).strftime("%Y-%m-%d")
max_date = (now + timedelta(days=42)).strftime("%Y-%m-%d")
min_date = (now + timedelta(minutes=30)).strftime("%Y-%m-%d")
max_date = (now + timedelta(days=30)).strftime("%Y-%m-%d")

if flask.request.method == "POST":
data = flask.request.form
Expand Down Expand Up @@ -265,12 +264,6 @@ def cred_your_exams(ua_contracts_api, trueability_api, **kwargs):
f"contractItemID={contract_item_id}",
"button_class": "p-button",
},
{
"text": "Take now",
"href": "/credentials/provision?"
f"contractItemID={contract_item_id}",
"button_class": "p-button",
},
]
exams_not_taken.append(
{"name": name, "state": "Not taken", "actions": actions}
Expand Down Expand Up @@ -366,87 +359,6 @@ def cred_exam(trueability_api, **_):
return flask.render_template("credentials/exam.html", url=url)


@shop_decorator(area="cred", permission="user", response="html")
def cred_provision(ua_contracts_api, trueability_api, **_):
contract_item_id = flask.request.args.get("contractItemID", type=int)

if contract_item_id is None:
return flask.redirect("/credentials/your-exams")

country_code = get_user_country_by_ip().json["country_code"] or "GB"
reservation_uuid = None
assessment = None
reservation = None
error = None

exam_contracts = ua_contracts_api.get_annotated_contract_items(
product_tags=["cue"],
)

exam_contract = None
for item in exam_contracts:
if contract_item_id == (item.get("id") or item["contractItem"]["id"]):
exam_contract = item
break

if exam_contract:
if "reservation" in exam_contract["cueContext"]:
reservation_uuid = exam_contract["cueContext"]["reservation"][
"IDs"
][-1]
else:
error = "Exam not found"

if not reservation_uuid:
tz_info = pytz.timezone("UTC")
starts_at = tz_info.localize(datetime.utcnow() + timedelta(seconds=20))
first_name, last_name = get_user_first_last_name()

try:
response = ua_contracts_api.post_assessment_reservation(
contract_item_id,
first_name,
last_name,
tz_info.zone,
starts_at.isoformat(),
country_code,
)

reservation_uuid = response.get("reservation", {}).get("IDs", [])[
-1
]

except UAContractsAPIErrorView:
error = (
"An error occurred while reserving your exam. "
+ "Please try refreshing the page."
)

if reservation_uuid:
response = trueability_api.get_assessment_reservation(reservation_uuid)

if "error" in response:
error = response.get("message", "No exam booking could be found.")
else:
reservation = response["assessment_reservation"]
assessment = reservation["assessment"]

if assessment and assessment.get("state") in [
"notified",
"released",
"in_progress",
]:
return flask.redirect(f"/credentials/exam?id={ assessment['id'] }")

return flask.render_template(
"/credentials/provision.html",
contract_item_id=contract_item_id,
assessment=assessment,
reservation=reservation,
error=error,
)


@shop_decorator(area="cred", permission="user_or_guest", response="html")
def cred_syllabus_data(**_):
exam_name = flask.request.args.get("exam")
Expand Down Expand Up @@ -609,10 +521,6 @@ def cred_redeem_code(ua_contracts_api, advantage_mapper, **kwargs):
return flask.redirect(
f"/credentials/schedule?contractItemID={contract_id}"
)
if action == "take":
return flask.redirect(
f"/credentials/provision?contractItemID={contract_id}"
)
return flask.render_template(
"/credentials/redeem.html",
notification_class="positive",
Expand Down
Loading