Add post and image deletion

This one was kind of a doozy. This also adds a custom 403 error page and
fixes some permission denied behavior that I was having issues with for
a while.

This is also set up in a way that hopefully will allow me to easily
implement user post deletion.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-07-13 15:19:20 -07:00
parent 6ff64a3299
commit 83533b5fb4
9 changed files with 147 additions and 3 deletions

8
board/templates/403.html Normal file
View File

@@ -0,0 +1,8 @@
{% extends "board/base.html" %}
{% block title %}
Permission denied
{% endblock title %}
{% block content %}
<h3>You do not have permission to do this.</h3>
{% endblock content %}

View File

@@ -0,0 +1,23 @@
{% extends "board/base.html" %}
{% load i18n %}
{% block content %}
<form id="form" method="post" action="{% url 'board:post_delete' post.id %}">
{% csrf_token %}
<table>
<tr>
<td><input type="submit" value="{% translate 'Delete post' %}" /></td>
<td><input id="delete_image" type="submit" value="{% translate 'Delete image only' %}" /></td>
</tr>
</table>
{{form.image_only}}
</form>
<script>
$(document).on("click","#delete_image", (e) => {
e.preventDefault();
$("#{{form.image_only.auto_id}}").val(1);
$("#form").submit();
});
</script>
{% endblock content %}

View File

@@ -0,0 +1,33 @@
{% extends "board/base.html" %}
{% load i18n static %}
{# Title #}
{% block title %}{% translate "Post delete success" %}{% endblock %}
{# Body #}
{% block content %}
<div class="row" id="message">
{# We do not use pluralize filter for "seconds" because it's a pain to get it to translate. #}
{% blocktranslate %}Delete successful. This window will close in {{window_timeout}} second(s).{% endblocktranslate %}
</div>
<script>
function isIframe() {
try {
return window.self !== window.top;
} catch (_) {
return true;
}
}
setTimeout(function() {
if(isIframe()) {
let deleteWindow = getDeleteWindow();
if(deleteWindow) {
deleteWindow.closeFrame();
}
} else {
window.close();
}
}, 1000 * {{window_timeout}});
</script>
{% endblock %}

View File

@@ -4,6 +4,7 @@
id="p{{post.id}}"
class="post"
data-report-url="{% url 'board:report_form' board.url post.id %}"
data-delete-url="{% url 'board:post_delete' post.id %}"
{% if perms.board.add_ban %}
data-ban-url="{% url 'board:ban_create' board.url post.id %}"
{% endif %}