operation_list = ["create_post", "delete_user", "view_logs"]
pemission_dict = {"Admin":["create_post", "delete_user", "view_logs"], "Editor":["create_post"],"Viewer":["view_logs"]}
user_dict = {"Alice": "Admin", "Bob":"Editor", "Carl":"Viewer"}
temporary_dict = {}
while True:
command = input("command:")
ifcommand == "login":
user = input("Username:")
if user in user_dict:
operation = input("Operation: create_post, delete_user, view_logs")
if operation in operation_list:
if operation in pemission_dict[user]:
print("Finished.")
elif user in temporary_dict and operation == temporary_dict[user]:
print("Finished.")
temporary_dict.pop(user)
else:
print("You're not allowed to do this")
else:
print("Illegal operation!!!")
else:
print("Illegal username!!!")
elifcommand == "change role":
pw = input("Password:")
if pw == "123":
user = input("Username:")
if user in user_dict:
role = input("Which role:")
if role in pemission_dict:
user_dict[user] = role
else:
print("Illegal role!!!")
else:
print("Illegal username!!!")
else:
print("Wrong password!!!")
elifcommand == "temporary change":
pw = input("Password:")
if pw == "123":
user = input("Username:")
if user in user_dict:
operation = input("Which operation:")
if operation in operation_list:
temporary_dict[user] = operation
else:
print("Illegal operation!!!")
else:
print("Illegal username!!!")
else:
print("Wrong password!!!")
elifcommand == "exit":
breakelse:
print("Wrong command. Commands: login, change role, temporary change and exit.")