diff --git a/CHANGELOG.md b/CHANGELOG.md index f5712de..57d2fe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.15.7 (Aug 02, 2021) + +### Removed + +* Remove external cts user message. This dependency is no longer required + as user access to the bot is now controlled in the cts admin panel. + + ## 0.15.6 (Jul 30, 2021) ### Fixed diff --git a/{{cookiecutter.bot_name}}/app/bot/bot.py b/{{cookiecutter.bot_name}}/app/bot/bot.py index 48c2e9b..2aa3653 100644 --- a/{{cookiecutter.bot_name}}/app/bot/bot.py +++ b/{{cookiecutter.bot_name}}/app/bot/bot.py @@ -1,12 +1,11 @@ """Configuration for bot instance.""" -from botx import Bot, Depends +from botx import Bot from botx_fsm import FSMMiddleware # type: ignore from botx_fsm.storages.redis import RedisStorage # type: ignore from loguru import logger from app.bot.commands import common from app.bot.dependencies.errors import internal_error_handler -from app.bot.dependencies.external_cts import message_from_current_cts from app.resources import strings from app.settings.config import get_app_settings @@ -14,10 +13,7 @@ redis_storage = RedisStorage(redis_dsn=str(config.REDIS_DSN), prefix=strings.BOT_NAME) logger.debug(redis_storage.redis_dsn) -bot = Bot( - bot_accounts=config.BOT_CREDENTIALS, - dependencies=[Depends(message_from_current_cts)], -) +bot = Bot(bot_accounts=config.BOT_CREDENTIALS) bot.add_middleware( FSMMiddleware, diff --git a/{{cookiecutter.bot_name}}/app/bot/dependencies/external_cts.py b/{{cookiecutter.bot_name}}/app/bot/dependencies/external_cts.py deleted file mode 100644 index 4b67703..0000000 --- a/{{cookiecutter.bot_name}}/app/bot/dependencies/external_cts.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Dependencies for check that message was send from bot's cts.""" -from botx import DependencyFailure, Message, SendingMessage - -from app.resources import strings - - -async def message_from_current_cts(message: Message) -> None: - """Check that user write from bot's cts.""" - if message.is_system_event: - return - - if not (message.user.ad_domain and message.ad_login): - answer = SendingMessage.from_message(message=message) - for bot_credentials in message.bot.bot_accounts: - if bot_credentials.host == message.user.host: - answer.text = strings.OTHER_CTS_WITH_BOT_MENTION_WARNING - answer.mention_contact(bot_credentials.bot_id) - break - - else: - answer.text = strings.OTHER_CTS_WARNING - - await message.bot.send(answer) - raise DependencyFailure diff --git a/{{cookiecutter.bot_name}}/tests/test_bot/test_dependencies/test_external_cts.py b/{{cookiecutter.bot_name}}/tests/test_bot/test_dependencies/test_external_cts.py deleted file mode 100644 index 0211228..0000000 --- a/{{cookiecutter.bot_name}}/tests/test_bot/test_dependencies/test_external_cts.py +++ /dev/null @@ -1,33 +0,0 @@ -import pytest -from botx import CommandTypes, MessageBuilder, TestClient - - -@pytest.mark.asyncio -async def test_message_from_external_cts( - builder: MessageBuilder, - botx_client: TestClient, -): - builder.user.ad_domain = None - builder.user.ad_login = None - builder.body = "/help" - builder.message.command.command_type = CommandTypes.user - await botx_client.send_command(builder.message) - body = botx_client.notifications[0].result.body - - assert body == "\n".join( - [ - "Данный бот зарегистрирован на другом CTS.", - "Перейдите по `меншну`, чтобы попасть к вашему боту", - ] - ) - - builder.user.host = "cts.testing2.dev" - await botx_client.send_command(builder.message) - body = botx_client.notifications[1].result.body - - assert body == "\n".join( - [ - "Данный бот зарегистрирован на другом CTS.", - "Обратитесь к администратору, чтобы он зарегистрировал бота на вашем CTS", - ] - )