Initial filtering of posts/submissions
This commit is contained in:
parent
3c8798e4da
commit
f231726b3a
11 changed files with 147 additions and 2 deletions
26
files/assets/js/filter_actions.js
Normal file
26
files/assets/js/filter_actions.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
function filter_new_status(id, new_status) {
|
||||
fetch('/admin/update_filter_status', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ post_id: id, new_status: new_status, formkey: formkey() }),
|
||||
headers: { 'content-type': 'application/json' }
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if(json.result === 'Update successful') {
|
||||
const postRow = document.getElementById(`post-${id}`);
|
||||
if(document.location.pathname === '/admin/filtered_submissions') {
|
||||
postRow.parentElement.removeChild(postRow);
|
||||
} else {
|
||||
const approveLink = postRow.querySelector('a#filter-approve')
|
||||
const removeLink = postRow.querySelector('a#filter-remove')
|
||||
approveLink.parentElement.removeChild(approveLink);
|
||||
removeLink.parentElement.removeChild(removeLink);
|
||||
}
|
||||
document.getElementById('toast-post-success-text').innerText = json.result;
|
||||
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success')).show();
|
||||
} else {
|
||||
document.getElementById('toast-post-error-text').innerText = "Error, please try again later."
|
||||
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error')).show();
|
||||
}
|
||||
});
|
||||
}
|
|
@ -51,6 +51,7 @@ class Submission(Base):
|
|||
flair = Column(String)
|
||||
ban_reason = Column(String)
|
||||
embed_url = Column(String)
|
||||
filter_state = Column(String)
|
||||
|
||||
author = relationship("User", primaryjoin="Submission.author_id==User.id")
|
||||
oauth_app = relationship("OauthApp", viewonly=True)
|
||||
|
|
|
@ -26,6 +26,10 @@ def get_logged_in_user():
|
|||
|
||||
if request.method != "GET":
|
||||
submitted_key = request.values.get("formkey")
|
||||
if not submitted_key and request.is_json:
|
||||
json = request.get_json(silent=True)
|
||||
if json and type(json) is dict:
|
||||
submitted_key = json.get('formkey')
|
||||
if not submitted_key: abort(401)
|
||||
if not v.validate_formkey(submitted_key): abort(401)
|
||||
|
||||
|
|
|
@ -400,6 +400,42 @@ def shadowbanned(v):
|
|||
users = [x for x in g.db.query(User).filter(User.shadowbanned != None).order_by(User.shadowbanned).all()]
|
||||
return render_template("shadowbanned.html", v=v, users=users)
|
||||
|
||||
@app.get("/admin/filtered_submissions")
|
||||
@admin_level_required(2)
|
||||
def filtered_submissions(v):
|
||||
try: page = int(request.values.get('page', 1))
|
||||
except: page = 1
|
||||
|
||||
posts_just_ids = g.db.query(Submission) \
|
||||
.order_by(Submission.id.desc()) \
|
||||
.filter(Submission.filter_state == 'filtered') \
|
||||
.limit(26) \
|
||||
.offset(25 * (page - 1)) \
|
||||
.with_entities(Submission.id)
|
||||
|
||||
post_ids = [x.id for x in posts_just_ids]
|
||||
next_exists = (len(post_ids) > 25)
|
||||
posts = get_posts(post_ids[:25], v=v)
|
||||
|
||||
return render_template("admin/filtered_submissions.html", v=v, listing=posts, next_exists=next_exists, page=page, sort="new")
|
||||
|
||||
@app.post("/admin/update_filter_status")
|
||||
@admin_level_required(2)
|
||||
def update_filter_status(v):
|
||||
update_body = request.get_json()
|
||||
new_status = update_body.get('new_status')
|
||||
post_id = update_body.get('post_id')
|
||||
if new_status not in ['normal', 'removed']:
|
||||
return { 'result': f'Status of {new_status} is not permitted' }
|
||||
|
||||
rows_updated = g.db.query(Submission).where(Submission.id == post_id).update({Submission.filter_state: new_status})
|
||||
|
||||
if rows_updated == 1:
|
||||
g.db.commit()
|
||||
return { 'result': 'Update successful' }
|
||||
else:
|
||||
return { 'result': f'Submission ID {post_id} does not exist' }
|
||||
|
||||
|
||||
@app.get("/admin/image_posts")
|
||||
@admin_level_required(2)
|
||||
|
|
|
@ -303,6 +303,12 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false"
|
|||
voted = [x[0] for x in g.db.query(Vote.submission_id).filter_by(user_id=v.id).all()]
|
||||
posts = posts.filter(Submission.id.notin_(voted))
|
||||
|
||||
if not v or v.admin_level < 2:
|
||||
filter_clause = (Submission.filter_state != 'filtered') & (Submission.filter_state != 'removed')
|
||||
if v:
|
||||
filter_clause = filter_clause | (Submission.author_id == v.id)
|
||||
posts = posts.filter(filter_clause)
|
||||
|
||||
if sub: posts = posts.filter_by(sub=sub.name)
|
||||
elif v: posts = posts.filter(or_(Submission.sub == None, Submission.sub.notin_(v.all_blocks)))
|
||||
|
||||
|
|
|
@ -1025,7 +1025,8 @@ def submit_post(v, sub=None):
|
|||
title=title[:500],
|
||||
title_html=title_html,
|
||||
sub=sub,
|
||||
ghost=ghost
|
||||
ghost=ghost,
|
||||
filter_state='filtered' if v.admin_level == 0 else 'normal'
|
||||
)
|
||||
|
||||
g.db.add(post)
|
||||
|
|
|
@ -17,6 +17,11 @@
|
|||
<li><a href="/admin/removed/posts">Removed Posts/Comments</a></li>
|
||||
</ul>
|
||||
|
||||
<h4>Filtering</h4>
|
||||
<ul>
|
||||
<li><a href="/admin/filtered_submissions">Filtered Submissions</a></li>
|
||||
</ul>
|
||||
|
||||
<h4>Users</h4>
|
||||
<ul>
|
||||
<li><a href="/admin/users">Users Feed</a></li>
|
||||
|
|
56
files/templates/admin/filtered_submissions.html
Normal file
56
files/templates/admin/filtered_submissions.html
Normal file
|
@ -0,0 +1,56 @@
|
|||
{% extends "userpage.html" %}
|
||||
|
||||
{% block adminpanel %}{% endblock %}
|
||||
{% block pagetype %}userpage{% endblock %}
|
||||
{% block banner %}{% endblock %}
|
||||
{% block mobileBanner %}{% endblock %}
|
||||
{% block desktopBanner %}{% endblock %}
|
||||
{% block desktopUserBanner %}{% endblock %}
|
||||
{% block mobileUserBanner %}{% endblock %}
|
||||
|
||||
{% block postNav %}{% endblock %}
|
||||
|
||||
{% block fixedMobileBarJS %}
|
||||
{% endblock %}
|
||||
|
||||
{% block title %}
|
||||
<title>Filtered Submissions</title>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="row no-gutters">
|
||||
|
||||
<div class="col">
|
||||
|
||||
{% block listing %}
|
||||
<div class="posts">
|
||||
{% include "submission_listing.html" %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block pagenav %}
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm py-3 pl-3 mb-0">
|
||||
{% if page>1 %}
|
||||
<li class="page-item">
|
||||
<small><a class="page-link" href="?page={{page-1}}" tabindex="-1">Prev</a></small>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled"><span class="page-link">Prev</span></li>
|
||||
{% endif %}
|
||||
{% if next_exists %}
|
||||
<li class="page-item">
|
||||
<small><a class="page-link" href="?page={{page+1}}">Next</a></small>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled"><span class="page-link">Next</span></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% endblock %}
|
|
@ -33,6 +33,11 @@
|
|||
<a id="delete2-{{p.id}}" class="{% if p.deleted_utc %}d-none{% endif %} list-inline-item" role="button" data-bs-toggle="modal" data-bs-dismiss="modal" data-bs-target="#deletePostModal" onclick="delete_postModal('{{p.id}}')"><i class="fas fa-trash-alt"></i>Delete</a>
|
||||
{% endif %}
|
||||
|
||||
{% if v and v.admin_level > 2 and p.filter_state == 'filtered' %}
|
||||
<a id="filter-approve" class="list-inline-item" role="button" onclick="filter_new_status({{p.id}}, 'normal')">Approve</a>
|
||||
<a id="filter-remove" class="list-inline-item" role="button" onclick="filter_new_status({{p.id}}, 'removed')">Remove</a>
|
||||
{% endif %}
|
||||
|
||||
{% if v %}
|
||||
<a class="list-inline-item" role="button" data-bs-toggle="dropdown" aria-expanded="false"><i class="fas fa-ellipsis-h fa-fw"></i></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
<script src="/assets/js/new_comments_count.js?v=242"></script>
|
||||
{% endif %}
|
||||
|
||||
{% if v and v.admin_level > 2 %}
|
||||
<script src="/assets/js/filter_actions.js?v=2"></script>
|
||||
{% endif %}
|
||||
|
||||
<div style="display:none" id="popover">
|
||||
<div class="popover-user-profile" role="tooltip">
|
||||
<img loading="lazy" class="pop-banner w-100 h-64 object-cover">
|
||||
|
|
|
@ -99,7 +99,8 @@ CREATE TABLE public.submissions (
|
|||
flair character varying(350),
|
||||
stickied_utc integer,
|
||||
ghost boolean DEFAULT false NOT NULL,
|
||||
sub character varying(20)
|
||||
sub character varying(20),
|
||||
filter_state character varying(40) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue