Skip to content

Commit 0f9073d

Browse files
committed
Add user log page
1 parent 9f71dce commit 0f9073d

File tree

7 files changed

+105
-30
lines changed

7 files changed

+105
-30
lines changed

conditional/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unused
9090
from conditional.blueprints.slideshow import slideshow_bp
9191
from conditional.blueprints.cache_management import cache_bp
9292
from conditional.blueprints.co_op import co_op_bp
93+
from conditional.blueprints.logs import log_bp
9394

9495
app.register_blueprint(dashboard_bp)
9596
app.register_blueprint(attendance_bp)
@@ -103,6 +104,7 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unused
103104
app.register_blueprint(slideshow_bp)
104105
app.register_blueprint(cache_bp)
105106
app.register_blueprint(co_op_bp)
107+
app.register_blueprint(log_bp)
106108

107109
from conditional.util.ldap import ldap_get_member
108110

conditional/blueprints/cache_management.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def clear_cache():
4141
user_name = request.headers.get('x-webauth-user')
4242
account = ldap_get_member(user_name)
4343

44-
if not ldap_is_eval_director(account) or not ldap_is_rtp(account):
44+
if not ldap_is_eval_director(account) and not ldap_is_rtp(account):
4545
return redirect("/dashboard")
4646

4747
log = logger.new(request=request)

conditional/blueprints/logs.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import structlog
2+
3+
from flask import Blueprint, request
4+
5+
from conditional.models.models import UserLog
6+
7+
from conditional.util.ldap import ldap_is_eboard
8+
from conditional.util.ldap import ldap_is_rtp
9+
from conditional.util.ldap import ldap_get_member
10+
11+
from conditional.util.flask import render_template
12+
13+
logger = structlog.get_logger()
14+
15+
log_bp = Blueprint('log_bp', __name__)
16+
17+
@log_bp.route('/logs')
18+
def display_logs():
19+
log = logger.new(request=request)
20+
log.info('Display Logs')
21+
22+
username = request.headers.get('x-webauth-user')
23+
account = ldap_get_member(username)
24+
log.info(account.displayName)
25+
26+
if not ldap_is_eboard(account) and not ldap_is_rtp(account):
27+
return "must be rtp or eboard", 403
28+
29+
logs = UserLog.query.all()
30+
31+
return render_template(request, "logs.html", logs=logs, username=username)

conditional/blueprints/member_management.py

+27-24
Original file line numberDiff line numberDiff line change
@@ -224,30 +224,33 @@ def edit_uid(uid, flask_request):
224224
account = ldap_get_member(uid)
225225
active_member = post_data['activeMember']
226226

227-
room_number = post_data['roomNumber']
228-
onfloor_status = post_data['onfloorStatus']
229-
housing_points = post_data['housingPoints']
230-
log.info('Edit {} - Room: {} On-Floor: {} Points: {}'.format(
231-
uid,
232-
post_data['roomNumber'],
233-
post_data['onfloorStatus'],
234-
post_data['housingPoints']))
235-
236-
ldap_set_roomnumber(account, room_number)
237-
if onfloor_status:
238-
# If a OnFloorStatusAssigned object exists, don't make another
239-
if not ldap_is_member_of_group(account, "onfloor"):
240-
db.session.add(OnFloorStatusAssigned(uid, datetime.now()))
241-
ldap_add_member_to_group(account, "onfloor")
242-
else:
243-
for ofs in OnFloorStatusAssigned.query.filter(OnFloorStatusAssigned.uid == uid):
244-
db.session.delete(ofs)
245-
db.session.flush()
246-
db.session.commit()
247-
248-
if ldap_is_member_of_group(account, "onfloor"):
249-
ldap_remove_member_from_group(account, "onfloor")
250-
ldap_set_housingpoints(account, housing_points)
227+
username = flask_request.headers.get('x-webauth-user')
228+
current_account = ldap_get_member(username)
229+
if ldap_is_eval_director(current_account):
230+
room_number = post_data['roomNumber']
231+
onfloor_status = post_data['onfloorStatus']
232+
housing_points = post_data['housingPoints']
233+
log.info('Edit {} - Room: {} On-Floor: {} Points: {}'.format(
234+
uid,
235+
post_data['roomNumber'],
236+
post_data['onfloorStatus'],
237+
post_data['housingPoints']))
238+
239+
ldap_set_roomnumber(account, room_number)
240+
if onfloor_status:
241+
# If a OnFloorStatusAssigned object exists, don't make another
242+
if not ldap_is_member_of_group(account, "onfloor"):
243+
db.session.add(OnFloorStatusAssigned(uid, datetime.now()))
244+
ldap_add_member_to_group(account, "onfloor")
245+
else:
246+
for ofs in OnFloorStatusAssigned.query.filter(OnFloorStatusAssigned.uid == uid):
247+
db.session.delete(ofs)
248+
db.session.flush()
249+
db.session.commit()
250+
251+
if ldap_is_member_of_group(account, "onfloor"):
252+
ldap_remove_member_from_group(account, "onfloor")
253+
ldap_set_housingpoints(account, housing_points)
251254

