diff options
author | John Nduli | 2024-09-05 02:05:31 +0300 |
---|---|---|
committer | BonfaceKilz | 2024-09-17 11:40:42 +0300 |
commit | e4a8e2506c38fc86229fb24c30e4570f8aa72037 (patch) | |
tree | 2afe4729dec003f5b6d2f90553504db901aac0db /gn2/wqflask | |
parent | e86a6a9d254df6c041c14edcb15a03e7bdb73ee2 (diff) | |
download | genenetwork2-e4a8e2506c38fc86229fb24c30e4570f8aa72037.tar.gz |
feat: prefill email in edit rif
Diffstat (limited to 'gn2/wqflask')
-rw-r--r-- | gn2/wqflask/templates/wiki/edit_wiki.html | 2 | ||||
-rw-r--r-- | gn2/wqflask/views.py | 17 |
2 files changed, 15 insertions, 4 deletions
diff --git a/gn2/wqflask/templates/wiki/edit_wiki.html b/gn2/wqflask/templates/wiki/edit_wiki.html index 242456c4..23412a31 100644 --- a/gn2/wqflask/templates/wiki/edit_wiki.html +++ b/gn2/wqflask/templates/wiki/edit_wiki.html @@ -59,7 +59,7 @@ </div> <div class="form-group"> <label for="email" class="col-sm-2">Email: </label> - <input type="text" name="email" value="" required> + <input type="text" name="email" value="{{ session_email }}" required> </div> <div class="form-group"> <label for="usercode" class="col-sm-2">User Code: </label> diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index d5fcedfe..ec2854c4 100644 --- a/gn2/wqflask/views.py +++ b/gn2/wqflask/views.py @@ -1590,10 +1590,10 @@ def approve_reject_diff() -> Response: diff_id=form["diff_id"])) -@app.route("/metadata/wiki/<int:comment_id>/edit", methods=["GET", "POST"]) +@app.route("/genewiki/<int:comment_id>/edit", methods=["GET", "POST"]) +@require_oauth2 def edit_wiki(comment_id: int): """fetch generif metadata from gn3 and display it""" - # FIXME: better error handling if request.method == "GET": last_wiki_resp = requests.get( urljoin(GN3_LOCAL_URL, f"/api/metadata/wiki/{comment_id}") @@ -1616,11 +1616,13 @@ def edit_wiki(comment_id: int): categories[i : i + 3] for i in range(0, len(categories), 3) ] + session_email = session_info()["user"]["email"] return render_template( "wiki/edit_wiki.html", content=last_wiki_content, species_dict=species_dict, grouped_categories=grouped_categories, + session_email=session_email, ) if request.method == "POST": post_data = request.form @@ -1635,8 +1637,17 @@ def edit_wiki(comment_id: int): "categories": post_data.getlist("genecategory"), "reason": post_data["reason"], } + def _invalid_token(err): + raise ValueError(f"Error finding user token, got: {err}") + + token = session_info()["user"]["token"].either( + lambda err: _invalid_token(err), lambda tok: tok["access_token"] + ) + post_response = requests.post( - urljoin(GN3_LOCAL_URL, f"api/metadata/wiki/{comment_id}/edit"), json=payload + urljoin(GN3_LOCAL_URL, f"api/metadata/wiki/{comment_id}/edit"), + json=payload, + headers={"Authorization": f"Bearer {token}"}, ) post_response.raise_for_status() post_res = post_response.json() |