diff --git a/app/community/routes.py b/app/community/routes.py index e4c8799b..4b5ca040 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -14,7 +14,8 @@ from app.constants import SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER, POST_TYPE_LIN from app.models import User, Community, CommunityMember, CommunityJoinRequest, CommunityBan, Post, PostReply, \ PostReplyVote, PostVote from app.community import bp -from app.utils import get_setting, render_template, allowlist_html, markdown_to_html, validation_required +from app.utils import get_setting, render_template, allowlist_html, markdown_to_html, validation_required, \ + shorten_string, markdown_to_text @bp.route('/add_local', methods=['GET', 'POST']) @@ -89,8 +90,12 @@ def show_community(community: Community): else: posts = community.posts + description = shorten_string(community.description, 150) if community.description else None + og_image = community.image.source_url if community.image_id else None + return render_template('community/community.html', community=community, title=community.title, - is_moderator=is_moderator, is_owner=is_owner, mods=mod_list, posts=posts) + is_moderator=is_moderator, is_owner=is_owner, mods=mod_list, posts=posts, description=description, + og_image=og_image) @bp.route('//subscribe', methods=['GET']) @@ -248,8 +253,13 @@ def show_post(post_id: int): post_id=post_id)) # redirect to current page to avoid refresh resubmitting the form else: replies = post_replies(post.id, 'top') + + og_image = post.image.source_url if post.image_id else None + description = shorten_string(markdown_to_text(post.body), 150) if post.body else None + return render_template('community/post.html', title=post.title, post=post, is_moderator=is_moderator, - canonical=post.ap_id, form=form, replies=replies, THREAD_CUTOFF_DEPTH=constants.THREAD_CUTOFF_DEPTH) + canonical=post.ap_id, form=form, replies=replies, THREAD_CUTOFF_DEPTH=constants.THREAD_CUTOFF_DEPTH, + description=description, og_image=og_image) @bp.route('/post//', methods=['GET', 'POST']) diff --git a/app/templates/base.html b/app/templates/base.html index 39f3b938..b389178f 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -36,6 +36,12 @@ {% if canonical %} {% endif %} + {% if description %} + + {% endif %} + {% if og_image %} + + {% endif %} {% endblock %} diff --git a/app/user/routes.py b/app/user/routes.py index 737d0617..15975033 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -6,7 +6,7 @@ from app import db from app.models import Post, Community, CommunityMember, User, PostReply from app.user import bp from app.user.forms import ProfileForm, SettingsForm -from app.utils import get_setting, render_template, markdown_to_html, user_access +from app.utils import get_setting, render_template, markdown_to_html, user_access, markdown_to_text, shorten_string from sqlalchemy import desc, or_ @@ -20,9 +20,11 @@ def show_profile(user): post_replies = PostReply.query.filter_by(user_id=user.id).order_by(desc(PostReply.posted_at)).all() canonical = user.ap_public_url if user.ap_public_url else None user.about_html = markdown_to_html(user.about) + description = shorten_string(markdown_to_text(user.about), 150) if user.about else None return render_template('user/show_profile.html', user=user, posts=posts, post_replies=post_replies, moderates=moderates.all(), canonical=canonical, title=_('Posts by %(user_name)s', - user_name=user.user_name)) + user_name=user.user_name), + description=description) @bp.route('/u//profile', methods=['GET', 'POST']) @@ -32,6 +34,8 @@ def edit_profile(actor): user = User.query.filter_by(user_name=actor, deleted=False, banned=False, ap_id=None).first() if user is None: abort(404) + if current_user.id != user.id: + abort(401) form = ProfileForm() if form.validate_on_submit(): current_user.email = form.email.data @@ -57,6 +61,8 @@ def change_settings(actor): user = User.query.filter_by(user_name=actor, deleted=False, banned=False, ap_id=None).first() if user is None: abort(404) + if current_user.id != user.id: + abort(401) form = SettingsForm() if form.validate_on_submit(): current_user.newsletter = form.newsletter.data diff --git a/app/utils.py b/app/utils.py index 93572904..bcfdc3d7 100644 --- a/app/utils.py +++ b/app/utils.py @@ -152,6 +152,10 @@ def markdown_to_html(markdown_text) -> str: return '' +def markdown_to_text(markdown_text) -> str: + return markdown_text.replace("# ", '') + + def domain_from_url(url: str) -> Domain: parsed_url = urlparse(url) domain = Domain.query.filter_by(name=parsed_url.hostname.lower()).first()