block nsfw community adding if nsfw is disabled

This commit is contained in:
rimu 2024-01-21 21:04:48 +13:00
parent 3d11dcf62e
commit 14d0344702
3 changed files with 18 additions and 4 deletions

View file

@ -382,6 +382,14 @@ def actor_json_to_model(activity_json, address, server):
mods_url = activity_json['moderators']
else:
mods_url = None
# only allow nsfw communities if enabled for this instance
site = Site.query.get(1) # can't use g.site because actor_json_to_model can be called from celery
if activity_json['sensitive'] and not site.enable_nsfw:
return None
if 'nsfl' in activity_json and activity_json['nsfl'] and not site.enable_nsfl:
return None
community = Community(name=activity_json['preferredUsername'],
title=activity_json['name'],
description=activity_json['summary'] if 'summary' in activity_json else '',

View file

@ -90,6 +90,11 @@ def add_remote():
message = Markup(
'Type address in the format !community@server.name. Search on <a href="https://lemmyverse.net/communities">Lemmyverse.net</a> to find some.')
flash(message, 'error')
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')
return render_template('community/add_remote.html',
title=_('Add remote community'), form=form, new_community=new_community,

View file

@ -54,10 +54,11 @@ def search_for_community(address: str):
community_data.close()
if community_json['type'] == 'Group':
community = actor_json_to_model(community_json, name, server)
if current_app.debug:
retrieve_mods_and_backfill(community.id)
else:
retrieve_mods_and_backfill.delay(community.id)
if community:
if current_app.debug:
retrieve_mods_and_backfill(community.id)
else:
retrieve_mods_and_backfill.delay(community.id)
return community
return None