mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Merge remote-tracking branch 'upstream/main'
This commit is contained in:
commit
98425bccd4
11 changed files with 99 additions and 12 deletions
|
@ -18,6 +18,8 @@ from sqlalchemy_searchable import make_searchable
|
|||
|
||||
from config import Config
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def get_locale():
|
||||
try:
|
||||
|
@ -97,12 +99,6 @@ def create_app(config_class=Config):
|
|||
from app.search import bp as search_bp
|
||||
app.register_blueprint(search_bp)
|
||||
|
||||
def get_resource_as_string(name, charset='utf-8'):
|
||||
with app.open_resource(name) as f:
|
||||
return f.read().decode(charset)
|
||||
|
||||
app.jinja_env.globals['get_resource_as_string'] = get_resource_as_string
|
||||
|
||||
# send error reports via email
|
||||
if app.config['MAIL_SERVER'] and app.config['MAIL_ERRORS']:
|
||||
auth = None
|
||||
|
|
|
@ -175,12 +175,12 @@ def user_profile(actor):
|
|||
actor = actor.strip()
|
||||
if current_user.is_authenticated and current_user.is_admin():
|
||||
if '@' in actor:
|
||||
user: User = User.query.filter_by(ap_id=actor.lower()).first()
|
||||
user: User = User.query.filter_by(ap_id=actor).first()
|
||||
else:
|
||||
user: User = User.query.filter_by(user_name=actor, ap_id=None).first()
|
||||
else:
|
||||
if '@' in actor:
|
||||
user: User = User.query.filter_by(ap_id=actor.lower(), deleted=False, banned=False).first()
|
||||
user: User = User.query.filter_by(ap_id=actor, deleted=False, banned=False).first()
|
||||
else:
|
||||
user: User = User.query.filter_by(user_name=actor, deleted=False, ap_id=None).first()
|
||||
|
||||
|
|
|
@ -98,6 +98,11 @@ def register():
|
|||
if form.user_name.data in disallowed_usernames:
|
||||
flash(_('Sorry, you cannot use that user name'), 'error')
|
||||
else:
|
||||
# Nazis use 88 and 14 in their user names very often.
|
||||
if '88' in form.user_name.data or '14' in form.user_name.data:
|
||||
resp = make_response(redirect(url_for('auth.please_wait')))
|
||||
resp.set_cookie('sesion', '17489047567495', expires=datetime(year=2099, month=12, day=30))
|
||||
return resp
|
||||
for referrer in blocked_referrers():
|
||||
if referrer in session.get('Referer', ''):
|
||||
resp = make_response(redirect(url_for('auth.please_wait')))
|
||||
|
|
|
@ -1028,3 +1028,41 @@ def community_moderate_report_resolve(community_id, report_id):
|
|||
return redirect(url_for('community.community_moderate', actor=community.link()))
|
||||
else:
|
||||
return render_template('community/community_moderate_report_resolve.html', form=form)
|
||||
|
||||
|
||||
@bp.route('/lookup/<community>/<domain>')
|
||||
def lookup(community, domain):
|
||||
if domain == current_app.config['SERVER_NAME']:
|
||||
return redirect('/c/' + community)
|
||||
|
||||
exists = Community.query.filter_by(name=community, ap_domain=domain).first()
|
||||
if exists:
|
||||
return redirect('/c/' + community + '@' + domain)
|
||||
else:
|
||||
address = '!' + community + '@' + domain
|
||||
if current_user.is_authenticated:
|
||||
new_community = None
|
||||
|
||||
new_community = search_for_community(address)
|
||||
if new_community is None:
|
||||
if g.site.enable_nsfw:
|
||||
flash(_('Community not found.'), 'warning')
|
||||
else:
|
||||
flash(_('Community not found. If you are searching for a nsfw community it is blocked by this instance.'), 'warning')
|
||||
else:
|
||||
if new_community.banned:
|
||||
flash(_('That community is banned from %(site)s.', site=g.site.name), 'warning')
|
||||
|
||||
return render_template('community/lookup_remote.html',
|
||||
title=_('Search result for remote community'), new_community=new_community,
|
||||
subscribed=community_membership(current_user, new_community) >= SUBSCRIPTION_MEMBER)
|
||||
else:
|
||||
# send them back where they came from
|
||||
flash('Searching for remote communities requires login', 'error')
|
||||
referrer = request.headers.get('Referer', None)
|
||||
if referrer is not None:
|
||||
return redirect(referrer)
|
||||
else:
|
||||
return redirect('/')
|
||||
|
||||
|
||||
|
|
|
@ -426,6 +426,10 @@ fieldset legend {
|
|||
background-color: #d8e5ee;
|
||||
}
|
||||
|
||||
html, body {
|
||||
overscroll-behavior-x: none;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
@import "scss/typography";
|
||||
@import "scss/controls";
|
||||
|
||||
html, body {
|
||||
overscroll-behavior-x: none;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
@ -14,6 +18,7 @@ a {
|
|||
}
|
||||
|
||||
#outer_container, footer {
|
||||
//overscroll-behavior-x: none;
|
||||
a:not(.btn):hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
|
32
app/templates/community/lookup_remote.html
Normal file
32
app/templates/community/lookup_remote.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %}
|
||||
{% extends 'themes/' + theme() + '/base.html' %}
|
||||
{% else %}
|
||||
{% extends "base.html" %}
|
||||
{% endif %} %}
|
||||
{% from 'bootstrap/form.html' import render_form %}
|
||||
|
||||
{% block app_content %}
|
||||
{% if new_community and not new_community.banned %}
|
||||
<div class="row">
|
||||
<div class="col mx-auto">
|
||||
<div class="card mt-5">
|
||||
<div class="card-body p-6">
|
||||
<div class="card-title">{{ _('Found a community:') }}</div>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
<a href="/c/{{ new_community.link() }}"><img src="{{ new_community.icon_image()}}" class="community_icon rounded-circle" style="width: 30px; vertical-align: middle;" /></a>
|
||||
<a href="/c/{{ new_community.link() }}">{{ new_community.title }}@{{ new_community.ap_domain }}</a>
|
||||
</p>
|
||||
<p> {% if subscribed %}
|
||||
<a class="btn btn-primary mt-4" href="/community/{{ new_community.link() }}/unsubscribe">{{ _('Leave') }}</a>
|
||||
{% else %}
|
||||
<a class="btn btn-primary mt-4" href="/community/{{ new_community.link() }}/subscribe">{{ _('Join') }}</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -42,7 +42,7 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
<div class="post_body mt-2">
|
||||
{{ post.body_html|safe if post.body_html else '' }}
|
||||
{{ post.body_html|community_links|safe if post.body_html else '' }}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
|
@ -99,7 +99,7 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
<div class="post_body">
|
||||
{{ post.body_html|safe if post.body_html else '' }}
|
||||
{{ post.body_html|community_links|safe if post.body_html else '' }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -109,7 +109,7 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
<div class="comment_body hidable {% if comment['comment'].reports and current_user.is_authenticated and post.community.is_moderator(current_user) %}reported{% endif %}">
|
||||
{{ comment['comment'].body_html | safe }}
|
||||
{{ comment['comment'].body_html | community_links | safe }}
|
||||
</div>{% if not comment['comment'].author.indexable %}<!--googleon: all-->{% endif %}
|
||||
</div>
|
||||
<div class="comment_actions hidable">
|
||||
|
|
|
@ -252,6 +252,12 @@ def microblog_content_to_title(html: str) -> str:
|
|||
return result
|
||||
|
||||
|
||||
def community_link_to_href(link: str) -> str:
|
||||
pattern = r"!([a-zA-Z0-9_.-]*)@([a-zA-Z0-9_.-]*)\b"
|
||||
server = r'<a href=https://' + current_app.config['SERVER_NAME'] + r'/community/lookup/'
|
||||
return re.sub(pattern, server + r'\g<1>/\g<2>>' + r'!\g<1>@\g<2></a>', link)
|
||||
|
||||
|
||||
def domain_from_url(url: str, create=True) -> Domain:
|
||||
parsed_url = urlparse(url.lower().replace('www.', ''))
|
||||
if parsed_url and parsed_url.hostname:
|
||||
|
|
|
@ -11,7 +11,7 @@ from flask import session, g, json, request, current_app
|
|||
from app.constants import POST_TYPE_LINK, POST_TYPE_IMAGE, POST_TYPE_ARTICLE
|
||||
from app.models import Site
|
||||
from app.utils import getmtime, gibberish, shorten_string, shorten_url, digits, user_access, community_membership, \
|
||||
can_create_post, can_upvote, can_downvote, shorten_number, ap_datetime, current_theme
|
||||
can_create_post, can_upvote, can_downvote, shorten_number, ap_datetime, current_theme, community_link_to_href
|
||||
|
||||
app = create_app()
|
||||
cli.register(app)
|
||||
|
@ -44,6 +44,7 @@ with app.app_context():
|
|||
app.jinja_env.globals['can_downvote'] = can_downvote
|
||||
app.jinja_env.globals['theme'] = current_theme
|
||||
app.jinja_env.globals['file_exists'] = os.path.exists
|
||||
app.jinja_env.filters['community_links'] = community_link_to_href
|
||||
app.jinja_env.filters['shorten'] = shorten_string
|
||||
app.jinja_env.filters['shorten_url'] = shorten_url
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue