checking for use_allowlist in exports

This commit is contained in:
Alan Roberts 2024-09-26 19:08:06 -04:00
parent 49a9e3e692
commit 1cbb15a32b

View file

@ -332,23 +332,35 @@ def admin_federation():
import_file.save(final_place) import_file.save(final_place)
# import bans in background task # import bans in background task
import_bans(final_place) if current_app.debug:
import_bans_task(final_place)
flash(_(f'import file: {import_file}')) return redirect(url_for('admin.admin_federation'))
return redirect(url_for('admin.admin_federation')) else:
import_bans_task.delay(final_place)
flash(_(f'Ban imports started in a background process.'))
return redirect(url_for('admin.admin_federation'))
# this is the export bans button # this is the export bans button
elif ban_lists_form.export_submit.data and ban_lists_form.validate(): elif ban_lists_form.export_submit.data and ban_lists_form.validate():
# create the empty dict # create the empty dict
ban_lists_dict = {} ban_lists_dict = {}
# get banned_instances info if get_setting('use_allowlist'):
banned_instances = [] # get the allowed_instances info
instance_bans = BannedInstances.query.all() allowed_instances = []
if len(instance_bans) > 0: already_allowed = AllowedInstances.query.all()
for bi in instance_bans: if len(already_allowed) > 0:
banned_instances.append(bi.domain) for aa in already_allowed:
ban_lists_dict['banned_instances'] = banned_instances allowed_instances.append(aa.domain)
ban_lists_dict['allowed_instances'] = banned_instances
else:
# get banned_instances info
banned_instances = []
instance_bans = BannedInstances.query.all()
if len(instance_bans) > 0:
for bi in instance_bans:
banned_instances.append(bi.domain)
ban_lists_dict['banned_instances'] = banned_instances
# get banned_domains info # get banned_domains info
banned_domains = [] banned_domains = []
@ -434,13 +446,6 @@ def admin_federation():
site=g.site site=g.site
) )
def import_bans(filename):
if current_app.debug:
import_bans_task(filename)
else:
import_bans_task.delay(filename)
@celery.task @celery.task
def import_bans_task(filename): def import_bans_task(filename):
contents = file_get_contents(filename) contents = file_get_contents(filename)