fixed /setadmin function
This commit is contained in:
parent
42a5ad4a12
commit
b347c10653
@ -9,6 +9,7 @@ __license__ = "None"
|
||||
#side-dependencies: none
|
||||
#Work in Progress
|
||||
|
||||
from email import header
|
||||
import sys
|
||||
import os
|
||||
import requests as r
|
||||
@ -340,14 +341,14 @@ class API_Handler:
|
||||
|
||||
Args:
|
||||
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:
|
||||
int: status code
|
||||
"""
|
||||
with r.Session() as s:
|
||||
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
|
||||
|
||||
|
||||
|
@ -136,7 +136,7 @@ def set_admin(message):
|
||||
bot.reply_to(message, "You have to be an admin to use this command")
|
||||
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)
|
||||
|
||||
def set_admin_step(message):
|
||||
@ -149,7 +149,10 @@ def set_admin_step(message):
|
||||
return
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user