menu: filter the last topics viewable by user (fix #101)

This commit is contained in:
Darks 2021-07-14 17:08:32 +02:00
parent fbc500e833
commit d4ceeb2cd1
Signed by: Darks
GPG Key ID: 7515644268BE1433
1 changed files with 11 additions and 1 deletions

View File

@ -1,3 +1,4 @@
from flask_login import current_user
from app import app, db
from app.forms.login import LoginForm
from app.forms.search import SearchForm
@ -5,6 +6,7 @@ from app.models.forum import Forum
from app.models.topic import Topic
@app.context_processor
def menu_processor():
""" All items used to render main menu. Includes search form """
@ -19,8 +21,16 @@ def menu_processor():
INNER JOIN post ON post.id = comment.id
GROUP BY topic.id
ORDER BY MAX(post.date_created) DESC
LIMIT 10;""")
LIMIT 20;""")
last_active_topics = [Topic.query.get(id) for id in raw]
# Filter the topics the user can view and limit to 10
if current_user.is_authenticated:
f = lambda t: current_user.can_access_forum(t.forum)
else:
f = lambda t: t.forum.is_default_accessible()
last_active_topics = list(filter(f, last_active_topics))[:10]
return dict(login_form=login_form, search_form=search_form,
main_forum=main_forum, last_active_topics=last_active_topics)