mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 12:03:46 +00:00 
			
		
		
		
	bug fix: Fix error when admin renames a bot after reactivating it.
Fix administration page javascript issue of TypeError that occurs due to undefined variable access in static/js/bot_data.js file. Reactivating a bot was not updating the state in `bot_data`. Sending an event on reactivating a bot fixes this issue. Fixes: #2840
This commit is contained in:
		
				
					committed by
					
						 Tim Abbott
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							15d60fa7ed
						
					
				
				
					commit
					f0121973d2
				
			| @@ -372,7 +372,6 @@ def notify_created_bot(user_profile): | |||||||
|     default_sending_stream_name = stream_name(user_profile.default_sending_stream) |     default_sending_stream_name = stream_name(user_profile.default_sending_stream) | ||||||
|     default_events_register_stream_name = stream_name(user_profile.default_events_register_stream) |     default_events_register_stream_name = stream_name(user_profile.default_events_register_stream) | ||||||
|  |  | ||||||
|     event = dict(type="realm_bot", op="add", |  | ||||||
|     bot = dict(email=user_profile.email, |     bot = dict(email=user_profile.email, | ||||||
|                user_id=user_profile.id, |                user_id=user_profile.id, | ||||||
|                full_name=user_profile.full_name, |                full_name=user_profile.full_name, | ||||||
| @@ -382,8 +381,15 @@ def notify_created_bot(user_profile): | |||||||
|                default_events_register_stream=default_events_register_stream_name, |                default_events_register_stream=default_events_register_stream_name, | ||||||
|                default_all_public_streams=user_profile.default_all_public_streams, |                default_all_public_streams=user_profile.default_all_public_streams, | ||||||
|                avatar_url=avatar_url(user_profile), |                avatar_url=avatar_url(user_profile), | ||||||
|                           owner=user_profile.bot_owner.email, |                ) | ||||||
|                           )) |  | ||||||
|  |     # Set the owner key only when the bot has an owner. | ||||||
|  |     # The default bots don't have an owner. So don't | ||||||
|  |     # set the owner key while reactivating them. | ||||||
|  |     if user_profile.bot_owner is not None: | ||||||
|  |         bot['owner'] = user_profile.bot_owner.email | ||||||
|  |  | ||||||
|  |     event = dict(type="realm_bot", op="add", bot=bot) | ||||||
|     send_event(event, bot_owner_userids(user_profile)) |     send_event(event, bot_owner_userids(user_profile)) | ||||||
|  |  | ||||||
| def do_create_user(email, password, realm, full_name, short_name, | def do_create_user(email, password, realm, full_name, short_name, | ||||||
| @@ -1862,6 +1868,9 @@ def do_reactivate_user(user_profile): | |||||||
|  |  | ||||||
|     notify_created_user(user_profile) |     notify_created_user(user_profile) | ||||||
|  |  | ||||||
|  |     if user_profile.is_bot: | ||||||
|  |         notify_created_bot(user_profile) | ||||||
|  |  | ||||||
| def do_change_password(user_profile, password, log=True, commit=True, | def do_change_password(user_profile, password, log=True, commit=True, | ||||||
|                        hashed_password=False): |                        hashed_password=False): | ||||||
|     # type: (UserProfile, Text, bool, bool, bool) -> None |     # type: (UserProfile, Text, bool, bool, bool) -> None | ||||||
|   | |||||||
| @@ -31,6 +31,7 @@ from zerver.lib.actions import ( | |||||||
|     do_create_user, |     do_create_user, | ||||||
|     do_deactivate_stream, |     do_deactivate_stream, | ||||||
|     do_deactivate_user, |     do_deactivate_user, | ||||||
|  |     do_reactivate_user, | ||||||
|     do_regenerate_api_key, |     do_regenerate_api_key, | ||||||
|     do_remove_alert_words, |     do_remove_alert_words, | ||||||
|     do_remove_realm_emoji, |     do_remove_realm_emoji, | ||||||
| @@ -1038,6 +1039,31 @@ class EventsRegisterTest(ZulipTestCase): | |||||||
|         error = bot_deactivate_checker('events[1]', events[1]) |         error = bot_deactivate_checker('events[1]', events[1]) | ||||||
|         self.assert_on_error(error) |         self.assert_on_error(error) | ||||||
|  |  | ||||||
|  |     def test_do_reactivate_user(self): | ||||||
|  |         # type: () -> None | ||||||
|  |         bot_reactivate_checker = check_dict([ | ||||||
|  |             ('type', equals('realm_bot')), | ||||||
|  |             ('op', equals('add')), | ||||||
|  |             ('bot', check_dict([ | ||||||
|  |                 ('email', check_string), | ||||||
|  |                 ('user_id', check_int), | ||||||
|  |                 ('full_name', check_string), | ||||||
|  |                 ('is_active', check_bool), | ||||||
|  |                 ('api_key', check_string), | ||||||
|  |                 ('default_sending_stream', check_none_or(check_string)), | ||||||
|  |                 ('default_events_register_stream', check_none_or(check_string)), | ||||||
|  |                 ('default_all_public_streams', check_bool), | ||||||
|  |                 ('avatar_url', check_string), | ||||||
|  |                 ('owner', check_none_or(check_string)), | ||||||
|  |             ])), | ||||||
|  |         ]) | ||||||
|  |         bot = self.create_bot('foo-bot@zulip.com') | ||||||
|  |         do_deactivate_user(bot) | ||||||
|  |         action = lambda: do_reactivate_user(bot) | ||||||
|  |         events = self.do_test(action) | ||||||
|  |         error = bot_reactivate_checker('events[1]', events[1]) | ||||||
|  |         self.assert_on_error(error) | ||||||
|  |  | ||||||
|     def test_rename_stream(self): |     def test_rename_stream(self): | ||||||
|         # type: () -> None |         # type: () -> None | ||||||
|         stream = self.make_stream('old_name') |         stream = self.make_stream('old_name') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user