252255
# Only update if there's a diff
253256
log.info('Set {} Active: {}'.format(uid, active_member))

conditional/templates/logs.html

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{% extends "nav.html" %}
2+
{% block title %}
3+
User Logs
4+
{% endblock %}
5+
{% block body %}
6+
7+
<div class="container main">
8+
<h3 class="page-title">User Logs</h3>
9+
<div class="panel panel-default">
10+
<div class="panel-body table-fill">
11+
<table class="table table-striped no-bottom-margin" data-module="table" data-searchable="true" data-sort-column="0" data-sort-order="desc" data-length-changable="true" data-page-length="100">
12+
<thead>
13+
<th>ID</th>
14+
<th>Method</th>
15+
<th>User</th>
16+
<th>Blueprint</th>
17+
<th>URL</th>
18+
<th>Description</th>
19+
</thead>
20+
<tbody>
21+
{% for log in logs %}
22+
<tr>
23+
<td>{{log.timestamp}}</td>
24+
<td>{{log.method}}</td>
25+
<td>{{log.uid}}</td>
26+
<td>{{log.blueprint}}</td>
27+
<td>{{log.path}}</td>
28+
<td>{{log.description}}</td>
29+
</tr>
30+
{% endfor %}
31+
</tbody>
32+
</table>
33+
</div>
34+
</div>
35+
</div>
36+
{% endblock %}

conditional/templates/nav.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
</li>
3434

3535
<li><a href="/housing"><span class="glyphicon glyphicon-home"></span> Housing</a></li>
36-
36+
3737
<li class="dropdown">
38-
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-ok"></span> Attendance
38+
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-ok"></span> Attendance
3939
{% if is_eboard and pending_review != 0 %}
4040
({{pending_review}})
4141
{% endif %}
@@ -51,8 +51,8 @@
5151
{% endif %}
5252
</ul>
5353
</li>
54-
55-
{% if is_eval_director or is_financial_director or is_rtp%}
54+
55+
{% if is_eboard or is_rtp%}
5656
<li class="dropdown">
5757
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-wrench"></span> Admin<span class="caret"></span></a>
5858
<ul class="dropdown-menu">
@@ -67,6 +67,8 @@
6767
<li><a href="/slideshow/spring"><span class="glyphicon glyphicon-eye-open"></span> Membership Evaluations Presentation</a></li>
6868
{% endif %}
6969

70+
<li><a href="/logs"><span class="glyphicon glyphicon-list"></span> User Logs</a></li>
71+
7072
{% if is_eval_director or is_rtp %}
7173
<li><a href="/clearcache"><span class="glyphicon glyphicon-floppy-remove"></span> Clear Cache</a></li>
7274
{% endif %}

frontend/javascript/modules/table.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default class Table {
1717
info: false,
1818
paging: !(this.table.dataset.paginated === 'false'),
1919
pagingType: "numbers",
20-
order: []
20+
order: [],
21+
pageLength: this.table.dataset.pageLength || 10
2122
};
2223

2324
// Just remove the search input from the DOM instead of disabling it

0 commit comments

Comments
 (0)