diff --git a/files/routes/search.py b/files/routes/search.py index 05c79a902..84181c6ea 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -35,7 +35,8 @@ def searchparse(text): @app.get("/search/posts") @auth_desired def searchposts(v): - + if not v or v.oldsite: template = '' + else: template = 'CHRISTMAS/' query = request.values.get("q", '').strip() @@ -63,6 +64,27 @@ def searchposts(v): if not (v and v.admin_level > 1): posts = posts.filter(Submission.private == False) + + if 'author' in criteria: + author = get_user(criteria['author']) + if author.is_private: + if request.headers.get("Authorization"): + return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"} + return render_template(f"{template}search.html", + v=v, + query=query, + total=0, + page=page, + listing=[], + sort=sort, + t=t, + next_exists=False, + domain=None, + domain_obj=None, + error=f"@{author.username}'s profile is private; You can't use the 'author' syntax on them." + ) + else: posts = posts.filter(Submission.author_id == author.id) + if 'q' in criteria: words=criteria['q'].split() words=[Submission.title.ilike('%'+x+'%') for x in words] @@ -71,10 +93,6 @@ def searchposts(v): if 'over18' in criteria: posts = posts.filter(Submission.over_18==True) - if 'author' in criteria: - author = get_user(criteria['author']) - if not author.is_private: posts = posts.filter(Submission.author_id == author.id) - if 'domain' in criteria: domain=criteria['domain'] posts=posts.filter( @@ -161,8 +179,7 @@ def searchposts(v): domain_obj=None if request.headers.get("Authorization"): return {"total":total, "data":[x.json for x in posts]} - if not v or v.oldsite: template = '' - else: template = 'CHRISTMAS/' + return render_template(f"{template}search.html", v=v, query=query, @@ -180,6 +197,8 @@ def searchposts(v): @auth_desired def searchcomments(v): + if not v or v.oldsite: template = '' + else: template = 'CHRISTMAS/' query = request.values.get("q", '').strip() @@ -191,11 +210,18 @@ def searchcomments(v): criteria=searchparse(query) - - - comments = g.db.query(Comment.id).filter(Comment.parent_submission != None) + if 'author' in criteria: + author = get_user(criteria['author']) + if author.is_private: + if request.headers.get("Authorization"): + return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"} + + return render_template(f"{template}search_comments.html", v=v, query=query, total=0, page=page, comments=[], sort=sort, t=t, next_exists=False, error=f"@{author.username}'s profile is private; You can't use the 'author' syntax on them.") + + else: comments = comments.filter(Comment.author_id == author.id) + if 'q' in criteria: words=criteria['q'].split() words=[Comment.body_html.ilike('%'+x+'%') for x in words] @@ -204,10 +230,6 @@ def searchcomments(v): if 'over18' in criteria: comments = comments.filter(Comment.over_18==True) - if 'author' in criteria: - author = get_user(criteria['author']) - if not author.is_private: comments = comments.filter(Comment.author_id == author.id) - if not(v and v.admin_level > 1): comments = comments.filter(Comment.deleted_utc == 0, Comment.is_banned == False) if t: @@ -253,8 +275,6 @@ def searchcomments(v): comments = get_comments(ids, v=v) if request.headers.get("Authorization"): return {"total":total, "data":[x.json for x in comments]} - if not v or v.oldsite: template = '' - else: template = 'CHRISTMAS/' return render_template(f"{template}search_comments.html", v=v, query=query, total=total, page=page, comments=comments, sort=sort, t=t, next_exists=next_exists) diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 66095ed5a..678b1e04a 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,7 +15,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index 760d34829..6fe815c27 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -7,7 +7,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/log.html b/files/templates/log.html index 299ac4e22..04504ef6e 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,7 +6,7 @@ {% block content %} {% if v %} - + {% if v.agendaposter %} - + {% endif %}
diff --git a/files/templates/login.html b/files/templates/login.html index 8c9682bb8..5ff84eae1 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -18,7 +18,7 @@ {% endblock %} - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 5db97cf42..71fcaf265 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -14,7 +14,7 @@ 2-Step Login - {{'SITE_NAME' | app_config}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index dad378406..031058a1d 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -34,7 +34,7 @@ - + {% if v.agendaposter %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index 2b8f95b8f..53e944222 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{'SITE_NAME' | app_config}}{% else %}Sign up - {{'SITE_NAME' | app_config}}{% endif %} - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index dc01a09b0..6500c8fbd 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -32,7 +32,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{'SITE_NAME' | app_config}}{% else %}{{'SITE_NAME' | app_config}}{% endif %} - + diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 4f3fe0ee7..65f8565d9 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -589,7 +589,9 @@ -

There are no posts here.

+ {% if request.path.startswith('/search') and error %} +

{{error}}

+ {% endif %}
diff --git a/files/templates/submit.html b/files/templates/submit.html index 5caea0e85..38bbb0df6 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -26,7 +26,7 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %} - + {% endif %} {% endblock %}