Use camo to avoid mixed content warnings when displaying emoji.

This commit is contained in:
Tim Abbott 2016-04-27 21:43:40 -07:00
parent 52c1e8ac7d
commit 5bd94c15c7
8 changed files with 17 additions and 12 deletions

View File

@ -3,7 +3,8 @@ var path = require('path');
var fs = require('fs');
set_global('page_params', {realm_emoji: {
burrito: 'static/third/gemoji/images/emoji/burrito.png'
burrito: {display_url: 'static/third/gemoji/images/emoji/burrito.png',
source_url: 'static/third/gemoji/images/emoji/burrito.png'}
}});
add_dependencies({

View File

@ -733,7 +733,8 @@ function render(template_name, args) {
var args = {
emoji: {
"name": "MouseFace",
"url": "http://emojipedia-us.s3.amazonaws.com/cache/46/7f/467fe69069c408e07517621f263ea9b5.png"
"display_url": "http://emojipedia-us.s3.amazonaws.com/cache/46/7f/467fe69069c408e07517621f263ea9b5.png",
"source_url": "http://emojipedia-us.s3.amazonaws.com/cache/46/7f/467fe69069c408e07517621f263ea9b5.png"
}
};

View File

@ -77,8 +77,9 @@ function populate_streams (streams_data) {
exports.populate_emoji = function (emoji_data) {
var emoji_table = $('#admin_emoji_table').expectOne();
emoji_table.find('tr.emoji_row').remove();
_.each(emoji_data, function (url, name) {
emoji_table.append(templates.render('admin_emoji_list', {emoji: {name: name, url: url}}));
_.each(emoji_data, function (data, name) {
emoji_table.append(templates.render('admin_emoji_list', {emoji: {name: name, source_url: data.source_url,
display_url: data.display_url}}));
});
loading.destroy_indicator($('#admin_page_emoji_loading_indicator'));
};

View File

@ -17,8 +17,8 @@ _.each(emoji_names, function (value) {
exports.update_emojis = function update_emojis(realm_emojis) {
// Copy the default emoji list and add realm-specific emoji to it
exports.emojis = default_emojis.slice(0);
_.each(realm_emojis, function (url, name) {
exports.emojis.push({emoji_name:name, emoji_url: url});
_.each(realm_emojis, function (data, name) {
exports.emojis.push({emoji_name:name, emoji_url: data.display_url});
});
exports.emojis_by_name = {};
_.each(exports.emojis, function (emoji) {

View File

@ -4,7 +4,7 @@
<span class="emoji_name">{{name}}</span>
</td>
<td>
<span class="emoji_image"><img src="{{url}}" alt="{{name}}" /></span>
<span class="emoji_image"><a href="{{source_url}}"><img src="{{display_url}}" alt="{{name}}" /></a></span>
</td>
<td>
<button class="btn delete btn-danger" data-emoji-name="{{name}}">

View File

@ -553,12 +553,12 @@ class Emoji(markdown.inlinepatterns.Pattern):
orig_syntax = match.group("syntax")
name = orig_syntax[1:-1]
realm_emoji = {} # type: Dict[str, str]
realm_emoji = {} # type: Dict[str, Dict[str, str]]
if db_data is not None:
realm_emoji = db_data['emoji']
if current_message and name in realm_emoji:
return make_emoji(name, realm_emoji[name], orig_syntax)
return make_emoji(name, realm_emoji[name]['display_url'], orig_syntax)
elif name in emoji_list:
src = 'static/third/gemoji/images/emoji/%s.png' % (name)
return make_emoji(name, src, orig_syntax)

View File

@ -15,6 +15,7 @@ from zerver.lib.cache import cache_with_key, flush_user_profile, flush_realm, \
from zerver.lib.utils import make_safe_digest, generate_random_token
from django.db import transaction
from zerver.lib.avatar import gravatar_hash, get_avatar_url
from zerver.lib.camo import get_camo_url
from django.utils import timezone
from django.contrib.sessions.models import Session
from zerver.lib.timestamp import datetime_to_timestamp
@ -229,7 +230,8 @@ class RealmEmoji(models.Model):
def get_realm_emoji_uncached(realm):
d = {}
for row in RealmEmoji.objects.filter(realm=realm):
d[row.name] = row.img_url
d[row.name] = dict(source_url=row.img_url,
display_url=get_camo_url(row.img_url))
return d
def flush_realm_emoji(sender, **kwargs):

View File

@ -10,7 +10,7 @@ from zerver.lib.actions import (
do_remove_realm_emoji,
get_realm,
)
from zerver.lib.camo import get_camo_url
from zerver.models import (
get_user_profile_by_email,
Message,
@ -314,7 +314,7 @@ class BugdownTest(TestCase):
def test_realm_emoji(self):
def emoji_img(name, url):
return '<img alt="%s" class="emoji" src="%s" title="%s">' % (name, url, name)
return '<img alt="%s" class="emoji" src="%s" title="%s">' % (name, get_camo_url(url), name)
zulip_realm = get_realm('zulip.com')
url = "https://zulip.com/test_realm_emoji.png"