Code ReviewSign In / operations / software / klaxon / 363666389c31a1e2b97bebc4b2efa23ba231c93d^! / .
commit363666389c31a1e2b97bebc4b2efa23ba231c93d[log] [tgz]
authorChris Danis <>Fri Jan 08 14:05:45 2021 -0500
committerChris Danis <>Wed Jan 20 11:49:21 2021 -0500
parente01d86ede1de0341c9780a14d498ebccc7a66c15 [diff]
Send pages with user's email address, if available Change-Id: Ibc4df50e963a323e8a4b93555da14290c819d2ef
diff --git a/klaxon/ b/klaxon/ index b38cc21..db6bd59 100644 --- a/klaxon/ +++ b/klaxon/
@@ -37,6 +37,7 @@ 'KLAXON_INCIDENT_LIST_CACHE_TTL_SECONDS': '10', 'KLAXON_INCIDENT_LIST_RECENCY_MINUTES': '60', 'KLAXON_CAS_AUTH_HEADER': 'CAS-User',+ 'KLAXON_CAS_EMAIL_HEADER': 'X-CAS-Mail', 'KLAXON_VO_API_ID': None, 'KLAXON_VO_API_KEY': None, 'KLAXON_VO_CREATE_INCIDENT_URL': None,@@ -109,6 +110,19 @@ raise werkzeug.exceptions.Forbidden return request.headers.get(header, default='unknown') + def get_cas_user_email():+ """From request context, returns the logged-in user's email address, if available."""+ header = app.config['KLAXON_CAS_EMAIL_HEADER']​+ return request.headers.get(header, default=None)++ def get_user_identity():+ """From request context, returns the logged-in username + email address, if available."""+ email = get_cas_user_email()+ if email:+ return f"{get_username()} ({email})"+ else:+ return get_username()+ @app.route('/') def root(): return render_template('index.html')​@@ -122,14 +136,16 @@ @app.route('/protected/page_form') def page_form():- return render_template('page_form.html', username=get_username())​+ return render_template('page_form.html', identity=get_user_identity(),​+ email=get_cas_user_email()) @app.route('/protected/submit_page', methods=['POST']) def submit_page(): form = request.form # TODO: validate that required fields in the form were included. summary = form['summary']- headline = f"Manual #page by {get_username()}: {summary}"+ headline = f"Manual page by {get_user_identity()}: {summary}"+ vo.send_page(summary=headline, description=form['description'])
diff --git a/klaxon/templates/page_form.html b/klaxon/templates/page_form.html index 3b39f91..5191736 100644 --- a/klaxon/templates/page_form.html +++ b/klaxon/templates/page_form.html
@@ -12,10 +12,10 @@ <div class="field"> <label class="label">You are logged in as: </label> <div class="control">- <input class="input" type="text" value="{{ username }}" readonly>+ <input class="input" type="text" value="{{ identity }}" readonly> </div> <p class="help">- Your username will be included.+ Your username{% if email %} and email address{% endif %} will be included. </p> </div>
Powered by Gitiles