From 32737c5af688e7051e5265a900f138a1f1e6a6b0 Mon Sep 17 00:00:00 2001 From: Steve Astels Date: Mon, 22 Jul 2024 10:17:34 -0400 Subject: [PATCH] add command to make user a platform admin (#2225) --- app/commands.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/commands.py b/app/commands.py index 84b5ad829d..e36fcdbbe4 100644 --- a/app/commands.py +++ b/app/commands.py @@ -1045,3 +1045,20 @@ def fix_billable_units(): Notification.query.filter(Notification.id == notification.id).update({"billable_units": template.fragment_count}) db.session.commit() print("End fix_billable_units") + + +@notify_command(name="admin") +@click.option("-u", "--user_email", required=True, help="user email address") +@click.option("--on/--off", required=False, default=True, show_default="on", help="set admin on or off") +def toggle_admin(user_email, on): + """ + Set a user to be a platform admin or not + """ + try: + user = User.query.filter(User.email_address == user_email).one() + except NoResultFound: + print(f"User {user_email} not found") + return + user.platform_admin = on + db.session.commit() + print(f"User {user.email_address} is now {'an admin' if user.platform_admin else 'not an admin'}")