Allow author deletes chat
This commit is contained in:
parent
34e8ac6b8e
commit
1f91299d41
3 changed files with 38 additions and 29 deletions
|
@ -37,6 +37,8 @@ from judge.models import Friend
|
||||||
from chat_box.models import Message, Profile, Room, UserRoom, Ignore, get_room_info
|
from chat_box.models import Message, Profile, Room, UserRoom, Ignore, get_room_info
|
||||||
from chat_box.utils import encrypt_url, decrypt_url, encrypt_channel, get_unread_boxes
|
from chat_box.utils import encrypt_url, decrypt_url, encrypt_channel, get_unread_boxes
|
||||||
|
|
||||||
|
from reversion import revisions
|
||||||
|
|
||||||
|
|
||||||
class ChatView(ListView):
|
class ChatView(ListView):
|
||||||
context_object_name = "message"
|
context_object_name = "message"
|
||||||
|
@ -137,15 +139,15 @@ def delete_message(request):
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
if not request.user.is_staff:
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
messid = int(request.POST.get("message"))
|
messid = int(request.POST.get("message"))
|
||||||
mess = Message.objects.get(id=messid)
|
mess = Message.objects.get(id=messid)
|
||||||
except:
|
except:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
if not request.user.is_staff and request.profile != mess.author:
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
mess.hidden = True
|
mess.hidden = True
|
||||||
mess.save()
|
mess.save()
|
||||||
|
|
||||||
|
@ -167,8 +169,12 @@ def mute_message(request):
|
||||||
except:
|
except:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
with revisions.create_revision():
|
||||||
|
revisions.set_comment(_("Mute chat") + ": " + mess.body)
|
||||||
|
revisions.set_user(request.user)
|
||||||
mess.author.mute = True
|
mess.author.mute = True
|
||||||
mess.author.save()
|
mess.author.save()
|
||||||
|
|
||||||
Message.objects.filter(room=None, author=mess.author).update(hidden=True)
|
Message.objects.filter(room=None, author=mess.author).update(hidden=True)
|
||||||
|
|
||||||
return JsonResponse(ret)
|
return JsonResponse(ret)
|
||||||
|
|
|
@ -411,7 +411,6 @@
|
||||||
|
|
||||||
scrollContainer($('#chat-box'), $('#loader'))
|
scrollContainer($('#chat-box'), $('#loader'))
|
||||||
|
|
||||||
{% if request.user.is_staff %}
|
|
||||||
$(document).on("click", ".chat_remove", function() {
|
$(document).on("click", ".chat_remove", function() {
|
||||||
var elt = $(this);
|
var elt = $(this);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -435,6 +434,8 @@
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
{% if request.user.is_staff %}
|
||||||
$(document).on("click", ".chat_mute", function() {
|
$(document).on("click", ".chat_mute", function() {
|
||||||
if (confirm("{{_('Mute this user and delete all messages?')}}")) {
|
if (confirm("{{_('Mute this user and delete all messages?')}}")) {
|
||||||
var elt = $(this);
|
var elt = $(this);
|
||||||
|
|
|
@ -15,10 +15,12 @@
|
||||||
</div>
|
</div>
|
||||||
<span class="content-message">
|
<span class="content-message">
|
||||||
<div class="body-block" id="body-block-{{ message.id }}" title="{{ message.time|date('g:i a') }}">
|
<div class="body-block" id="body-block-{{ message.id }}" title="{{ message.time|date('g:i a') }}">
|
||||||
{% if request.user.is_staff %}
|
{% if request.user.is_staff or request.profile == message.author %}
|
||||||
<a class="red chatbtn_remove_mess chat_remove" value="{{message.id}}" style="cursor: pointer;">
|
<a class="red chatbtn_remove_mess chat_remove" value="{{message.id}}" style="cursor: pointer;">
|
||||||
{{_('Delete')}}
|
{{_('Delete')}}
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if request.user.is_staff and request.profile != message.author %}
|
||||||
<a class="red chatbtn_remove_mess chat_mute" value="{{message.id}}" style="cursor: pointer;">
|
<a class="red chatbtn_remove_mess chat_mute" value="{{message.id}}" style="cursor: pointer;">
|
||||||
{{_('Mute')}}
|
{{_('Mute')}}
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Reference in a new issue