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()
|
||||||
|
|
||||||
mess.author.mute = True
|
with revisions.create_revision():
|
||||||
mess.author.save()
|
revisions.set_comment(_("Mute chat") + ": " + mess.body)
|
||||||
|
revisions.set_user(request.user)
|
||||||
|
mess.author.mute = True
|
||||||
|
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,30 +411,31 @@
|
||||||
|
|
||||||
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({
|
url: "{{ url('delete_chat_message') }}",
|
||||||
url: "{{ url('delete_chat_message') }}",
|
type: 'post',
|
||||||
type: 'post',
|
data: {
|
||||||
data: {
|
message: elt.attr('value'),
|
||||||
message: elt.attr('value'),
|
},
|
||||||
},
|
dataType: 'json',
|
||||||
dataType: 'json',
|
success: function(data){
|
||||||
success: function(data){
|
var $block = elt.parent();
|
||||||
var $block = elt.parent();
|
if ($block.parent().find('.body-block').length > 1) {
|
||||||
if ($block.parent().find('.body-block').length > 1) {
|
$block.remove();
|
||||||
$block.remove();
|
}
|
||||||
}
|
else {
|
||||||
else {
|
elt.closest('li').remove();
|
||||||
elt.closest('li').remove();
|
}
|
||||||
}
|
},
|
||||||
},
|
fail: function(data) {
|
||||||
fail: function(data) {
|
console.log('Fail to delete');
|
||||||
console.log('Fail to delete');
|
},
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
{% 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