Skip to content

Commit

Permalink
add ban button to player pages
Browse files Browse the repository at this point in the history
  • Loading branch information
sbezboro committed Aug 9, 2016
1 parent a66f5d7 commit 90c667f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
44 changes: 34 additions & 10 deletions standardweb/templates/player.html
Expand Up @@ -26,17 +26,20 @@
<div class="section-header">
<div class="pull-right align-right">
{% if current_user and player.user != current_user %}
{% if current_user.admin_or_moderator and player.user %}
{% if player.user.forum_ban %}
Forum banned
{% else %}
<a class="btn btn-lite btn-danger confirm" href="{{ url_for('forum_ban', user_id=player.user.id) }}">Forum Ban</a>
{% endif %}
{% with profile = player.user.forum_profile %}
{% if profile and profile.post_count %}
<a class="btn btn-lite btn-danger confirm" data-confirm-message="Are you absolutely sure? There is no way to undo this!" href="{{ url_for('delete_user_forum_posts', user_id=player.user.id) }}">Delete All Forum Posts</a>
{% if current_user.admin_or_moderator %}
<a class="btn btn-lite btn-danger ban" href="#">Server Ban</a>
{% if player.user %}
{% if player.user.forum_ban %}
Forum banned
{% else %}
<a class="btn btn-lite btn-danger confirm" href="{{ url_for('forum_ban', user_id=player.user.id) }}">Forum Ban</a>
{% endif %}
{% endwith %}
{% with profile = player.user.forum_profile %}
{% if profile and profile.post_count %}
<a class="btn btn-lite btn-danger confirm" data-confirm-message="Are you absolutely sure? There is no way to undo this!" href="{{ url_for('delete_user_forum_posts', user_id=player.user.id) }}">Delete All Forum Posts</a>
{% endif %}
{% endwith %}
{% endif %}
{% endif %}
<a class="btn btn-lite" href="{{ url_for('messages', username=player.username) }}">Send Message</a>
{% endif %}
Expand Down Expand Up @@ -314,6 +317,27 @@ <h2>No record of {{ username or 'that player'}} having played on any server</h2>
</script>
{% if current_user and current_user.admin %}
<script type="application/javascript">
$('.ban').on('click', function() {
var dialog = new StandardWeb.InputDialog('Server Ban', 'Reason:', '');
dialog.positiveCallback = function(inputValue) {
$.ajax({
url: "{{ url_for('ban_player', uuid=player.uuid) }}",
type: 'POST',
data: {reason: inputValue},
success: function() {
dialog.close();
StandardWeb.alertManager.addAlert('success', 'Player banned from all servers!');
},
error: function() {
dialog.close();
StandardWeb.alertManager.addAlert('error', 'There was a problem banning the user, please try again.');
}
});
};

dialog.show();
return false;
});
$('.adjust-time').on('click', function() {
var dialog = new StandardWeb.InputDialog('Adjust player time', 'Adjustment:', 'minutes');
dialog.positiveCallback = function(inputValue) {
Expand Down
17 changes: 17 additions & 0 deletions standardweb/views/player.py
Expand Up @@ -2,6 +2,7 @@
from sqlalchemy.orm import joinedload

from standardweb import app
from standardweb.lib import api
from standardweb.lib import helpers as h
from standardweb.lib import player as libplayer
from standardweb.models import Server, Player, User, IPTracking
Expand Down Expand Up @@ -120,3 +121,19 @@ def adjust_player_time(server_id, uuid):
return jsonify({
'err': 0
})


@login_required(only_moderator=True)
@app.route('/player/<uuid>/ban', methods=['POST'])
def ban_player(uuid):
player = Player.query.filter_by(uuid=uuid).first()
if not player:
abort(404)

reason = request.form.get('reason') or None

api.ban_player(player, reason=reason)

return jsonify({
'err': 0
})

0 comments on commit 90c667f

Please sign in to comment.