Skip to content

Commit

Permalink
View users - fixed filter by organization (#87)
Browse files Browse the repository at this point in the history
* Created View User app

List users

* Uncomment auth lines

Authentication commented out for testing. Removing comments

* Update apcd-cms/src/apps/view_users/static/view_users_table/css/table.css

Co-authored-by: sophia-massie <[email protected]>

* Update apcd-cms/src/apps/view_users/templates/view_users.html

Co-authored-by: sophia-massie <[email protected]>

* Fixed FIlter

Added organization dropdown using organizations from table but removing duplicates from dropdown list. Amended db query to orderby orgs
Fixed column heading Role ID

---------

Co-authored-by: Shayan Khan <[email protected]>
Co-authored-by: sophia-massie <[email protected]>
  • Loading branch information
3 people authored Feb 3, 2023
1 parent 1f3142b commit 2ff166f
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 21 deletions.
38 changes: 38 additions & 0 deletions apcd-cms/src/apps/utils/apcd_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@
APCD_DB = settings.APCD_DATABASE


def get_users():
cur = None
conn = None
try:
conn = psycopg2.connect(
host=APCD_DB['host'],
dbname=APCD_DB['database'],
user=APCD_DB['user'],
password=APCD_DB['password'],
port=APCD_DB['port'],
sslmode='require'
)
query = """SELECT
users.user_id,
users.user_email,
users.user_name,
users.org_name,
users.role_id,
users.created_at,
users.updated_at,
users.notes
FROM users
ORDER BY users.org_name ASC
"""
cur = conn.cursor()
cur.execute(query)
return cur.fetchall()

except Exception as error:
logger.error(error)

finally:
if cur is not None:
cur.close()
if conn is not None:
conn.close()


def get_users():
cur = None
conn = None
Expand Down
59 changes: 38 additions & 21 deletions apcd-cms/src/apps/view_users/templates/view_users.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@ <h1>View Users</h1>
<div class="filter-container">
<div class="filter-content">
<span><b>Filter by Organization: </b></span>
<select id="statusFilter" class="status-filter" onchange="filterTableByStatus()">
<option class="dropdown-text">All</option>
<option class="dropdown-text">UUL</option>
<option class="dropdown-text">UMR</option>
<option class="dropdown-text">UHC</option>
<option class="dropdown-text">Reserve Nat Ins Co</option>
<option class="dropdown-text">Optum Behavioral</option>
<select id="organizationFilter" class="organization-filter" onchange="filterTableByOrganization()">

<option class="dropdown-text"></option>
{% for r in rows %}
<option class="dropdown-text">{{r.org_name}}</option>
{% endfor %}
</select>
</div>
</div>
<table id="usersTable" class="users-table"><table class="o-fixed-header-table o-table-wrap--flexible-horz users-table">
<table id="usersTable" class="users-table sortable"><table class="o-fixed-header-table o-table-wrap--flexible-horz users-table">
<thead>
<tr>
{% for k in header %}
<th>{{k}}</th>
{% endfor %}
</tr>
</thead>
<tbody>
<tbody id="usersTableBody">
{% for r in rows %}
<tr>
<td>{{r.user_id}}</td>
Expand All @@ -54,21 +53,39 @@ <h1>View Users</h1>
</table>
</div>
<script>
function filterTableByStatus() {
var dropdown, filter, table, rows, status, i;
dropdown = document.getElementById("statusFilter");
filter = dropdown.value;
table = document.getElementById("registrationTable");
rows = table.getElementsByTagName("tr");
[...rows].slice(1).forEach(row => {
status = row.getElementsByTagName("td")[5];
if (status.innerText != filter && filter != 'All') {
row.style.display = "none";
function filterTableByOrganization() {
var dropdown, filter, table, tr, td, i;
input = document.getElementById("organizationFilter");
console.log(input)
filter = input.value.toUpperCase();
console.log(filter)
table = document.getElementById("usersTableBody");
console.log(table)
tr = table.getElementsByTagName("tr");
console.log(tr)
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[3];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
row.style.display = "";
tr[i].style.display = "none";
}
})
}
}
}

/***remove duplicates from dropdown
*/
const options = []

document.querySelectorAll('#organizationFilter > option').forEach((option) => {
if (options.includes(option.value)) option.remove()
else options.push(option.value)
})



</script>

{% endblock %}
55 changes: 55 additions & 0 deletions apcd-cms/src/apps/view_users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,59 @@ def _set_modal_content(usr):
user_view = [usr for usr in user_content if usr[1] == user[0]]
context['rows'].append(_set_user(user,))

return context
from django.http import HttpResponseRedirect
from django.views.generic.base import TemplateView
from apps.utils.apcd_database import get_users
from apps.utils.apcd_groups import is_apcd_admin
import logging

logger = logging.getLogger(__name__)


class ViewUsersTable(TemplateView):
template_name = 'view_users.html'
user_content = get_users()

def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated or not is_apcd_admin(request.user):
return HttpResponseRedirect('/')
return super(ViewUsersTable, self).dispatch(request, *args, **kwargs)

def get_context_data(self, *args, **kwargs):
context = super(ViewUsersTable, self).get_context_data(*args, **kwargs)
actions = 'View'
import datetime
user_content = get_users()




def _set_user(usr):
return {
'user_id': usr[0],
'user_email': usr[1],
'user_name': usr[2],
'org_name': usr[3],
'role_id': usr[4],
'created_at': usr[5],
'updated_at': usr[6],
'notes': usr[7],

}

def _set_modal_content(usr):
return {
'notes': usr[7],

}



context['header'] = ['User ID', 'Email', 'Name', 'Organization', 'Role ID', 'Created', 'Updated', 'Notes']
context['rows'] = []
for user in user_content:
user_view = [usr for usr in user_content if usr[1] == user[0]]
context['rows'].append(_set_user(user,))

return context

0 comments on commit 2ff166f

Please sign in to comment.