Merge branch 'feature/instance-hidelist'

This commit is contained in:
codl 2022-03-04 14:20:00 +01:00
commit 44632934a7
3 changed files with 42 additions and 19 deletions

View File

@ -1,5 +1,7 @@
## vNEXT ## vNEXT
* add: instance hidelist
<https://github.com/codl/forget/pull/590>
* removed: migration path for known instances list from cookie to localstorage * removed: migration path for known instances list from cookie to localstorage
<https://github.com/codl/forget/pull/545> <https://github.com/codl/forget/pull/545>

View File

@ -47,7 +47,23 @@ SENTRY
If you want to send exceptions to sentry, enter your sentry DSN here If you want to send exceptions to sentry, enter your sentry DSN here
""" """
# SENTRY_DSN= # SENTRY_DSN=''
"""
HIDDEN INSTANCES
The front page shows one-click login buttons for the mastodon and
misskey instances that see the most heavy use. Instances configured in this
list will be prevented from appearing in these buttons.
They will still appear if a user has previously logged into them and their
browser remembers it. A user will still be able to log into them by manually
typing the address into the log in form.
This is a space-delimited list. Example syntax:
HIDDEN_INSTANCES='social.example.com pleroma.example.net mk.example.org'
"""
# HIDDEN_INSTANCES=''
""" """
ADVANCED FLASK CONFIG ADVANCED FLASK CONFIG

View File

@ -37,8 +37,9 @@ def index():
@app.route('/about/') @app.route('/about/')
def about(): def about():
mastodon_instances = libforget.mastodon.suggested_instances() blocklist = app.config.get('HIDDEN_INSTANCES', '').split()
misskey_instances = libforget.misskey.suggested_instances() mastodon_instances = libforget.mastodon.suggested_instances(blocklist=blocklist)
misskey_instances = libforget.misskey.suggested_instances(blocklist=blocklist)
return render_template( return render_template(
'about.html', 'about.html',
mastodon_instances=mastodon_instances, mastodon_instances=mastodon_instances,
@ -186,9 +187,11 @@ def mastodon_login_step1(instance=None):
or request.form.get('instance_url', None)) or request.form.get('instance_url', None))
if not instance_url: if not instance_url:
blocklist = app.config.get('HIDDEN_INSTANCES', '').split()
instances = libforget.mastodon.suggested_instances( instances = libforget.mastodon.suggested_instances(
limit=30, limit=30,
min_popularity=1 min_popularity=1,
blocklist=blocklist,
) )
return render_template( return render_template(
'mastodon_login.html', instances=instances, 'mastodon_login.html', instances=instances,
@ -202,15 +205,15 @@ def mastodon_login_step1(instance=None):
instance_url=instance_url, _external=True) instance_url=instance_url, _external=True)
try: try:
app = libforget.mastodon.get_or_create_app( mastoapp = libforget.mastodon.get_or_create_app(
instance_url, instance_url,
callback, callback,
url_for('index', _external=True)) url_for('index', _external=True))
db.session.merge(app) db.session.merge(mastoapp)
db.session.commit() db.session.commit()
return redirect(libforget.mastodon.login_url(app, callback)) return redirect(libforget.mastodon.login_url(mastoapp, callback))
except Exception: except Exception:
if sentry: if sentry:
@ -221,14 +224,14 @@ def mastodon_login_step1(instance=None):
@app.route('/login/mastodon/callback/<instance_url>') @app.route('/login/mastodon/callback/<instance_url>')
def mastodon_login_step2(instance_url): def mastodon_login_step2(instance_url):
code = request.args.get('code', None) code = request.args.get('code', None)
app = MastodonApp.query.get(instance_url) mastoapp = MastodonApp.query.get(instance_url)
if not code or not app: if not code or not mastoapp:
return redirect(url_for('mastodon_login_step1', error=True)) return redirect(url_for('mastodon_login_step1', error=True))
callback = url_for('mastodon_login_step2', callback = url_for('mastodon_login_step2',
instance_url=instance_url, _external=True) instance_url=instance_url, _external=True)
token = libforget.mastodon.receive_code(code, app, callback) token = libforget.mastodon.receive_code(code, mastoapp, callback)
account = token.account account = token.account
session = login(account.id) session = login(account.id)
@ -247,9 +250,11 @@ def misskey_login(instance=None):
or request.form.get('instance_url', None)) or request.form.get('instance_url', None))
if not instance_url: if not instance_url:
blocklist = app.config.get('HIDDEN_INSTANCES', '').split()
instances = libforget.misskey.suggested_instances( instances = libforget.misskey.suggested_instances(
limit = 30, limit = 30,
min_popularity = 1 min_popularity = 1,
blocklist=blocklist,
) )
return render_template( return render_template(
'misskey_login.html', instances=instances, 'misskey_login.html', instances=instances,
@ -264,16 +269,16 @@ def misskey_login(instance=None):
try: try:
session = make_session() session = make_session()
app = libforget.misskey.get_or_create_app( mkapp = libforget.misskey.get_or_create_app(
instance_url, instance_url,
callback, callback,
url_for('index', _external=True), url_for('index', _external=True),
session) session)
db.session.merge(app) db.session.merge(mkapp)
db.session.commit() db.session.commit()
return redirect(libforget.misskey.login_url(app, callback, session)) return redirect(libforget.misskey.login_url(mkapp, callback, session))
except Exception: except Exception:
if sentry: if sentry:
@ -285,11 +290,11 @@ def misskey_login(instance=None):
def misskey_callback(instance_url): def misskey_callback(instance_url):
# legacy auth and miauth use different parameter names # legacy auth and miauth use different parameter names
token = request.args.get('token', None) or request.args.get('session', None) token = request.args.get('token', None) or request.args.get('session', None)
app = MisskeyApp.query.get(instance_url) mkapp = MisskeyApp.query.get(instance_url)
if not token or not app: if not token or not mkapp:
return redirect(url_for('misskey_login', error=True)) return redirect(url_for('misskey_login', error=True))
token = libforget.misskey.receive_token(token, app) token = libforget.misskey.receive_token(token, mkapp)
account = token.account account = token.account
session = login(account.id) session = login(account.id)