fixed /setadmin function

This commit is contained in:
Linus E 2022-04-26 12:21:37 +02:00
parent 42a5ad4a12
commit b347c10653
2 changed files with 9 additions and 5 deletions

View File

@ -9,6 +9,7 @@ __license__ = "None"
#side-dependencies: none #side-dependencies: none
#Work in Progress #Work in Progress
from email import header
import sys import sys
import os import os
import requests as r import requests as r
@ -340,14 +341,14 @@ class API_Handler:
Args: Args:
email (string): email of the user email (string): email of the user
is_admin (String): "true" if user should be Admin, "false" if not is_admin (bool): "true" if user should be Admin, "false" if not
Returns: Returns:
int: status code int: status code
""" """
with r.Session() as s: with r.Session() as s:
headers = {'Authorization': 'Bearer ' + self.token} # only bot token is needed, user is chosen by email headers = {'Authorization': 'Bearer ' + self.token} # only bot token is needed, user is chosen by email
req = s.put(self.db_adress + "/user/setAdmin", json={"admin": str(is_admin),"email": str(email)}) req = s.put(self.db_adress + "/user/setAdmin", json={"admin": is_admin,"email": str(email)}, headers=headers)
return req.status_code return req.status_code

View File

@ -136,7 +136,7 @@ def set_admin(message):
bot.reply_to(message, "You have to be an admin to use this command") bot.reply_to(message, "You have to be an admin to use this command")
return return
bot.send_message(chat_id=user_id, text='send email and "true" if this account should have admin rights, else "false"\n in format: <email>,<is_admin>') # ask for email and admin rights to set bot.send_message(chat_id=user_id, text='send email and true if this account should have admin rights, else false\n in format: <email>,<is_admin>') # request email and admin rights to change to
bot.register_next_step_handler(message, set_admin_step) bot.register_next_step_handler(message, set_admin_step)
def set_admin_step(message): def set_admin_step(message):
@ -149,7 +149,10 @@ def set_admin_step(message):
return return
email = args_message[0] email = args_message[0]
is_admin = args_message[1] is_admin = False # default: False
if args_message[1].lower() == "true": # if user types true, set is_admin to true
is_admin = True
status = api_handler.set_admin(email, is_admin) # set admin in db status = api_handler.set_admin(email, is_admin) # set admin in db