|
|
@ -2,6 +2,7 @@ from datetime import datetime, timedelta
|
|
|
|
from os import path, remove
|
|
|
|
from os import path, remove
|
|
|
|
from io import BytesIO
|
|
|
|
from io import BytesIO
|
|
|
|
from base64 import b64encode
|
|
|
|
from base64 import b64encode
|
|
|
|
|
|
|
|
from sys import audit
|
|
|
|
from qrcode import make as qrcode_make
|
|
|
|
from qrcode import make as qrcode_make
|
|
|
|
from flask import render_template, Blueprint, request, session, flash
|
|
|
|
from flask import render_template, Blueprint, request, session, flash
|
|
|
|
from flask import send_from_directory, redirect, url_for, current_app
|
|
|
|
from flask import send_from_directory, redirect, url_for, current_app
|
|
|
@ -12,8 +13,7 @@ from suchwow import config
|
|
|
|
from suchwow.models import Post, Profile, Comment, Ban
|
|
|
|
from suchwow.models import Post, Profile, Comment, Ban
|
|
|
|
from suchwow.utils.decorators import login_required, profile_required, moderator_required
|
|
|
|
from suchwow.utils.decorators import login_required, profile_required, moderator_required
|
|
|
|
from suchwow.utils.helpers import allowed_file, is_moderator, get_session_user
|
|
|
|
from suchwow.utils.helpers import allowed_file, is_moderator, get_session_user
|
|
|
|
from suchwow.utils.helpers import rw_cache, post_webhook
|
|
|
|
from suchwow.utils.helpers import post_webhook, audit_event
|
|
|
|
from suchwow.reddit import make_post
|
|
|
|
|
|
|
|
from suchwow.discord import post_discord_webhook
|
|
|
|
from suchwow.discord import post_discord_webhook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -57,7 +57,6 @@ def create():
|
|
|
|
submitter = get_session_user()
|
|
|
|
submitter = get_session_user()
|
|
|
|
u = Profile.filter(username=submitter)
|
|
|
|
u = Profile.filter(username=submitter)
|
|
|
|
banned = Ban.filter(user=u).first()
|
|
|
|
banned = Ban.filter(user=u).first()
|
|
|
|
print(banned)
|
|
|
|
|
|
|
|
if banned:
|
|
|
|
if banned:
|
|
|
|
flash(f"You can't post: {banned.reason}", "is-danger")
|
|
|
|
flash(f"You can't post: {banned.reason}", "is-danger")
|
|
|
|
return redirect("/")
|
|
|
|
return redirect("/")
|
|
|
@ -105,7 +104,7 @@ def create():
|
|
|
|
post.save()
|
|
|
|
post.save()
|
|
|
|
post.save_thumbnail()
|
|
|
|
post.save_thumbnail()
|
|
|
|
url = url_for('post.read', id=post.id, _external=True)
|
|
|
|
url = url_for('post.read', id=post.id, _external=True)
|
|
|
|
post_webhook(f"New post :doge2: [{post.id}]({url}) by `{submitter}` :neckbeard:")
|
|
|
|
audit_event(f'Created new post {post.id}')
|
|
|
|
flash("New post created and pending approval!", "is-success")
|
|
|
|
flash("New post created and pending approval!", "is-success")
|
|
|
|
return redirect(url_for("main.index"))
|
|
|
|
return redirect(url_for("main.index"))
|
|
|
|
return render_template("post/create.html")
|
|
|
|
return render_template("post/create.html")
|
|
|
@ -119,11 +118,10 @@ def approve(id):
|
|
|
|
if not post.approved:
|
|
|
|
if not post.approved:
|
|
|
|
post.approved = True
|
|
|
|
post.approved = True
|
|
|
|
post.save()
|
|
|
|
post.save()
|
|
|
|
post_webhook(f"Post [{post.id}]({url}) approved :white_check_mark: by `{get_session_user()}` :fieri_parrot:")
|
|
|
|
|
|
|
|
flash("Approved", "is-success")
|
|
|
|
flash("Approved", "is-success")
|
|
|
|
|
|
|
|
audit_event(f'Approved post {post.id}')
|
|
|
|
if current_app.config["DEBUG"] is False:
|
|
|
|
if current_app.config["DEBUG"] is False:
|
|
|
|
post_discord_webhook(post)
|
|
|
|
post_discord_webhook(post)
|
|
|
|
post_webhook(f"Post [{post.id}]({url}) submitted :dab_parrot: to Discord.")
|
|
|
|
|
|
|
|
return redirect(url_for("mod.pending_posts"))
|
|
|
|
return redirect(url_for("mod.pending_posts"))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
flash("You can't approve this", "is-success")
|
|
|
|
flash("You can't approve this", "is-success")
|
|
|
@ -141,8 +139,8 @@ def delete(id):
|
|
|
|
save_path_base = path.join(current_app.config["DATA_FOLDER"], "uploads")
|
|
|
|
save_path_base = path.join(current_app.config["DATA_FOLDER"], "uploads")
|
|
|
|
save_path = path.join(save_path_base, post.image_name)
|
|
|
|
save_path = path.join(save_path_base, post.image_name)
|
|
|
|
remove(save_path)
|
|
|
|
remove(save_path)
|
|
|
|
|
|
|
|
audit_event(f'Deleted post {post.id}')
|
|
|
|
post.delete_instance()
|
|
|
|
post.delete_instance()
|
|
|
|
post_webhook(f"Post {post.id} deleted :dumpsterfire: by `{user}` :godmode:")
|
|
|
|
|
|
|
|
flash("Deleted that shit, brah!", "is-success")
|
|
|
|
flash("Deleted that shit, brah!", "is-success")
|
|
|
|
if is_mod:
|
|
|
|
if is_mod:
|
|
|
|
return redirect(url_for("mod.pending_posts"))
|
|
|
|
return redirect(url_for("mod.pending_posts"))
|
|
|
|