Skip to content

Commit

Permalink
Remove get_webhook_responses view
Browse files Browse the repository at this point in the history
  • Loading branch information
britneywwc committed Mar 12, 2024
1 parent cba0ebe commit d3afd16
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 58 deletions.
6 changes: 0 additions & 6 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
cred_your_exams,
get_activation_keys,
get_cue_products,
get_filtered_webhook_responses,
get_issued_badges,
get_my_issued_badges,
get_webhook_response,
Expand Down Expand Up @@ -919,11 +918,6 @@ def takeovers_index():
view_func=cred_beta_activation,
methods=["GET", "POST"],
)
app.add_url_rule(
"/credentials/get_filtered_webhook_responses",
view_func=get_filtered_webhook_responses,
methods=["GET"],
)
app.add_url_rule(
"/credentials/get_webhook_response",
view_func=get_webhook_response,
Expand Down
101 changes: 49 additions & 52 deletions webapp/shop/cred/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
handle_confidentiality_agreement_submission,
has_filed_confidentiality_agreement,
)
from webapp.shop.decorators import shop_decorator, canonical_staff
from webapp.shop.decorators import (
shop_decorator,
canonical_staff,
get_trueability_api_instance,
init_trueability_session,
)
from webapp.shop.utils import get_exam_contract_id, get_user_first_last_name
from webapp.login import user_info

Expand Down Expand Up @@ -634,12 +639,50 @@ def cred_shop_thank_you(**kwargs):

@shop_decorator(area="cube", permission="user", response="html")
@canonical_staff()
def cred_shop_webhook_responses(**kwargs):
def cred_shop_webhook_responses(trueability_api, **kwargs):
ability_screen_id = "4190"
page = flask.request.args.get("page", 1)
webhook = get_filtered_webhook_responses(
ability_screen_id=ability_screen_id, page=page
).json
if "page" in kwargs:
page = int(kwargs["page"])
else:
page = flask.request.args.get("page", 1)
page = int(page)

per_page = flask.request.args.get("per_page", 10)
per_page = int(per_page)
ta_results_per_page = 100
ta_page = math.ceil(page * per_page // ta_results_per_page)

trueability_session = init_trueability_session("cred")
trueability_api = get_trueability_api_instance("cred", trueability_session)
webhook_responses = trueability_api.get_filtered_webhook_responses(
ability_screen_id=ability_screen_id,
page=ta_page,
)
total_count = webhook_responses["meta"]["total_count"]
ta_webhook_responses = webhook_responses["webhook_responses"]
ta_webhook_responses = [
ta_webhook_responses[i]
for i in range(
page * per_page % ta_results_per_page - per_page,
min(page * per_page % ta_results_per_page, total_count),
)
]
page_metadata = {}
page_metadata["current_page"] = page
page_metadata["total_pages"] = math.ceil(
webhook_responses["meta"]["total_count"] // per_page
)
page_metadata["total_count"] = total_count
page_metadata["next_page"] = (
page + 1 if page < page_metadata["total_pages"] else None
)
page_metadata["prev_page"] = page - 1 if page > 1 else None

webhook = {
"webhook_responses": ta_webhook_responses,
"meta": page_metadata,
}

return flask.render_template(
"credentials/shop/webhook_responses.html", webhook_responses=webhook
)
Expand Down Expand Up @@ -765,52 +808,6 @@ def cred_beta_activation(**_):
return flask.render_template("credentials/beta-activation.html")


@shop_decorator(area="cred", permission="user", response="json")
@canonical_staff()
def get_filtered_webhook_responses(trueability_api, **kwargs):
if kwargs["ability_screen_id"]:
ability_screen_id = kwargs["ability_screen_id"]
else:
ability_screen_id = flask.request.args.get("ability_screen_id", None)

if kwargs["page"]:
page = int(kwargs["page"])
else:
page = flask.request.args.get("page", 1)
page = int(page)
per_page = flask.request.args.get("per_page", 10)
per_page = int(per_page)
ta_results_per_page = 100
ta_page = math.ceil(page * per_page // ta_results_per_page)
webhook_responses = trueability_api.get_filtered_webhook_responses(
ability_screen_id=ability_screen_id,
page=ta_page,
)
total_count = webhook_responses["meta"]["total_count"]
ta_webhook_responses = webhook_responses["webhook_responses"]
ta_webhook_responses = [
ta_webhook_responses[i]
for i in range(
page * per_page % ta_results_per_page - per_page,
min(page * per_page % ta_results_per_page, total_count),
)
]
page_metadata = {}
page_metadata["current_page"] = page
page_metadata["total_pages"] = math.ceil(
webhook_responses["meta"]["total_count"] // per_page
)
page_metadata["total_count"] = total_count
page_metadata["next_page"] = (
page + 1 if page < page_metadata["total_pages"] else None
)
page_metadata["prev_page"] = page - 1 if page > 1 else None

return flask.jsonify(
{"webhook_responses": ta_webhook_responses, "meta": page_metadata}
)


@shop_decorator(area="cred", permission="user", response="json")
@canonical_staff()
def get_webhook_response(trueability_api, **kwargs):
Expand Down

0 comments on commit d3afd16

Please sign in to comment.