Allow search and other pages for logged out users
This commit is contained in:
parent
f36a0b88e2
commit
1841134b47
4 changed files with 31 additions and 46 deletions
|
@ -467,8 +467,7 @@ def changeloglist(v=None, sort="new", page=1, t="all", site=None):
|
||||||
|
|
||||||
|
|
||||||
@app.get("/random_post")
|
@app.get("/random_post")
|
||||||
@auth_required
|
def random_post():
|
||||||
def random_post(v):
|
|
||||||
|
|
||||||
p = g.db.query(Submission.id).filter(Submission.deleted_utc == 0, Submission.is_banned == False, Submission.private == False).order_by(func.random()).first()
|
p = g.db.query(Submission.id).filter(Submission.deleted_utc == 0, Submission.is_banned == False, Submission.private == False).order_by(func.random()).first()
|
||||||
|
|
||||||
|
@ -479,8 +478,7 @@ def random_post(v):
|
||||||
|
|
||||||
|
|
||||||
@app.get("/random_user")
|
@app.get("/random_user")
|
||||||
@auth_required
|
def random_user():
|
||||||
def random_user(v):
|
|
||||||
u = g.db.query(User.username).order_by(func.random()).first()
|
u = g.db.query(User.username).order_by(func.random()).first()
|
||||||
|
|
||||||
if u: u = u[0]
|
if u: u = u[0]
|
||||||
|
|
|
@ -32,8 +32,7 @@ def searchparse(text):
|
||||||
|
|
||||||
|
|
||||||
@app.get("/search/posts")
|
@app.get("/search/posts")
|
||||||
@auth_required
|
def searchposts(v=None):
|
||||||
def searchposts(v):
|
|
||||||
|
|
||||||
query = request.values.get("q", '').strip()
|
query = request.values.get("q", '').strip()
|
||||||
|
|
||||||
|
@ -57,18 +56,19 @@ def searchposts(v):
|
||||||
|
|
||||||
posts = g.db.query(Submission.id)
|
posts = g.db.query(Submission.id)
|
||||||
|
|
||||||
if not v.paid_dues: posts = posts.filter_by(club=False)
|
if not (v and v.paid_dues): posts = posts.filter_by(club=False)
|
||||||
|
|
||||||
if v.admin_level < 2:
|
if v and v.admin_level < 2:
|
||||||
posts = posts.filter(Submission.deleted_utc == 0, Submission.is_banned == False, Submission.private == False, Submission.author_id.notin_(v.userblocks))
|
posts = posts.filter(Submission.deleted_utc == 0, Submission.is_banned == False, Submission.private == False, Submission.author_id.notin_(v.userblocks))
|
||||||
|
elif not v:
|
||||||
|
posts = posts.filter(Submission.deleted_utc == 0, Submission.is_banned == False, Submission.private == False)
|
||||||
|
|
||||||
|
|
||||||
if 'author' in criteria:
|
if 'author' in criteria:
|
||||||
posts = posts.filter(Submission.ghost == False)
|
posts = posts.filter(Submission.ghost == False)
|
||||||
author = get_user(criteria['author'])
|
author = get_user(criteria['author'])
|
||||||
if not author: return {"error": "User not found"}
|
if not author: return {"error": "User not found"}
|
||||||
if author.is_private and author.id != v.id and v.admin_level < 2 and not v.eye:
|
if author.is_private and (not v or (author.id != v.id and v.admin_level < 2 and not v.eye)):
|
||||||
if request.headers.get("Authorization"):
|
if request.headers.get("Authorization"):
|
||||||
return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}
|
return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}
|
||||||
return render_template("search.html",
|
return render_template("search.html",
|
||||||
|
@ -174,8 +174,7 @@ def searchposts(v):
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.get("/search/comments")
|
@app.get("/search/comments")
|
||||||
@auth_required
|
def searchcomments(v=None):
|
||||||
def searchcomments(v):
|
|
||||||
|
|
||||||
|
|
||||||
query = request.values.get("q", '').strip()
|
query = request.values.get("q", '').strip()
|
||||||
|
@ -194,7 +193,7 @@ def searchcomments(v):
|
||||||
comments = comments.filter(Comment.ghost == False)
|
comments = comments.filter(Comment.ghost == False)
|
||||||
author = get_user(criteria['author'])
|
author = get_user(criteria['author'])
|
||||||
if not author: return {"error": "User not found"}
|
if not author: return {"error": "User not found"}
|
||||||
if author.is_private and author.id != v.id and v.admin_level < 2 and not v.eye:
|
if author.is_private and (not v or (author.id != v.id and v.admin_level < 2 and not v.eye)):
|
||||||
if request.headers.get("Authorization"):
|
if request.headers.get("Authorization"):
|
||||||
return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}
|
return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}
|
||||||
|
|
||||||
|
@ -227,13 +226,15 @@ def searchcomments(v):
|
||||||
comments = comments.filter(Comment.created_utc >= cutoff)
|
comments = comments.filter(Comment.created_utc >= cutoff)
|
||||||
|
|
||||||
|
|
||||||
if v.admin_level < 2:
|
if v and v.admin_level < 2:
|
||||||
private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()]
|
private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()]
|
||||||
|
|
||||||
comments = comments.filter(Comment.author_id.notin_(v.userblocks), Comment.is_banned==False, Comment.deleted_utc == 0, Comment.parent_submission.notin_(private))
|
comments = comments.filter(Comment.author_id.notin_(v.userblocks), Comment.is_banned==False, Comment.deleted_utc == 0, Comment.parent_submission.notin_(private))
|
||||||
|
elif not v:
|
||||||
|
private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()]
|
||||||
|
comments = comments.filter(Comment.is_banned==False, Comment.deleted_utc == 0, Comment.parent_submission.notin_(private))
|
||||||
|
|
||||||
|
|
||||||
if not v.paid_dues:
|
if not (v and v.paid_dues):
|
||||||
club = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()]
|
club = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()]
|
||||||
comments = comments.filter(Comment.parent_submission.notin_(club))
|
comments = comments.filter(Comment.parent_submission.notin_(club))
|
||||||
|
|
||||||
|
@ -265,8 +266,7 @@ def searchcomments(v):
|
||||||
|
|
||||||
|
|
||||||
@app.get("/search/users")
|
@app.get("/search/users")
|
||||||
@auth_required
|
def searchusers(v=None):
|
||||||
def searchusers(v):
|
|
||||||
|
|
||||||
query = request.values.get("q", '').strip()
|
query = request.values.get("q", '').strip()
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,8 @@ def support(v):
|
||||||
return render_template('support.html', v=v)
|
return render_template('support.html', v=v)
|
||||||
|
|
||||||
@app.get("/stats")
|
@app.get("/stats")
|
||||||
@auth_required
|
|
||||||
@cache.memoize(timeout=86400, make_name=make_name)
|
@cache.memoize(timeout=86400, make_name=make_name)
|
||||||
def participation_stats(v):
|
def participation_stats(v=None):
|
||||||
|
|
||||||
|
|
||||||
day = int(time.time()) - 86400
|
day = int(time.time()) - 86400
|
||||||
|
@ -114,15 +113,13 @@ def chart():
|
||||||
|
|
||||||
|
|
||||||
@app.get("/weekly_chart")
|
@app.get("/weekly_chart")
|
||||||
@auth_required
|
def weekly_chart():
|
||||||
def weekly_chart(v):
|
|
||||||
file = cached_chart(kind="weekly", site=SITE)
|
file = cached_chart(kind="weekly", site=SITE)
|
||||||
f = send_file(file)
|
f = send_file(file)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
@app.get("/daily_chart")
|
@app.get("/daily_chart")
|
||||||
@auth_required
|
def daily_chart():
|
||||||
def daily_chart(v):
|
|
||||||
file = cached_chart(kind="daily", site=SITE)
|
file = cached_chart(kind="daily", site=SITE)
|
||||||
f = send_file(file)
|
f = send_file(file)
|
||||||
return f
|
return f
|
||||||
|
@ -207,8 +204,7 @@ def patrons(v):
|
||||||
|
|
||||||
@app.get("/admins")
|
@app.get("/admins")
|
||||||
@app.get("/badmins")
|
@app.get("/badmins")
|
||||||
@auth_required
|
def admins(v=None):
|
||||||
def admins(v):
|
|
||||||
if v and v.admin_level > 2:
|
if v and v.admin_level > 2:
|
||||||
admins = g.db.query(User).filter(User.admin_level>1).order_by(User.truecoins.desc()).all()
|
admins = g.db.query(User).filter(User.admin_level>1).order_by(User.truecoins.desc()).all()
|
||||||
admins += g.db.query(User).filter(User.admin_level==1).order_by(User.truecoins.desc()).all()
|
admins += g.db.query(User).filter(User.admin_level==1).order_by(User.truecoins.desc()).all()
|
||||||
|
@ -218,8 +214,8 @@ def admins(v):
|
||||||
|
|
||||||
@app.get("/log")
|
@app.get("/log")
|
||||||
@app.get("/modlog")
|
@app.get("/modlog")
|
||||||
@auth_required
|
|
||||||
def log(v):
|
def log(v=None):
|
||||||
|
|
||||||
try: page = max(int(request.values.get("page", 1)), 1)
|
try: page = max(int(request.values.get("page", 1)), 1)
|
||||||
except: page = 1
|
except: page = 1
|
||||||
|
@ -259,8 +255,7 @@ def log(v):
|
||||||
return render_template("log.html", v=v, admins=admins, types=types, admin=admin, type=kind, actions=actions, next_exists=next_exists, page=page)
|
return render_template("log.html", v=v, admins=admins, types=types, admin=admin, type=kind, actions=actions, next_exists=next_exists, page=page)
|
||||||
|
|
||||||
@app.get("/log/<id>")
|
@app.get("/log/<id>")
|
||||||
@auth_required
|
def log_item(id, v=None):
|
||||||
def log_item(id, v):
|
|
||||||
|
|
||||||
try: id = int(id)
|
try: id = int(id)
|
||||||
except: abort(404)
|
except: abort(404)
|
||||||
|
@ -278,15 +273,13 @@ def log_item(id, v):
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api")
|
@app.get("/api")
|
||||||
@auth_required
|
def api(v=None):
|
||||||
def api(v):
|
|
||||||
return render_template("api.html", v=v)
|
return render_template("api.html", v=v)
|
||||||
|
|
||||||
@app.get("/contact")
|
@app.get("/contact")
|
||||||
@app.get("/press")
|
@app.get("/press")
|
||||||
@app.get("/media")
|
@app.get("/media")
|
||||||
@auth_required
|
def contact(v=None):
|
||||||
def contact(v):
|
|
||||||
|
|
||||||
return render_template("contact.html", v=v)
|
return render_template("contact.html", v=v)
|
||||||
|
|
||||||
|
@ -415,15 +408,13 @@ def blocks(v):
|
||||||
return render_template("blocks.html", v=v, users=users, targets=targets)
|
return render_template("blocks.html", v=v, users=users, targets=targets)
|
||||||
|
|
||||||
@app.get("/banned")
|
@app.get("/banned")
|
||||||
@auth_required
|
def banned(v=None):
|
||||||
def banned(v):
|
|
||||||
|
|
||||||
users = [x for x in g.db.query(User).filter(User.is_banned > 0, User.unban_utc == 0).all()]
|
users = [x for x in g.db.query(User).filter(User.is_banned > 0, User.unban_utc == 0).all()]
|
||||||
return render_template("banned.html", v=v, users=users)
|
return render_template("banned.html", v=v, users=users)
|
||||||
|
|
||||||
@app.get("/formatting")
|
@app.get("/formatting")
|
||||||
@auth_required
|
def formatting(v=None):
|
||||||
def formatting(v):
|
|
||||||
|
|
||||||
return render_template("formatting.html", v=v)
|
return render_template("formatting.html", v=v)
|
||||||
|
|
||||||
|
|
|
@ -751,26 +751,22 @@ def api_is_available(name):
|
||||||
return {name: True}
|
return {name: True}
|
||||||
|
|
||||||
@app.get("/id/<id>")
|
@app.get("/id/<id>")
|
||||||
@auth_required
|
def user_id(id):
|
||||||
def user_id(id, v):
|
|
||||||
user = get_account(id)
|
user = get_account(id)
|
||||||
return redirect(user.url)
|
return redirect(user.url)
|
||||||
|
|
||||||
@app.get("/u/<username>")
|
@app.get("/u/<username>")
|
||||||
@auth_required
|
def redditor_moment_redirect(username):
|
||||||
def redditor_moment_redirect(username, v):
|
|
||||||
return redirect(f"/@{username}")
|
return redirect(f"/@{username}")
|
||||||
|
|
||||||
@app.get("/@<username>/followers")
|
@app.get("/@<username>/followers")
|
||||||
@auth_required
|
def followers(username, v=None):
|
||||||
def followers(username, v):
|
|
||||||
u = get_user(username, v=v)
|
u = get_user(username, v=v)
|
||||||
users = g.db.query(User).join(Follow, Follow.target_id == u.id).filter(Follow.user_id == User.id).order_by(Follow.created_utc).all()
|
users = g.db.query(User).join(Follow, Follow.target_id == u.id).filter(Follow.user_id == User.id).order_by(Follow.created_utc).all()
|
||||||
return render_template("followers.html", v=v, u=u, users=users)
|
return render_template("followers.html", v=v, u=u, users=users)
|
||||||
|
|
||||||
@app.get("/@<username>/following")
|
@app.get("/@<username>/following")
|
||||||
@auth_required
|
def following(username, v=None):
|
||||||
def following(username, v):
|
|
||||||
u = get_user(username, v=v)
|
u = get_user(username, v=v)
|
||||||
users = g.db.query(User).join(Follow, Follow.user_id == u.id).filter(Follow.target_id == User.id).order_by(Follow.created_utc).all()
|
users = g.db.query(User).join(Follow, Follow.user_id == u.id).filter(Follow.target_id == User.id).order_by(Follow.created_utc).all()
|
||||||
return render_template("following.html", v=v, u=u, users=users)
|
return render_template("following.html", v=v, u=u, users=users)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue