Setting some user profile settings works. Going to deprecate socials field.

This commit is contained in:
Michael Woods
2025-03-16 20:47:01 -04:00
parent 54b94ab3f4
commit 6d25551847
3 changed files with 55 additions and 6 deletions

View File

@@ -154,10 +154,36 @@ def user(ctx, list_users, output_format, username):
click.echo(format_list_dicts([x.pretty_dict() for x in output_objects], output_format=output_format.lower()))
exit_client(ctx.obj, 0)
@click.command()
@click.option('--email', '-e', type=str, default=None, help="Sets your e-mail address in your profile.")
@click.option('--bio', '-b', type=str, default=None, help="Sets your about you text in your profile.")
@click.option('--status', '-S', type=str, default=None,
help="Sets your status (happy,sad, gone fishing, etc) in your profile.")
@click.option('--location', '-l', type=str, default=None,
help="Sets your physical location (in whatever form you want) in your profile.")
@click.option('--socials', '-m', type=str, default=None,
help="Comma (,) separated list of social media or websites you are known by.")
@click.pass_context
def set_user(ctx, email, bio, status, location, socials):
"""Set your user profile settings on the BBS."""
social_list = None
client = ctx.obj['client']
if type(socials) is str:
social_list = socials.split(',')
try:
users.update_self(client, ctx.obj['bbs'], email=email, bio=bio, socials=social_list,
location=location, status=status)
exit_client(ctx.obj, 0)
except Exception as e:
click.echo(str(e), err=True)
exit_client(ctx.obj, 98)
cli.add_command(user)
cli.add_command(query_server)
cli.add_command(job, name='job')
cli.add_command(objects, name='object')
cli.add_command(set_user, name='set')
if __name__ == '__main__':
cli()

View File

@@ -1,7 +1,8 @@
import os
import os.path
import click
from packetserver.client.objects import ObjectWrapper, post_object, post_file, get_user_objects, get_object_by_uuid
from packetserver.client.objects import (ObjectWrapper, post_object, post_file,
get_user_objects, get_object_by_uuid, delete_object_by_uuid)
from packetserver.client.cli.util import exit_client, format_list_dicts
from copy import deepcopy
from uuid import UUID
@@ -53,6 +54,27 @@ def get(ctx, uuid):
exit_client(ctx.obj, 19)
@click.command()
@click.argument('uuid', required=True, type=str)
@click.pass_context
def delete(ctx, uuid):
"""Delete the object identified by its UUID."""
client = ctx.obj['client']
u = ""
try:
u = UUID(uuid)
except ValueError as e:
click.echo(f"'{uuid}' is not a valid UUID.", err=True)
exit_client(ctx.obj, 13)
try:
delete_object_by_uuid(client, ctx.obj['bbs'], u)
exit_client(ctx.obj, 0)
except Exception as e:
click.echo(e, err=True)
exit_client(ctx.obj, 19)
@click.command()
@click.option('--number', '-n', type=int, default=0, help="Number of objects to list. Default 0 for all.")
@click.option('--search', '-S', type=str, default=None, help="Search string to filter objects with.")
@@ -101,4 +123,5 @@ def list_objects(ctx, number, search, reverse, sort_by, output_format):
objects.add_command(upload_file)
objects.add_command(list_objects, name='list')
objects.add_command(get)
objects.add_command(get)
objects.add_command(delete)

View File

@@ -270,13 +270,13 @@ def handle_user_update(req: Request, conn: PacketServerConnection, db: ZODB.DB):
location = str(req.payload['location'])
if 'status' in req.payload:
status = str(req.payload['stus'])
status = str(req.payload['status'])
if 'email' in req.payload:
email = req.payload['email']
if not email_valid(email):
send_blank_response(conn, req, status_code=400, payload="email must be valid format")
return
if not email_valid(email):
send_blank_response(conn, req, status_code=400, payload="email must be valid format")
return
if 'socials' in req.payload:
var_socials = req.payload['socials']