mirror of https://github.com/zulip/zulip.git
realm_emoji: Make sure that a deactivated realm emoji can't be used.
A deactivated realm emoji should neither be accepted further as a reaction nor its further occurences in a message be rendered as an emoji. However, all the old occurences should continue to render normally.
This commit is contained in:
parent
8db2cf8d7c
commit
7950f82f27
|
@ -128,7 +128,8 @@ function handleUnicodeEmoji(unicode_emoji) {
|
|||
function handleEmoji(emoji_name) {
|
||||
var input_emoji = ':' + emoji_name + ":";
|
||||
var emoji_url;
|
||||
if (emoji.realm_emojis.hasOwnProperty(emoji_name)) {
|
||||
if (emoji.realm_emojis.hasOwnProperty(emoji_name) &&
|
||||
emoji.realm_emojis[emoji_name].deactivated !== true) {
|
||||
emoji_url = emoji.realm_emojis[emoji_name].emoji_url;
|
||||
return '<img alt="' + input_emoji + '"' +
|
||||
' class="emoji" src="' + emoji_url + '"' +
|
||||
|
|
|
@ -750,7 +750,7 @@ class Emoji(markdown.inlinepatterns.Pattern):
|
|||
if db_data is not None:
|
||||
realm_emoji = db_data['emoji']
|
||||
|
||||
if current_message and name in realm_emoji:
|
||||
if current_message and name in realm_emoji and not realm_emoji[name]['deactivated']:
|
||||
return make_realm_emoji(realm_emoji[name]['source_url'], orig_syntax)
|
||||
elif name == 'zulip':
|
||||
return make_realm_emoji('/static/generated/emoji/images/emoji/unicode/zulip.png', orig_syntax)
|
||||
|
|
|
@ -12,7 +12,8 @@ from zerver.models import Realm, RealmEmoji, UserProfile
|
|||
|
||||
def check_valid_emoji(realm, emoji_name):
|
||||
# type: (Realm, Text) -> None
|
||||
if emoji_name in set(realm.get_emoji().keys()):
|
||||
realm_emojis = realm.get_emoji()
|
||||
if emoji_name in realm_emojis and not realm_emojis[emoji_name]['deactivated']:
|
||||
return
|
||||
if emoji_name in name_to_codepoint:
|
||||
return
|
||||
|
|
|
@ -33,6 +33,7 @@ from zerver.models import (
|
|||
Message,
|
||||
Stream,
|
||||
Realm,
|
||||
RealmEmoji,
|
||||
RealmFilter,
|
||||
Recipient,
|
||||
)
|
||||
|
@ -505,6 +506,18 @@ class BugdownTest(ZulipTestCase):
|
|||
converted = bugdown.convert(":test:", message_realm=realm, message=msg)
|
||||
self.assertEqual(converted, '<p>:test:</p>')
|
||||
|
||||
def test_deactivated_realm_emoji(self):
|
||||
# type: () -> None
|
||||
realm = get_realm('zulip')
|
||||
check_add_realm_emoji(realm, "test", 'test.png')
|
||||
emoji = RealmEmoji.objects.get(realm=realm, name='test')
|
||||
emoji.deactivated = True
|
||||
emoji.save(update_fields=['deactivated'])
|
||||
|
||||
msg = Message(sender=self.example_user('hamlet'))
|
||||
converted = bugdown.convert(":test:", message_realm=realm, message=msg)
|
||||
self.assertEqual(converted, '<p>:test:</p>')
|
||||
|
||||
def test_unicode_emoji(self):
|
||||
# type: () -> None
|
||||
msg = u'\u2615' # ☕
|
||||
|
|
|
@ -8,7 +8,7 @@ from six import string_types
|
|||
from zerver.lib.test_helpers import tornado_redirected_to_list, get_display_recipient, \
|
||||
get_test_image_file
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.models import get_realm, Recipient, UserMessage
|
||||
from zerver.models import get_realm, RealmEmoji, Recipient, UserMessage
|
||||
|
||||
class ReactionEmojiTest(ZulipTestCase):
|
||||
def test_missing_emoji(self):
|
||||
|
@ -41,6 +41,25 @@ class ReactionEmojiTest(ZulipTestCase):
|
|||
**self.api_auth(sender))
|
||||
self.assert_json_error(result, "Emoji 'foo' does not exist")
|
||||
|
||||
def test_add_deactivated_realm_emoji(self):
|
||||
# type: () -> None
|
||||
"""
|
||||
Sending deactivated realm emoji fails.
|
||||
"""
|
||||
email = "iago@zulip.com"
|
||||
self.login(email)
|
||||
with get_test_image_file('img.png') as fp1:
|
||||
emoji_data = {'f1': fp1}
|
||||
result = self.client_put_multipart('/json/realm/emoji/my_emoji', info=emoji_data)
|
||||
self.assert_json_success(result)
|
||||
emoji = RealmEmoji.objects.get(name="my_emoji")
|
||||
emoji.deactivated = True
|
||||
emoji.save(update_fields=['deactivated'])
|
||||
sender = 'hamlet@zulip.com'
|
||||
result = self.client_put('/api/v1/messages/1/emoji_reactions/my_emoji',
|
||||
**self.api_auth(sender))
|
||||
self.assert_json_error(result, "Emoji 'my_emoji' does not exist")
|
||||
|
||||
def test_valid_emoji(self):
|
||||
# type: () -> None
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue