mirror of
https://github.com/zulip/zulip.git
synced 2025-10-25 09:03:57 +00:00
backend: Add bot config data to initial state data.
This commit is contained in:
@@ -1929,11 +1929,23 @@ def get_bot_services(user_profile_id: str) -> List[Service]:
|
||||
return list(Service.objects.filter(user_profile__id=user_profile_id))
|
||||
|
||||
def get_service_dicts_for_bots(user_profile_id: str) -> List[Dict[str, Any]]:
|
||||
user_profile = get_user_profile_by_id(user_profile_id)
|
||||
services = get_bot_services(user_profile_id)
|
||||
service_dicts = [{'base_url': service.base_url,
|
||||
'interface': service.interface,
|
||||
}
|
||||
for service in services]
|
||||
service_dicts = [] # type: List[Dict[Text, Any]]
|
||||
if user_profile.bot_type == UserProfile.OUTGOING_WEBHOOK_BOT:
|
||||
service_dicts = [{'base_url': service.base_url,
|
||||
'interface': service.interface,
|
||||
}
|
||||
for service in services]
|
||||
elif user_profile.bot_type == UserProfile.EMBEDDED_BOT:
|
||||
from zerver.lib.bot_config import get_bot_config, ConfigError
|
||||
try:
|
||||
service_dicts = [{'config_data': get_bot_config(user_profile),
|
||||
'service_name': services[0].name
|
||||
}]
|
||||
# A ConfigError just means that there are no config entries for user_profile.
|
||||
except ConfigError:
|
||||
pass
|
||||
return service_dicts
|
||||
|
||||
def get_service_profile(user_profile_id: str, service_name: str) -> Service:
|
||||
|
||||
@@ -186,8 +186,8 @@ class HomeTest(ZulipTestCase):
|
||||
with patch('zerver.lib.cache.cache_set') as cache_mock:
|
||||
result = self._get_home_page(stream='Denmark')
|
||||
|
||||
self.assert_length(queries, 41)
|
||||
self.assert_length(cache_mock.call_args_list, 7)
|
||||
self.assert_length(queries, 42)
|
||||
self.assert_length(cache_mock.call_args_list, 8)
|
||||
|
||||
html = result.content.decode('utf-8')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user