diff --git a/files/routes/admin.py b/files/routes/admin.py index 254d7960ad..4be2e85917 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -436,7 +436,8 @@ def badge_grant_post(v): g.db.add(user) - g.db.commit() + + g.db.commit() return redirect("/admin/badge_grant") diff --git a/files/routes/awards.py b/files/routes/awards.py index 8e2aeb4374..eab24e95fe 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -200,14 +200,13 @@ ALLOW_MULTIPLE = ( @app.post("/post//awards") @auth_required -@validate_formkey def award_post(pid, v): if v.is_suspended and v.unban_utc == 0: return {"error": "forbidden."}, 403 kind = request.form.get("kind", "") - + if kind not in AWARDS: return {"error": "That award doesn't exist."}, 404 @@ -260,12 +259,11 @@ def award_post(pid, v): g.db.add(post.author) g.db.commit() - return {"message": "Award given!"} + return redirect(request.referrer) @app.post("/comment//awards") @auth_required -@validate_formkey def award_comment(cid, v): if v.is_suspended and v.unban_utc == 0: @@ -325,7 +323,7 @@ def award_comment(cid, v): g.db.add(c.author) g.db.commit() - return {"message": "Award given!"} + return redirect(request.referrer) @app.get("/admin/user_award") @auth_required diff --git a/files/routes/comments.py b/files/routes/comments.py index 0ce640bda0..59cf01d6f0 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -161,7 +161,7 @@ def api_comment(v): if not body and not request.files.get('file'): return {"error":"You need to actually write something!"}, 400 - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF|9999))', body, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') body = body.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") body_md = CustomRenderer().render(mistletoe.Document(body)) @@ -607,7 +607,7 @@ def edit_comment(cid, v): if c.is_banned or c.deleted_utc > 0: abort(403) body = request.form.get("body", "")[:10000] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF|9999))', body, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') body = body.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") body_md = CustomRenderer().render(mistletoe.Document(body)) diff --git a/files/routes/login.py b/files/routes/login.py index 230e371c4a..35276d3368 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -47,17 +47,29 @@ def check_for_alts(current_id): otheralts = g.db.query(Alt).options(lazyload('*')).filter(or_(Alt.user1 == past_id, Alt.user2 == past_id, Alt.user1 == current_id, Alt.user2 == current_id)).all() for a in otheralts: - new_alt = Alt(user1=a.user1, user2=past_id) - g.db.add(new_alt) + try: + new_alt = Alt(user1=a.user1, user2=past_id) + g.db.add(new_alt) + g.db.flush() + except: g.db.rollback() for a in otheralts: - new_alt = Alt(user1=a.user1, user2=current_id) - g.db.add(new_alt) + try: + new_alt = Alt(user1=a.user1, user2=current_id) + g.db.add(new_alt) + g.db.flush() + except: g.db.rollback() for a in otheralts: - new_alt = Alt(user1=a.user2, user2=past_id) - g.db.add(new_alt) + try: + new_alt = Alt(user1=a.user2, user2=past_id) + g.db.add(new_alt) + g.db.flush() + except: g.db.rollback() for a in otheralts: - new_alt = Alt(user1=a.user2, user2=current_id) - g.db.add(new_alt) + try: + new_alt = Alt(user1=a.user2, user2=current_id) + g.db.add(new_alt) + g.db.flush() + except: g.db.rollback() # login post procedure diff --git a/files/routes/posts.py b/files/routes/posts.py index 14202889bc..1ee65b8cab 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -33,7 +33,7 @@ def toggle_club(pid, v): post = get_post(pid) - if (post.author_id != v.id or v.club_banned) and not v.admin_level >= 3: abort(403) + if post.author_id != v.id or not v.paid_dues: abort(403) post.club = not post.club g.db.add(post) @@ -251,7 +251,7 @@ def edit_post(pid, v): p.title_html = filter_title(title) if body != p.body: - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF|9999))', body, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') body_md = CustomRenderer().render(mistletoe.Document(body)) body_html = sanitize(body_md) @@ -803,7 +803,7 @@ def submit_post(v): else: return render_template("submit.html", v=v, error="2048 character limit for URLs.", title=title, url=url,body=request.form.get("body", "")), 400 # render text - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF|9999))', body, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') body = body.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") body_md = CustomRenderer().render(mistletoe.Document(body)) @@ -859,9 +859,12 @@ def submit_post(v): # check for embeddable video domain = parsed_url.netloc + if v.paid_dues: club = bool(request.form.get("club","")) + else: club = False + new_post = Submission( private=bool(request.form.get("private","")), - club=bool(request.form.get("club","")), + club=club, author_id=v.id, over_18=bool(request.form.get("over_18","")), app_id=v.client.application.id if v.client else None, diff --git a/files/routes/settings.py b/files/routes/settings.py index dc78ccb2ae..d138fd7064 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -102,7 +102,7 @@ def settings_profile_post(v): if request.values.get("bio"): bio = request.values.get("bio")[:1500] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF|9999))', bio, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', bio, re.MULTILINE): if "wikipedia" not in i.group(1): bio = bio.replace(i.group(1), f'![]({i.group(1)})') bio = bio.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") @@ -312,6 +312,7 @@ def gumroad(v): return {"error": f"{patron} rewards already claimed"}, 400 v.patron = tier + g.db.add(v) grant_awards = {} if tier == 1: @@ -355,12 +356,12 @@ def gumroad(v): g.db.bulk_save_objects(_awards) - new_badge = Badge(badge_id=20+tier, - user_id=v.id, - ) - g.db.add(new_badge) + if not v.has_badge(20+tier): + new_badge = Badge(badge_id=20+tier, + user_id=v.id, + ) + g.db.add(new_badge) - g.db.add(v) g.db.commit() return {"message": f"{patron} rewards claimed!"} diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index eecf2c7f08..b859a296b6 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -1,4 +1,12 @@ - + + - \ No newline at end of file diff --git a/files/templates/default.html b/files/templates/default.html index dc7f6d001b..15a8a66c7a 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -670,8 +670,7 @@ function awardModal(link) { var target = document.getElementById("awardTarget"); - - target.value = link; + target.action = link; } // Expand Images on Desktop