diff --git a/bot_modules/access.py b/bot_modules/access.py index 9d2416e..97455c5 100644 --- a/bot_modules/access.py +++ b/bot_modules/access.py @@ -13,11 +13,9 @@ from aiogram.dispatcher.filters.state import State, StatesGroup class FSMRequestToBDAccess(StatesGroup): sqlRequest = State() - class FSMEditAccessItem(StatesGroup): item_field = State() - class FSMEditDefaultAccessItem(StatesGroup): item_field = State() # --------------------------------------------------------- @@ -80,7 +78,7 @@ moduleaccess_edit_access_message = f''' Введите новую строку доступа: ''' -edit_moduleaccess_default_access_button_name = "◈ Изменить доступ по умолчанию к модулю " +edit_moduleaccess_default_access_button_name = "◈ Изменить доступ по умолчанию" moduleaccess_edit_default_access_message = f''' Текущий доступ по умолчанию к модулю #{mod_name_field}: #{mod_default_access_field} @@ -93,12 +91,17 @@ moduleaccess_success_edit_message = '''✅ Доступ к модулю успе button_names = { mod_simple_message.ButtonNames.START: start_button_name, - mod_table_operate.ButtonNames.EDIT_ACCESS: "◇ Изменить доступ к модулю", - mod_table_operate.ButtonNames.EDIT_DEFAULT_ACCESS: "◈ Изменить доступ по умолчанию к модулю ", + mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать доступ", + mod_table_operate.ButtonNames.EDIT_ACCESS: edit_moduleaccess_access_button_name, + mod_table_operate.ButtonNames.EDIT_DEFAULT_ACCESS: edit_moduleaccess_default_access_button_name, } messages = { mod_simple_message.Messages.START: start_message, + mod_table_operate.Messages.START_EDIT: ''' +Пожалуйста, выберите действие: +''', + mod_table_operate.Messages.SELECT_TO_EDIT: moduleaccess_select_to_edit_message, mod_table_operate.Messages.EDIT_ACCESS: moduleaccess_edit_access_message, mod_table_operate.Messages.EDIT_DEFAULT_ACCESS: moduleaccess_edit_default_access_message, mod_table_operate.Messages.SUCCESS_EDIT: moduleaccess_success_edit_message, @@ -127,17 +130,13 @@ class ModuleAccess(mod_table_operate.TableOperateModule): None, self.m_GetAccessFunc ) - ''' - def GetInitBDCommands(self): - return [ - f"""CREATE TABLE IF NOT EXISTS {table_name}( - {mod_name_field} TEXT, - {moduleaccess_field} TEXT, - {mod_default_access_field} TEXT, - UNIQUE({mod_name_field}) - );""", - ] + super().GetInitBDCommands() - ''' + + def GetButtonNameAndKeyValueAndAccess(self, a_Item): + return \ + a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)],\ + a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)],\ + a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)] + def GetName(self): return module_name diff --git a/bot_modules/mod_simple_message.py b/bot_modules/mod_simple_message.py index fffa8c8..8ef5a65 100644 --- a/bot_modules/mod_simple_message.py +++ b/bot_modules/mod_simple_message.py @@ -69,6 +69,9 @@ class SimpleMessageModule(mod_interface.IModule): return msg def CreateButton(self, a_ButtonName, a_ButtonDesc): + assert len(a_ButtonDesc) < 41 # Телеграм не поддерживает больше + assert a_ButtonDesc[0] != ' ' # Телеграм не поддерживает пробелы в начале + assert a_ButtonDesc[-1:] != ' ' # Телеграм не поддерживает пробелы в конце btn = self.m_BotButtons.CreateMessage(f'{self.GetName()} {a_ButtonName}', a_ButtonDesc, self.m_Log.GetTimeNow()) return btn diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index 1817686..3291662 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -92,7 +92,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): keyboard.ButtonWithAccess(self.GetButton(ButtonNames.LIST), user_access.AccessMode.VIEW, self.GetAccess()), keyboard.ButtonWithAccess(self.GetButton(ButtonNames.ADD), user_access.AccessMode.ADD, self.GetAccess()), keyboard.ButtonWithAccess(self.GetButton(ButtonNames.DEL), user_access.AccessMode.DELETE, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT), user_access.AccessMode.EDIT, self.GetAccess()) + keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT), user_access.AccessMode.EDIT, self.GetAccess()), ] return mod_buttons + keyboard.MakeButtons(cur_buttons, a_UserGroups) @@ -102,7 +102,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_PHOTO), user_access.AccessMode.VIEW, self.GetAccess()), keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_NAME), user_access.AccessMode.ADD, self.GetAccess()), keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_DESC), user_access.AccessMode.DELETE, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_ACCESS), user_access.AccessMode.EDIT, self.GetAccess()) + keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_ACCESS), user_access.AccessMode.DELETE, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), user_access.AccessMode.EDIT, self.GetAccess()), ] return mod_buttons + keyboard.MakeButtons(cur_buttons, a_UserGroups) @@ -140,7 +141,9 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return simple_message.WorkFuncResult(self.GetMessage(Messages.ERROR_FIND)) elif len(a_Item) == self.m_Table.GetFieldsCount(): msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(msg.GetDesc(), a_Item)) - msg.UpdatePhotoID(a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO)]) + photo_field = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO) + if photo_field: + msg.UpdatePhotoID(a_Item[photo_field]) item_access = a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)] if Inline_keyboard_template_func: Inline_keyboard_func = Inline_keyboard_template_func(a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)]) @@ -330,10 +333,10 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return a_Prefix = self.RegisterSelect(a_ButtonName, a_AccessMode, only_parent = True) - check_func = bd_item.GetCheckForTextFunc(a_ButtonName) if a_Prefix: check_func = bd_item.GetCheckForPrefixFunc(a_Prefix) + #print(a_ButtonName, a_Prefix, check_func) bd_item_edit.EditBDItemRegisterHandlers(self.m_Bot, \ a_Prefix, \ a_FSM, \ diff --git a/bot_sys/keyboard.py b/bot_sys/keyboard.py index b0ecbc4..9dde72a 100644 --- a/bot_sys/keyboard.py +++ b/bot_sys/keyboard.py @@ -41,8 +41,9 @@ def MakeButtons(a_ButtonList : [ButtonWithAccess], a_UserGroups): for b in a_ButtonList: if not b.label: continue + label = str(b.label) if user_access.CheckAccessString(b.access_string, a_UserGroups, b.access_mode): - buttons += [types.KeyboardButton(str(b.label))] + buttons += [types.KeyboardButton(label)] step = GetButtonInRowCount(len(buttons)) return Chunks(buttons, step) @@ -83,7 +84,9 @@ def MakeInlineKeyboardButtons(a_ButtonList : [InlineButtonWithAccess], a_UserGro buttons = [] for b in a_ButtonList: if user_access.CheckAccessString(b.access_string, a_UserGroups, b.access_mode): - buttons += [InlineButton(b.label, f'{b.callback_prefix}{b.callback_data}')] + data = f'{b.callback_prefix}{b.callback_data}' + assert len(data) < 41 # Телеграм больше не поддерживает + buttons += [InlineButton(b.label, data)] step = GetButtonInRowCount(len(buttons)) return Chunks(buttons, step)