Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jdabtieu/CTFOJ into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jdabtieu committed Dec 16, 2020
2 parents c01087d + 8ff3036 commit 0b4a87d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Otherwise, email [jdabtieu](mailto:jonathan.wu3@outlook.com) for other support.

## Usage
If you have logged in with an administrator account, you will be able to manage the site through
the "Admin Tools" interface. This includes the ability to create practice problems, contests, and announcements.
the "Admin Console" interface. This includes the ability to create practice problems, contests, and announcements.
Additionally, you will be able to manage users and view submissions.

## Contributing
Expand Down
7 changes: 6 additions & 1 deletion application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,10 @@ def delete_problem(problem_id):
flash('Problem successfully deleted', 'success')
return redirect("/problems")

@app.route("/admin/console")
@admin_required
def admin_console():
return render_template("admin/console.html", maintenance_mode=maintenance_mode)

@app.route("/admin/submissions")
@admin_required
Expand Down Expand Up @@ -1386,7 +1390,8 @@ def editcontest(contest_id):
def maintenance():
global maintenance_mode
maintenance_mode = not maintenance_mode
return "Enabled maintenance mode" if maintenance_mode else "Disabled maintenance mode"
flash("Enabled maintenance mode" if maintenance_mode else "Disabled maintenance mode", "success")
return redirect('/admin/console')


def errorhandler(e):
Expand Down
9 changes: 5 additions & 4 deletions assets/css/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/****************** PROBLEM PAGE LAYOUT **********************/
.flag-submit {
width: 90%;
display: inline;
Expand Down Expand Up @@ -62,6 +63,10 @@ div.md-preview {
width: 16px;
}

table {
table-layout: fixed;
}

/****************** COLOURS **********************************/
.white {
color: #ffffff!important;
Expand All @@ -78,7 +83,3 @@ div.md-preview {
.svg-green {
filter: invert(57%) sepia(58%) saturate(3606%) hue-rotate(83deg) brightness(118%) contrast(125%);
}

table {
table-layout: fixed;
}
30 changes: 30 additions & 0 deletions templates/admin/console.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "layout.html" %}

{% block title %}Admin Console{% endblock %}

{% block main %}
<h1>Admin Console</h1>
<a class="btn btn-primary" href="/admin/submissions" role="button">Submissions</a>
<br>
<br>
<a class="btn btn-primary" href="/admin/users" role="button">Users</a>
<br>
<br>
<a class="btn btn-primary" href="/admin/createannouncement" role="button">Create Announcement</a>
<br>
<br>
<a class="btn btn-primary" href="/admin/createcontest" role="button">Create Contest</a>
<br>
<br>
<a class="btn btn-primary" href="/admin/createproblem" role="button">Create Problem</a>
<br>
<br>
<a class="btn btn-primary" href="/problems/draft" role="button">Draft Problems</a>
<hr>
<p>The only thing maintenance mode should be used for is to make significant changes to the database that requires nobody writes to it during that time, as well as 5 minutes before a reboot to let users know that the site will be down momentarily. If the application is rebooted, maintenance mode will turn itself off.</p>
{% if maintenance_mode %}
<a class="btn btn-primary" href="/admin/maintenance" role="button">Disable Maintenance Mode</a>
{% else %}
<a class="btn btn-primary" href="/admin/maintenance" role="button">Enable Maintenance Mode</a>
{% endif %}
{% endblock %}
12 changes: 1 addition & 11 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,7 @@
<li><a class="nav-link" href="/problems">Practice</a></li>
<li><a class="nav-link" href="/contests">Contests</a></li>
{% if session.admin %}
<li class="dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" data-toggle="dropdown">Admin Tools</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="/admin/submissions">Submissions</a>
<a class="dropdown-item" href="/admin/users">Users</a>
<a class="dropdown-item" href="/admin/createcontest">Create Contest</a>
<a class="dropdown-item" href="/admin/createproblem">Create Problem</a>
<a class="dropdown-item" href="/admin/createannouncement">Create Announcement</a>
<a class="dropdown-item" href="/problems/draft">Draft Problems</a>
</div>
</li>
<li><a class="nav-link" href="/admin/console">Admin Console</a></li>
{% endif %}
</ul>
<ul class="navbar-nav ml-auto">
Expand Down
16 changes: 16 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ def test_admin(client, database):
result = client.get('/admin/users')
assert result.status_code == 200
assert b'Users' in result.data

result = client.get('/admin/createannouncement')
assert result.status_code == 200
assert b'Create Announcement' in result.data

result = client.get('/admin/createcontest')
assert result.status_code == 200
assert b'Create Contest' in result.data

result = client.get('/admin/createproblem')
assert result.status_code == 200
assert b'Create Problem' in result.data

result = client.get('/problems/draft')
assert result.status_code == 200
assert b'Draft' in result.data
client.get('/logout')

# Normal users should be redirected to home
Expand Down

0 comments on commit 0b4a87d

Please sign in to comment.