From 6ea76ba2a9e63a8169d45b568812fb7ec3a9cb8b Mon Sep 17 00:00:00 2001 From: Kuchenpirat Date: Tue, 7 Jan 2025 14:43:29 +0000 Subject: [PATCH] add make_admin script --- .../docs/documentation/getting-started/faq.md | 10 +++++++ docs/docs/overrides/api.html | 2 +- mealie/scripts/make_admin.py | 30 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 mealie/scripts/make_admin.py diff --git a/docs/docs/documentation/getting-started/faq.md b/docs/docs/documentation/getting-started/faq.md index 5484c718a16..b07dc44abd2 100644 --- a/docs/docs/documentation/getting-started/faq.md +++ b/docs/docs/documentation/getting-started/faq.md @@ -84,6 +84,16 @@ docker exec -it mealie bash python /app/mealie/scripts/reset_locked_users.py ``` +## How can I reset admin privileges for my account? + +If you've lost admin privileges and no other admin can restore them, you can use the Command Line Interface (CLI) to grant admin access. + +```shell +docker exec -it mealie bash + +python /app/mealie/scripts/make_admin.py +``` + ## How can I change my password? You can change your password by going to the user profile page and clicking the "Change Password" button. Alternatively you can use the following script to change your password via the CLI if you are locked out of your account. diff --git a/docs/docs/overrides/api.html b/docs/docs/overrides/api.html index 00328079e4f..8c7f4880deb 100644 --- a/docs/docs/overrides/api.html +++ b/docs/docs/overrides/api.html @@ -14,7 +14,7 @@
diff --git a/mealie/scripts/make_admin.py b/mealie/scripts/make_admin.py new file mode 100644 index 00000000000..71fd20ec01d --- /dev/null +++ b/mealie/scripts/make_admin.py @@ -0,0 +1,30 @@ +import sys + +from mealie.core import root_logger +from mealie.db.db_setup import session_context +from mealie.repos.repository_factory import AllRepositories + + +def main(): + confirmed = input("Enter user email to assign this user admin privileges: ") + + logger = root_logger.get_logger() + + with session_context() as session: + repos = AllRepositories(session, group_id=None, household_id=None) + + user = repos.users.get_one(confirmed, "email") + if not user: + logger.error("no user found") + sys.exit(1) + + user.admin = True + repos.users.update(user.id, user) + + logger.info("updated user %s to admin", user.username) + input("press enter to exit ") + sys.exit(0) + + +if __name__ == "__main__": + main()