From 6c67b2e3e641b12c50db0ace3aa36fd937e813dd Mon Sep 17 00:00:00 2001 From: Alexei Date: Sat, 4 Nov 2023 13:08:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D0=B5=D0=B9=201.=20=D0=9A=D0=BD?= =?UTF-8?q?=D0=BE=D0=BF=D0=BA=D0=B0=20=D0=B7=D0=B0=D1=8F=D0=B2=D0=BA=D0=B0?= =?UTF-8?q?=20=D1=83=D0=B1=D0=B8=D1=80=D0=B0=D0=B5=D1=82=D1=81=D1=8F=202.?= =?UTF-8?q?=20=D0=9F=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB=D1=87=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8E=20=D0=B7=D0=B0=D1=8F=D0=B2=D0=BA=D0=B8=20=D0=B4?= =?UTF-8?q?=D1=80=D1=83=D0=B3=D0=B8=D1=85=20=D0=BD=D0=B5=20=D0=B2=D0=B8?= =?UTF-8?q?=D0=B4=D0=BD=D1=8B=203.=20=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D0=B0=20=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/access.py | 2 +- bot_modules/all_orders.py | 2 +- bot_modules/authorize.py | 37 +++++++++++++++++++-------- bot_modules/backup.py | 2 +- bot_modules/bd_version.py | 2 +- bot_modules/buttons.py | 2 +- bot_modules/comments.py | 2 +- bot_modules/groups.py | 4 +-- bot_modules/groups_utils.py | 6 ++++- bot_modules/languages.py | 2 +- bot_modules/messages.py | 2 +- bot_modules/mod_simple_message.py | 5 ++-- bot_modules/mod_table_operate.py | 48 +++++++++++++++++++++++------------ bot_modules/needs.py | 2 +- bot_modules/orders.py | 6 ++--- bot_modules/profile.py | 2 +- bot_modules/projects.py | 2 +- bot_modules/start.py | 2 +- bot_modules/subscribes.py | 6 ++--- bot_modules/tasks.py | 2 +- bot_modules/user_in_groups.py | 2 +- bot_modules/users.py | 2 +- bot_modules/users_groups_agregator.py | 9 ++++++- template/docs_message.py | 7 ++--- 24 files changed, 100 insertions(+), 58 deletions(-) diff --git a/bot_modules/access.py b/bot_modules/access.py index c5b9b6b..da020e4 100644 --- a/bot_modules/access.py +++ b/bot_modules/access.py @@ -106,7 +106,7 @@ init_access = f'{user_access.user_access_group_new}=-' class ModuleAccess(mod_table_operate.TableOperateModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, None, None, init_access, a_ChildModuleNameList, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, None, None, init_access, init_access, a_ChildModuleNameList, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) self.m_SqlRequestButtonName = self.CreateButton('sql request', sql_request_button_name) self.m_RequestStartMessage = self.CreateMessage('equest start', request_start_message) diff --git a/bot_modules/all_orders.py b/bot_modules/all_orders.py index 5efd31f..9f40bb9 100644 --- a/bot_modules/all_orders.py +++ b/bot_modules/all_orders.py @@ -111,7 +111,7 @@ class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource): class ModuleAllOrders(orders.ModuleOrders): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetInitBDCommands(self): # уже сделано в ModuleUserOrders diff --git a/bot_modules/authorize.py b/bot_modules/authorize.py index 9c39865..cc9f9e3 100644 --- a/bot_modules/authorize.py +++ b/bot_modules/authorize.py @@ -4,7 +4,7 @@ # Авторизация или регистрация в кооперативе или другой организации from bot_sys import bot_bd, keyboard, user_access, bd_table, bot_subscribes, config -from bot_modules import mod_table_operate, mod_simple_message +from bot_modules import mod_table_operate, mod_simple_message, users_groups_agregator, groups_utils from template import docs_message, bd_item, bd_item_select from enum import Enum @@ -50,6 +50,8 @@ table = bd_table.Table(table_name, [ ) init_access = f'{user_access.user_access_group_new}=va' +def_init_access = f'{user_access.user_access_group_new}=a' +g_group_auth_name = 'authorize_users' def GetAuthorizeItem(a_Bot, a_UserID): items = bd_item.GetBDItemsTemplate(a_Bot, table_name, user_id_field)(a_UserID) @@ -246,7 +248,7 @@ messages.update(messages_confirm_status) class ModuleAuthorize(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, def_init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name @@ -279,18 +281,23 @@ class ModuleAuthorize(mod_table_operate.TableOperateModule): a_Item[key_name_id],\ a_Item[access_field_id] - def GetStartKeyboardButtons(self, a_Message, a_UserGroups): - parent_buttons = super().GetStartKeyboardButtons(a_Message, a_UserGroups) + def GetStartButtons(self, a_Message, a_UserGroups): user_id = str(a_Message.from_user.id) item = GetAuthorizeItem(self.m_Bot, user_id) user_confirm_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.USER_CONFIRM) - print('GetStartKeyboardButtons', item, user_confirm_field_id) + cur_buttons = [] + if item and item[user_confirm_field_id] == self.GetMessage(mod_table_operate.EnumMessageForView(ConfirmStatus.YES)).GetDesc(): - cur_buttons += [ - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.LIST_AUTH_DOCS), user_access.AccessMode.VIEW, self.GetAccess()), - ] - return parent_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) + cur_buttons += [[ButtonNames.LIST_AUTH_DOCS, user_access.AccessMode.VIEW]] + else: + cur_buttons += [[mod_table_operate.ButtonNames.ADD, user_access.AccessMode.ADD]] + + return cur_buttons + [ + [mod_table_operate.ButtonNames.LIST, user_access.AccessMode.VIEW], + [mod_table_operate.ButtonNames.DEL, user_access.AccessMode.DELETE], + [mod_table_operate.ButtonNames.EDIT, user_access.AccessMode.EDIT], + ] def RegisterHandlers(self): super().RegisterHandlers() @@ -323,7 +330,17 @@ class ModuleAuthorize(mod_table_operate.TableOperateModule): def AddBDItemFunc(self, a_ItemData, a_UserID): a_ItemData[user_id_field] = a_UserID #a_ItemData[address_field] = '' - return super().AddBDItemFunc(a_ItemData, a_UserID) + result = super().AddBDItemFunc(a_ItemData, a_UserID) + users_groups_agregator.AddUserInGroup(self.m_Bot, a_UserID, g_group_auth_name) + return result + + def GetKeyFieldDestiny(self): + return bd_table.TableFieldDestiny.USER_ID + + def GetInitBDCommands(self): + return super(). GetInitBDCommands() + [ + groups_utils.CreateGroupRequest(g_group_auth_name) + ] def GetReplaceDictFunc(a_Bot, a_user_id): item = GetAuthorizeItem(a_Bot, a_user_id) diff --git a/bot_modules/backup.py b/bot_modules/backup.py index cf294a2..dc7b989 100644 --- a/bot_modules/backup.py +++ b/bot_modules/backup.py @@ -48,7 +48,7 @@ init_access = f'{user_access.user_access_group_new}=-' class ModuleBackup(mod_simple_message.SimpleMessageModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(messages, button_names, init_access, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(messages, button_names, init_access, init_access, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) self.m_BackupBDButtonName = self.CreateButton('backup bd', backup_bd_button_name) self.m_BackupBDMessage = self.CreateMessage('backup bd', backup_bd_message) diff --git a/bot_modules/bd_version.py b/bot_modules/bd_version.py index d74dfd9..081a075 100644 --- a/bot_modules/bd_version.py +++ b/bot_modules/bd_version.py @@ -40,7 +40,7 @@ messages = { class ModuleBDVersion(mod_table_operate.TableOperateModule): def __init__(self, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, None, None, init_access, None, None, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, None, None, init_access, init_access, None, None, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/buttons.py b/bot_modules/buttons.py index 63e77fa..09dbfda 100644 --- a/bot_modules/buttons.py +++ b/bot_modules/buttons.py @@ -128,7 +128,7 @@ messages = { class ModuleButtons(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/comments.py b/bot_modules/comments.py index 953169f..b5c8457 100644 --- a/bot_modules/comments.py +++ b/bot_modules/comments.py @@ -130,7 +130,7 @@ messages.update(messages_subscribes) class ModuleComments(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/groups.py b/bot_modules/groups.py index c82485c..4e10654 100644 --- a/bot_modules/groups.py +++ b/bot_modules/groups.py @@ -125,12 +125,12 @@ messages = { class ModuleGroups(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name def GetInitBDCommands(self): return super(). GetInitBDCommands() + [ - f"INSERT OR IGNORE INTO {table_name} ({name_field}, {access_field}, {create_datetime_field}) VALUES ('{user_access.user_access_group_new}', '{user_access.user_access_group_new}=-', {bot_bd.GetBDDateTimeNow()});" + groups_utils.CreateGroupRequest(user_access.user_access_group_new) ] diff --git a/bot_modules/groups_utils.py b/bot_modules/groups_utils.py index 1bc67a0..27b2bbe 100644 --- a/bot_modules/groups_utils.py +++ b/bot_modules/groups_utils.py @@ -3,7 +3,7 @@ # Группы пользователей -from bot_sys import user_access +from bot_sys import user_access, bot_bd table_name = 'user_groups' key_name = 'groupID' @@ -28,3 +28,7 @@ def GetUserGroupData(a_Bot, a_UserID): if len(i) > 0: groups += [i[0]] return user_access.UserGroups(a_UserID, groups) + +def CreateGroupRequest(a_GroupName): + return f"INSERT OR IGNORE INTO {table_name} ({name_field}, {access_field}, {create_datetime_field}) VALUES ('{a_GroupName}', '{user_access.user_access_group_new}=-', {bot_bd.GetBDDateTimeNow()});" + diff --git a/bot_modules/languages.py b/bot_modules/languages.py index 06d0835..b3022fb 100644 --- a/bot_modules/languages.py +++ b/bot_modules/languages.py @@ -126,7 +126,7 @@ messages = { class ModuleLanguages(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) self.m_LanguageIDs = {} def GetName(self): diff --git a/bot_modules/messages.py b/bot_modules/messages.py index 310b043..27ca51f 100644 --- a/bot_modules/messages.py +++ b/bot_modules/messages.py @@ -128,7 +128,7 @@ messages = { class ModuleMessages(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/mod_simple_message.py b/bot_modules/mod_simple_message.py index a533a9d..8f5e9a3 100644 --- a/bot_modules/mod_simple_message.py +++ b/bot_modules/mod_simple_message.py @@ -17,9 +17,10 @@ class Messages(Enum): START = auto() class SimpleMessageModule(mod_interface.IModule): - def __init__(self, a_Messages, a_Buttons, a_InitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): + def __init__(self, a_Messages, a_Buttons, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): self.m_ChildModuleNameList = a_ChildModuleNameList self.m_InitAccess = a_InitAccess + self.m_DefInitAccess = a_DefInitAccess self.m_Bot = a_Bot self.m_ModuleAgregator = a_ModuleAgregator self.m_BotMessages = a_BotMessages @@ -99,7 +100,7 @@ class SimpleMessageModule(mod_interface.IModule): def GetInitBDCommands(self): return [ - access_utils.GetAccessForModuleRequest(self.GetName(), self.m_InitAccess, self.m_InitAccess), + access_utils.GetAccessForModuleRequest(self.GetName(), self.m_InitAccess, self.m_DefInitAccess), ] def GetAccess(self): diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index f826fc8..5c257c4 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -83,8 +83,8 @@ def MakeFSMForEdit(a_ModName, a_FieldName): return _locals['fsm'] class TableOperateModule(mod_simple_message.SimpleMessageModule): - def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(a_Messages, a_Buttons, a_InitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): + super().__init__(a_Messages, a_Buttons, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) self.m_Table = a_Table self.m_EditModuleNameList = a_EditModuleNameList self.m_ChildModName = a_ChildModName @@ -99,8 +99,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return self.GetButtonNameAndKeyValueAndAccess(a_Item) self.m_GetButtonNameAndKeyValueAndAccessFunc = GetButtonNameAndKeyValueAndAccess - async def PreDelete(a_CallbackQuery, a_Item): - return await self.PreDelete(a_CallbackQuery, a_Item) + async def PreDelete(a_CallbackQuery, a_Item, a_None): + return await self.PreDelete(a_CallbackQuery, a_Item, a_None) self.m_PreDeleteFunc = PreDelete async def PostDelete(a_CallbackQuery, a_ItemID): @@ -116,14 +116,21 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): self.m_Table.GetInitTableRequest(), ] + super().GetInitBDCommands() + def GetStartButtons(self, a_Message, a_UserGroups): + return [ + [ButtonNames.LIST, user_access.AccessMode.VIEW], + [ButtonNames.ADD, user_access.AccessMode.ADD], + [ButtonNames.DEL, user_access.AccessMode.DELETE], + [ButtonNames.EDIT, user_access.AccessMode.EDIT], + ] + def GetStartKeyboardButtons(self, a_Message, a_UserGroups): mod_buttons = super().GetStartKeyboardButtons(a_Message, a_UserGroups) - cur_buttons = [ - 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()), - ] + cur_buttons = [] + for b in self.GetStartButtons(a_Message, a_UserGroups): + bn = b[0] + ba = b[1] + cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(bn), ba, self.GetAccess())] return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) def GetAccessForEditKeyboardButtons(self, a_Field): @@ -157,7 +164,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return keyboard.MakeInlineKeyboardButtons(self.m_Bot, cur_buttons, a_UserGroups) def GetButtonNameAndKeyValueAndAccess(self, a_Item): - key_name_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY) + key_name_id = self.GetKeyFieldID() name_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.NAME) access_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS) assert key_name_id != None @@ -220,12 +227,12 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): msg = self.UpdateMessage(msg, lang, a_Item, a_EnablePhoto = a_EnablePhoto) 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)]) + Inline_keyboard_func = Inline_keyboard_template_func(a_Item[self.GetKeyFieldID()]) return simple_message.WorkFuncResult(msg, item_access = item_access, Inline_keyboard_func = Inline_keyboard_func) return ShowMessage - async def PreDelete(self, a_CallbackQuery, a_Item): + async def PreDelete(self, a_CallbackQuery, a_Item, a_None): if len(a_Item) < self.m_Table.GetFieldsCount(): return simple_message.WorkFuncResult(self.GetMessage(Messages.ERROR_FIND)) access = a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)] @@ -379,7 +386,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return self.OnChange() table_name = self.m_Table.GetName() - key_name = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY) + key_name = self.GetKeyFieldName() edit_keyboard_func = self.m_GetEditKeyboardButtonsFunc GetButtonNameAndKeyValueAndAccess = self.m_GetButtonNameAndKeyValueAndAccessFunc GetAccess = self.m_GetAccessFunc @@ -469,10 +476,19 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): f = fields[f_id] self.m_Bot.RegisterMessageHandler(bd_item_add.FinishAddBDItemTemplate(self.m_Bot, fsm, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, f.m_Name, self.ShowMessageTemplate(self.GetMessage(Messages.SUCCESS_CREATE)), None, a_AccessFunc, a_ButtonFunc, access_mode, field_type = GetFieldType(f)), content_types = GetContentTypes(f), state = getattr(fsm, f'item{f_id}')) + def GetKeyFieldDestiny(self): + return bd_table.TableFieldDestiny.KEY + + def GetKeyFieldName(self): + return self.m_Table.GetFieldNameByDestiny(self.GetKeyFieldDestiny()) + + def GetKeyFieldID(self): + return self.m_Table.GetFieldIDByDestiny(self.GetKeyFieldDestiny()) + def RegisterHandlers(self): super().RegisterHandlers() table_name = self.m_Table.GetName() - key_name = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY) + key_name = self.GetKeyFieldName() name_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.NAME) desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC) photo_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PHOTO) @@ -485,7 +501,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): if self.m_ParentModName: parent_mod = self.GetModule(self.m_ParentModName) parent_table_name = parent_mod.m_Table.GetName() - parent_key_name = parent_mod.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY) + parent_key_name = parent_mod.GetKeyFieldName() def GetViewItemInlineKeyboardTemplate(a_ItemID): return self.GetViewItemInlineKeyboardTemplate(a_ItemID) diff --git a/bot_modules/needs.py b/bot_modules/needs.py index 0f0bf2f..ace1d88 100644 --- a/bot_modules/needs.py +++ b/bot_modules/needs.py @@ -131,7 +131,7 @@ messages.update(messages_subscribes) class ModuleNeeds(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/orders.py b/bot_modules/orders.py index 3559006..edf6fd0 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -200,8 +200,8 @@ class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource): return True class ModuleOrders(mod_table_operate.TableOperateModule): - def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): + super().__init__(table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def SelectSourceTemplate(self, a_PrevPrefix, a_ButtonName): parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) @@ -262,7 +262,7 @@ class ModuleOrders(mod_table_operate.TableOperateModule): class ModuleUserOrders(ModuleOrders): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/profile.py b/bot_modules/profile.py index f0c2a67..c584a07 100644 --- a/bot_modules/profile.py +++ b/bot_modules/profile.py @@ -32,7 +32,7 @@ init_access = f'{user_access.user_access_group_new}=+' class ModuleProfile(mod_simple_message.SimpleMessageModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(messages, button_names, init_access, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(messages, button_names, init_access, init_access, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/projects.py b/bot_modules/projects.py index becbc93..a3fc0c0 100644 --- a/bot_modules/projects.py +++ b/bot_modules/projects.py @@ -129,7 +129,7 @@ messages.update(messages_subscribes) class ModuleProjects(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/start.py b/bot_modules/start.py index dc55776..58d3c63 100644 --- a/bot_modules/start.py +++ b/bot_modules/start.py @@ -24,7 +24,7 @@ init_access = f'{user_access.user_access_group_all}=+' class ModuleStart(mod_simple_message.SimpleMessageModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(messages, button_names, init_access, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(messages, button_names, init_access, init_access, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/subscribes.py b/bot_modules/subscribes.py index a807b8d..6c4e663 100644 --- a/bot_modules/subscribes.py +++ b/bot_modules/subscribes.py @@ -171,8 +171,8 @@ class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource): return True class ModuleSubscribe(mod_table_operate.TableOperateModule): - def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): + super().__init__(table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def SelectSourceTemplate(self, a_PrevPrefix, a_ButtonName): parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) @@ -205,7 +205,7 @@ class ModuleSubscribe(mod_table_operate.TableOperateModule): class ModuleUserSubscribe(ModuleSubscribe): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) self.UpdateSubscribes() def GetName(self): diff --git a/bot_modules/tasks.py b/bot_modules/tasks.py index 8e148b7..1523adb 100644 --- a/bot_modules/tasks.py +++ b/bot_modules/tasks.py @@ -131,7 +131,7 @@ messages.update(messages_subscribes) class ModuleTasks(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/user_in_groups.py b/bot_modules/user_in_groups.py index f2e7830..3509cad 100644 --- a/bot_modules/user_in_groups.py +++ b/bot_modules/user_in_groups.py @@ -106,7 +106,7 @@ messages = { class ModuleUserInGroups(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/users.py b/bot_modules/users.py index e4feaee..ba92907 100644 --- a/bot_modules/users.py +++ b/bot_modules/users.py @@ -128,7 +128,7 @@ messages = { class ModuleUsers(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) def GetName(self): return module_name diff --git a/bot_modules/users_groups_agregator.py b/bot_modules/users_groups_agregator.py index 4c4533a..7c29fe7 100644 --- a/bot_modules/users_groups_agregator.py +++ b/bot_modules/users_groups_agregator.py @@ -57,7 +57,7 @@ init_access = f'{user_access.user_access_group_new}=-' class ModuleUsersGroupsAgregator(mod_simple_message.SimpleMessageModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): - super().__init__(messages, button_names, init_access, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) + super().__init__(messages, button_names, init_access, init_access, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) self.m_SqlRequestButtonName = self.CreateButton('sql request', sql_request_button_name) self.m_RequestStartMessage = self.CreateMessage('equest start', request_start_message) @@ -99,3 +99,10 @@ class ModuleUsersGroupsAgregator(mod_simple_message.SimpleMessageModule): bd_item.GetCheckForTextFunc(self.m_HelpButtonName) ) +def AddUserInGroup(a_Bot, a_UserID, a_GroupName): + g_id = a_Bot.SQLRequest(f'SELECT {groups.key_name} FROM {groups.table_name} WHERE {groups.name_field} = "{a_GroupName}"'); + print ('AddUserInGroup', g_id) + if not g_id or len(g_id) != 1 or len(g_id[0]) != 1: + return False + group_id = g_id[0][0] + a_Bot.SQLRequest(f'INSERT INTO {user_in_groups.table_name}({user_in_groups.name_field}, {user_in_groups.parent_id_field}) VALUES({a_UserID}, {group_id})') diff --git a/template/docs_message.py b/template/docs_message.py index 3f9288a..9354644 100644 --- a/template/docs_message.py +++ b/template/docs_message.py @@ -43,14 +43,12 @@ def DocFilesTemplate(a_Bot, a_FilesFunc, a_CaptionMessage, a_AccessFunc, a_GetBu async def ReplaceInFile(a_Bot, a_InputFileName, a_OutFileName, a_DictReplace): try: filedata = '' - print('ReplaceInFile f', a_InputFileName) + with open(a_InputFileName, 'r') as in_f: filedata = in_f.read() - s = filedata - print('ReplaceInFile s', s) + for rep_this, to_this in a_DictReplace.items(): - print('ReplaceInFile', rep_this, to_this) s = s.replace(rep_this, to_this) with open(a_OutFileName, 'w') as out_f: @@ -73,7 +71,6 @@ async def SaveAsPdf(a_Bot, a_InputFileName, a_OutFileName): return None async def MakeDocFile(a_Bot, a_FilePath, a_DictReplace, a_user_id): - print ('MakeDocFile', a_FilePath) user_file_path = a_FilePath[:-5] pdf_file_path = user_file_path user_file_path += f"_{a_user_id}.html"