Add ability to filter audit log by user

This commit is contained in:
rubenwardy 2020-12-09 20:21:20 +00:00
parent d5190b0d76
commit 4433c32afc
2 changed files with 15 additions and 3 deletions

View File

@ -14,8 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask import render_template, request
from app.models import db, AuditLogEntry, UserRank
from flask import render_template, request, abort
from app.models import db, AuditLogEntry, UserRank, User
from app.utils import rank_required, get_int_or_abort
from . import bp
@ -27,7 +27,15 @@ def audit():
page = get_int_or_abort(request.args.get("page"), 1)
num = min(40, get_int_or_abort(request.args.get("n"), 100))
pagination = AuditLogEntry.query.order_by(db.desc(AuditLogEntry.created_at)).paginate(page, num, True)
query = AuditLogEntry.query.order_by(db.desc(AuditLogEntry.created_at))
if "username" in request.args:
user = User.query.filter_by(username=request.args.get("username")).first()
if not user:
abort(404)
query = query.filter_by(causer=user)
pagination = query.paginate(page, num, True)
return render_template("admin/audit.html", log=pagination.items, pagination=pagination)

View File

@ -59,6 +59,10 @@
</tr>
</table>
{% if current_user.rank.atLeast(current_user.rank.MODERATOR) %}
<a class="btn btn-secondary float-right" href="{{ url_for('admin.audit', username=user.username) }}">View All</a>
{% endif %}
<h3>{{ _("Recent Account Actions") }}</h3>
{% from "macros/audit_log.html" import render_audit_log %}