mirror of https://github.com/zulip/zulip.git
bot_config: Have check_valid_bot_config also take the bot_type.
This is a prep commit to allow us to validate user provided bot config data using the same function for incoming webhook type bots alongside embedded bots (as opposed to creating a new function just for incoming webhook bots).
This commit is contained in:
parent
f5c57361d6
commit
94c351ead4
|
@ -47,19 +47,21 @@ def check_short_name(short_name_raw: str) -> str:
|
||||||
raise JsonableError(_("Bad name or username"))
|
raise JsonableError(_("Bad name or username"))
|
||||||
return short_name
|
return short_name
|
||||||
|
|
||||||
def check_valid_bot_config(service_name: str, config_data: Dict[str, str]) -> None:
|
def check_valid_bot_config(bot_type: int, service_name: str,
|
||||||
try:
|
config_data: Dict[str, str]) -> None:
|
||||||
from zerver.lib.bot_lib import get_bot_handler
|
if bot_type == UserProfile.EMBEDDED_BOT:
|
||||||
bot_handler = get_bot_handler(service_name)
|
try:
|
||||||
if hasattr(bot_handler, 'validate_config'):
|
from zerver.lib.bot_lib import get_bot_handler
|
||||||
bot_handler.validate_config(config_data)
|
bot_handler = get_bot_handler(service_name)
|
||||||
except ConfigValidationError:
|
if hasattr(bot_handler, 'validate_config'):
|
||||||
# The exception provides a specific error message, but that
|
bot_handler.validate_config(config_data)
|
||||||
# message is not tagged translatable, because it is
|
except ConfigValidationError:
|
||||||
# triggered in the external zulip_bots package.
|
# The exception provides a specific error message, but that
|
||||||
# TODO: Think of some clever way to provide a more specific
|
# message is not tagged translatable, because it is
|
||||||
# error message.
|
# triggered in the external zulip_bots package.
|
||||||
raise JsonableError(_("Invalid configuration data!"))
|
# TODO: Think of some clever way to provide a more specific
|
||||||
|
# error message.
|
||||||
|
raise JsonableError(_("Invalid configuration data!"))
|
||||||
|
|
||||||
# Adds an outgoing webhook or embedded bot service.
|
# Adds an outgoing webhook or embedded bot service.
|
||||||
def add_service(name: str, user_profile: UserProfile, base_url: Optional[str]=None,
|
def add_service(name: str, user_profile: UserProfile, base_url: Optional[str]=None,
|
||||||
|
|
|
@ -321,7 +321,7 @@ def add_bot_backend(
|
||||||
user_profile, default_events_register_stream_name)
|
user_profile, default_events_register_stream_name)
|
||||||
|
|
||||||
if bot_type == UserProfile.EMBEDDED_BOT:
|
if bot_type == UserProfile.EMBEDDED_BOT:
|
||||||
check_valid_bot_config(service_name, config_data)
|
check_valid_bot_config(bot_type, service_name, config_data)
|
||||||
|
|
||||||
bot_profile = do_create_user(email=email, password='',
|
bot_profile = do_create_user(email=email, password='',
|
||||||
realm=user_profile.realm, full_name=full_name,
|
realm=user_profile.realm, full_name=full_name,
|
||||||
|
|
Loading…
Reference in New Issue