diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 453e4058..7abacc29 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -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 '', diff --git a/app/community/routes.py b/app/community/routes.py index 996b398c..a48ec74a 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -90,6 +90,11 @@ def add_remote(): message = Markup( 'Type address in the format !community@server.name. Search on Lemmyverse.net 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, diff --git a/app/community/util.py b/app/community/util.py index d2c3df79..9f69862f 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -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