diff --git a/database.py b/database.py
index 4ecc4e0..524025c 100644
--- a/database.py
+++ b/database.py
@@ -194,9 +194,9 @@ class Admin(TableDeclarativeBase):
user_id = Column(BigInteger, ForeignKey("users.user_id"), primary_key=True)
user = relationship("User")
# Permissions
- edit_products = Column(Boolean, default=True)
- receive_orders = Column(Boolean, default=True)
- create_transactions = Column(Boolean, default=True)
+ edit_products = Column(Boolean, default=False)
+ receive_orders = Column(Boolean, default=False)
+ create_transactions = Column(Boolean, default=False)
display_on_help = Column(Boolean, default=False)
is_owner = Column(Boolean, default=False)
# Live mode enabled
diff --git a/strings.py b/strings.py
index a42142e..5ad919a 100644
--- a/strings.py
+++ b/strings.py
@@ -210,6 +210,12 @@ emoji_completed = "✅"
# Emoji: refunded order
emoji_refunded = "✴️"
+# Emoji: yes
+emoji_yes = "✅"
+
+# Emoji: no
+emoji_no = "🚫"
+
# Text: unprocessed order
text_not_processed = "in sospeso"
@@ -257,6 +263,18 @@ ask_credit = "Di quanto vuoi modificare il credito del cliente?\n" \
"Metti un segno +
se vuoi aggiungere credito all'account del cliente," \
" oppure un segno -
se vuoi dedurlo."
+# Edit admin: can edit products?
+ask_edit_products = "Vuoi che l'amministratore sia autorizzato a modificare la configurazione dei prodotti?"
+
+# Edit admin: can receive orders?
+ask_receive_orders = "Vuoi che l'amministratore sia autorizzato a ricevere e gestire gli ordini?"
+
+# Edit admin: can create transactions?
+ask_create_transactions = "Vuoi che l'amministratore sia autorizzato a creare nuove transazioni?"
+
+# Edit admin: should be displayed on help
+ask_display_on_help = "Vuoi che l'amministratore venga visualizzato nella sezione Contatta il negozio?"
+
# Thread has started downloading an image and might be unresponsive
downloading_image = "Sto scaricando la tua foto!\n" \
"Potrei metterci un po'... Abbi pazienza!\n" \
diff --git a/worker.py b/worker.py
index 9cd2710..3dcad97 100644
--- a/worker.py
+++ b/worker.py
@@ -250,6 +250,34 @@ class ChatWorker(threading.Thread):
# Return the callbackquery
return update.callback_query
+ def __user_select(self) -> typing.Union[db.User, CancelSignal]:
+ """Select an user from the ones in the database."""
+ # Find all the users in the database
+ users = self.session.query(db.User).order_by(db.User.user_id).all()
+ # Create a list containing all the keyboard button strings
+ keyboard_buttons = [[strings.menu_cancel]]
+ # Add to the list all the users
+ for user in users:
+ keyboard_buttons.append([user.identifiable_str()])
+ # Create the keyboard
+ keyboard = telegram.ReplyKeyboardMarkup(keyboard_buttons, one_time_keyboard=True)
+ # Keep asking until a result is returned
+ while True:
+ # Send the keyboard
+ self.bot.send_message(self.chat.id, strings.conversation_admin_select_user, reply_markup=keyboard)
+ # Wait for a reply
+ reply = self.__wait_for_regex("user_([0-9]+)", cancellable=True)
+ # Allow the cancellation of the operation
+ if reply == strings.menu_cancel:
+ return CancelSignal()
+ # Find the user in the database
+ user = self.session.query(db.User).filter_by(user_id=int(reply)).one_or_none()
+ # Ensure the user exists
+ if not user:
+ self.bot.send_message(self.chat.id, strings.error_user_does_not_exist)
+ continue
+ return user
+
def __user_menu(self):
"""Function called from the run method when the user is not an administrator.
Normal bot actions should be placed here."""
@@ -924,27 +952,8 @@ class ChatWorker(threading.Thread):
def __create_transaction(self):
"""Edit manually the credit of an user."""
- # Find all the users in the database
- users = self.session.query(db.User).order_by(db.User.user_id).all()
- # Create a list containing all the keyboard button strings
- keyboard_buttons = [[strings.menu_cancel]]
- # Add to the list all the users
- for user in users:
- keyboard_buttons.append([user.identifiable_str()])
- # Create the keyboard
- keyboard = telegram.ReplyKeyboardMarkup(keyboard_buttons, one_time_keyboard=True)
- # Send the keyboard
- self.bot.send_message(self.chat.id, strings.conversation_admin_select_user, reply_markup=keyboard)
- # Wait for a reply
- reply = self.__wait_for_regex("user_([0-9]+)", cancellable=True)
- # Allow the cancellation of the operation
- if reply == strings.menu_cancel:
- return
- # Find the user in the database
- user = self.session.query(db.User).filter_by(user_id=int(reply)).one_or_none()
- # Ensure the user exists
- if not user:
- self.bot.send_message(self.chat.id, strings.error_user_does_not_exist)
+ # Make the admin select an user
+ user = self.__user_select()
# Create an inline keyboard with a single cancel button
cancel = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton(strings.menu_cancel,
callback_data="cmd_cancel")]])