mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
find_users_by_email view calls API and feeds results to template
Template then displays the results. Page displays a message if no results found
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
from flask import abort, render_template, request, url_for
|
||||
from flask_login import login_required
|
||||
|
||||
from app import user_api_client
|
||||
from app.main import main
|
||||
from app.utils import user_is_platform_admin
|
||||
from app.main.forms import SearchUsersForm
|
||||
|
||||
|
||||
@main.route("/find-users-by-email", methods=['GET'])
|
||||
@main.route("/find-users-by-email", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def find_users_by_email():
|
||||
form = SearchUsersForm()
|
||||
users_found = None
|
||||
if form.validate_on_submit():
|
||||
users_found = user_api_client.find_users_by_full_or_partial_email(form.search.data)['data']
|
||||
return render_template(
|
||||
'views/find-users/find-users-by-email.html',
|
||||
form=SearchUsersForm(),
|
||||
form=form,
|
||||
users_found=users_found
|
||||
)
|
||||
|
||||
@@ -179,6 +179,12 @@ class UserApiClient(NotifyAdminAPIClient):
|
||||
data = {'email': email_address}
|
||||
self.post(endpoint, data=data)
|
||||
|
||||
def find_users_by_full_or_partial_email(self, email_address):
|
||||
endpoint = '/user/find-users-by-email'
|
||||
data = {'email': email_address}
|
||||
users = self.post(endpoint, data=data)
|
||||
return users
|
||||
|
||||
def is_email_already_in_use(self, email_address):
|
||||
if self.get_user_by_email_or_none(email_address):
|
||||
return True
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
{{ textbox(
|
||||
form.search,
|
||||
width='1-1',
|
||||
label='Find users by e-mail'
|
||||
label='Find users by e-mail, or by partial e-mail'
|
||||
) }}
|
||||
</div>
|
||||
<div class="column-one-quarter align-button-with-textbox">
|
||||
@@ -37,4 +37,19 @@
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
</form>
|
||||
|
||||
{% if users_found %}
|
||||
<nav class="browse-list">
|
||||
<ul>
|
||||
{% for user in users_found %}
|
||||
<li class="browse-list-item">
|
||||
<a href="#" class="browse-list-link">{{ user.email_address }}</a>
|
||||
<p class="browse-list-sub-item">{{ user.name }}</p>
|
||||
</li>
|
||||
<hr>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% elif users_found == [] %}
|
||||
<p>No users found.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user