Skip to content

Commit

Permalink
Merge pull request #12910 from mrgnr/cred-marketo-keys
Browse files Browse the repository at this point in the history
Add form for setting activation keys in marketo
  • Loading branch information
mrgnr committed May 31, 2023
2 parents 4a96ae3 + e008755 commit 9afcda5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
26 changes: 26 additions & 0 deletions templates/credentials/beta-activation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "credentials/base_cred.html" %}

{% block title %}Canonical Credentials -- Beta activation{% endblock %}

{% block meta_description %}The Canonical Ubuntu Essentials exams certify knowledge and verify skills in general Linux, Ubuntu Desktop, and Ubuntu Server topics.{% endblock meta_description %}

{% block content %}

<section class="p-strip--suru-topped">
<div class="row">
<h1>Add activation keys</h1>
<div class="col-8">
<form action="/credentials/beta/activation" method="post">
<label class="p-heading--3" for="Emails">Email addresses</label>
<p>Add one or more user email addresses below, each on a new line.</p>
<textarea id="Emails" name="emails" class="is-required" required aria-required="true" rows="10" placeholder="charlie.changer@example.com"></textarea>
<label class="p-heading--3" for="Keys">Activation keys</label>
<p>Add one or more activation keys below, each on a new line.</p>
<textarea id="Keys" name="keys" class="is-required" required aria-required="true" rows="10" placeholder="abcdef"></textarea>
<button type="submit" class="p-button--positive">Submit</button>
</form>
</div>
</div>
</section>

{% endblock content%}
6 changes: 6 additions & 0 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
cred_submit_form,
cred_syllabus_data,
cred_your_exams,
cred_beta_activation,
get_activation_keys,
rotate_activation_key,
)
Expand Down Expand Up @@ -900,6 +901,11 @@ def takeovers_index():
view_func=activate_activation_key,
methods=["POST"],
)
app.add_url_rule(
"/credentials/beta/activation",
view_func=cred_beta_activation,
methods=["GET", "POST"],
)

# Charmed OpenStack docs
openstack_docs = Docs(
Expand Down
14 changes: 14 additions & 0 deletions webapp/marketo.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,17 @@ def submit_form(self, data):
return self.request(
"POST", "/rest/v1/leads/submitForm.json", json=data
)

def describe_leads(self):
return self.request("GET", "/rest/v1/leads/describe.json")

def get_lead(self, id_):
return self.request("GET", f"/rest/v1/leads/{id_}.json")

def update_leads(self, leads=None):
data = {
"action": "updateOnly",
"lookupField": "email",
"input": leads,
}
return self.request("POST", "/rest/v1/leads.json", json=data)
20 changes: 20 additions & 0 deletions webapp/shop/cred/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from googleapiclient.discovery import build
from werkzeug.exceptions import BadRequest

from ...views import marketo_api


TIMEZONE_COUNTRIES = {
timezone: country
Expand Down Expand Up @@ -652,3 +654,21 @@ def activate_activation_key(ua_contracts_api, **kwargs):
"activationKey": activation_key,
}
)


@shop_decorator(area="cred", permission="user", response="html")
@canonical_staff()
def cred_beta_activation(**_):
if flask.request.method == "POST":
data = flask.request.form

emails = data["emails"].split("\n")
keys = data["keys"].split("\n")

leads = []
for email, key in zip(emails, keys):
leads.append({"email": email, "cred_activation_key": key})

marketo_api.update_leads(leads)

return flask.render_template("credentials/beta-activation.html")

0 comments on commit 9afcda5

Please sign in to comment.