mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
removing the admin bits and just making it a user export
This commit is contained in:
parent
e623e1cec0
commit
713516c6ae
2 changed files with 2 additions and 54 deletions
|
@ -220,13 +220,6 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
|
||||||
{% if user_access('manage users', current_user.id) %}
|
|
||||||
<div class="col-4">
|
|
||||||
<a class="w-100 btn btn-primary confirm_first" href="/u/{{ user.link() }}/export_settings">{{ _('Export Settings') }}</a>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -213,9 +213,7 @@ def remove_cover():
|
||||||
return '<div> ' + _('Banner removed!') + '</div>'
|
return '<div> ' + _('Banner removed!') + '</div>'
|
||||||
|
|
||||||
# export settings function. used in the /user/settings for a user to export their own settings
|
# export settings function. used in the /user/settings for a user to export their own settings
|
||||||
# used in the admin moderation /u/<actor>/export_settings call to let admins
|
def export_user_settings(user):
|
||||||
# export the user settings plus admin relevant settings
|
|
||||||
def export_user_settings(user, admin_request=False):
|
|
||||||
# make the empty dict
|
# make the empty dict
|
||||||
user_dict = {}
|
user_dict = {}
|
||||||
|
|
||||||
|
@ -272,19 +270,6 @@ def export_user_settings(user, admin_request=False):
|
||||||
user_subscribed_communities.append(c.ap_profile_id)
|
user_subscribed_communities.append(c.ap_profile_id)
|
||||||
user_dict['followed_communities'] = user_subscribed_communities
|
user_dict['followed_communities'] = user_subscribed_communities
|
||||||
|
|
||||||
# if this is an admin level export request
|
|
||||||
if admin_request:
|
|
||||||
user_dict['public_key'] = user.public_key
|
|
||||||
user_dict['private_key'] = user.private_key
|
|
||||||
|
|
||||||
user_roles = []
|
|
||||||
for r in user.roles.all():
|
|
||||||
user_roles.append(r.name)
|
|
||||||
user_dict['roles'] = user_roles
|
|
||||||
|
|
||||||
user_dict['reputation'] = user.reputation
|
|
||||||
user_dict['attitude'] = user.attitude
|
|
||||||
|
|
||||||
# setup the BytesIO buffer
|
# setup the BytesIO buffer
|
||||||
buffer = BytesIO()
|
buffer = BytesIO()
|
||||||
buffer.write(str(python_json.dumps(user_dict)).encode('utf-8'))
|
buffer.write(str(python_json.dumps(user_dict)).encode('utf-8'))
|
||||||
|
@ -313,7 +298,7 @@ def change_settings():
|
||||||
# seperate if to handle just the 'Export' button being clicked
|
# seperate if to handle just the 'Export' button being clicked
|
||||||
if form.export_settings.data and form.validate():
|
if form.export_settings.data and form.validate():
|
||||||
# get the user settings for this user
|
# get the user settings for this user
|
||||||
buffer = export_user_settings(user, admin_request=False)
|
buffer = export_user_settings(user)
|
||||||
|
|
||||||
# confirmation displayed to user when the page loads up again
|
# confirmation displayed to user when the page loads up again
|
||||||
flash(_l('Export Complete.'))
|
flash(_l('Export Complete.'))
|
||||||
|
@ -604,36 +589,6 @@ def delete_profile(actor):
|
||||||
goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}'
|
goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}'
|
||||||
return redirect(goto)
|
return redirect(goto)
|
||||||
|
|
||||||
@bp.route('/u/<actor>/export_settings', methods=['GET'])
|
|
||||||
@login_required
|
|
||||||
def export_settings(actor):
|
|
||||||
if user_access('manage users', current_user.id):
|
|
||||||
actor = actor.strip()
|
|
||||||
user:User = User.query.filter_by(user_name=actor, deleted=False).first()
|
|
||||||
if user is None:
|
|
||||||
user = User.query.filter_by(ap_id=actor, deleted=False).first()
|
|
||||||
if user is None:
|
|
||||||
abort(404)
|
|
||||||
# get the user settings for this user
|
|
||||||
buffer = export_user_settings(user, admin_request=True)
|
|
||||||
|
|
||||||
# send the file to the user as a download
|
|
||||||
# the as_attachment=True results in flask
|
|
||||||
# redirecting to the current page, so no
|
|
||||||
# url_for needed here
|
|
||||||
return send_file(
|
|
||||||
buffer,
|
|
||||||
download_name=f'{user.user_name}_piefed_settings.json',
|
|
||||||
as_attachment=True,
|
|
||||||
mimetype='application/json'
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
|
||||||
abort(401)
|
|
||||||
|
|
||||||
goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}'
|
|
||||||
return redirect(goto)
|
|
||||||
|
|
||||||
@bp.route('/instance/<int:instance_id>/unblock', methods=['GET'])
|
@bp.route('/instance/<int:instance_id>/unblock', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
def instance_unblock(instance_id):
|
def instance_unblock(instance_id):
|
||||||
|
|
Loading…
Add table
Reference in a new issue