mirror of https://github.com/zulip/zulip.git
emoji: Add author field to RealmEmoji table and track.
This commit is contained in:
parent
dee5a0c8d7
commit
ffa724f8fc
|
@ -3556,9 +3556,9 @@ def notify_realm_emoji(realm):
|
||||||
user_ids = [userdict['id'] for userdict in get_active_user_dicts_in_realm(realm)]
|
user_ids = [userdict['id'] for userdict in get_active_user_dicts_in_realm(realm)]
|
||||||
send_event(event, user_ids)
|
send_event(event, user_ids)
|
||||||
|
|
||||||
def check_add_realm_emoji(realm, name, img_url):
|
def check_add_realm_emoji(realm, name, img_url, author=None):
|
||||||
# type: (Realm, Text, Text) -> None
|
# type: (Realm, Text, Text, Optional[UserProfile]) -> None
|
||||||
emoji = RealmEmoji(realm=realm, name=name, img_url=img_url)
|
emoji = RealmEmoji(realm=realm, name=name, img_url=img_url, author=author)
|
||||||
emoji.full_clean()
|
emoji.full_clean()
|
||||||
emoji.save()
|
emoji.save()
|
||||||
notify_realm_emoji(realm)
|
notify_realm_emoji(realm)
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.4 on 2016-12-20 07:02
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('zerver', '0045_realm_waiting_period_threshold'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='realmemoji',
|
||||||
|
name='author',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
]
|
|
@ -354,6 +354,7 @@ def list_of_domains_for_realm(realm):
|
||||||
return list(RealmAlias.objects.filter(realm = realm).values_list('domain', flat=True))
|
return list(RealmAlias.objects.filter(realm = realm).values_list('domain', flat=True))
|
||||||
|
|
||||||
class RealmEmoji(ModelReprMixin, models.Model):
|
class RealmEmoji(ModelReprMixin, models.Model):
|
||||||
|
author = models.ForeignKey('UserProfile', blank=True, null=True)
|
||||||
realm = models.ForeignKey(Realm) # type: Realm
|
realm = models.ForeignKey(Realm) # type: Realm
|
||||||
# Second part of the regex (negative lookbehind) disallows names ending with one of the punctuation characters
|
# Second part of the regex (negative lookbehind) disallows names ending with one of the punctuation characters
|
||||||
name = models.TextField(validators=[MinLengthValidator(1),
|
name = models.TextField(validators=[MinLengthValidator(1),
|
||||||
|
|
|
@ -21,11 +21,14 @@ class RealmEmojiTest(ZulipTestCase):
|
||||||
|
|
||||||
def test_upload(self):
|
def test_upload(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.login("iago@zulip.com")
|
email = "iago@zulip.com"
|
||||||
|
self.login(email)
|
||||||
data = {"name": "my_emoji", "url": "https://example.com/my_emoji"}
|
data = {"name": "my_emoji", "url": "https://example.com/my_emoji"}
|
||||||
result = self.client_put("/json/realm/emoji", info=data)
|
result = self.client_put("/json/realm/emoji", info=data)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
self.assertEqual(200, result.status_code)
|
self.assertEqual(200, result.status_code)
|
||||||
|
emoji = RealmEmoji.objects.get(name=data['name'])
|
||||||
|
self.assertEqual(emoji.author.email, email)
|
||||||
|
|
||||||
result = self.client_get("/json/realm/emoji")
|
result = self.client_get("/json/realm/emoji")
|
||||||
content = ujson.loads(result.content)
|
content = ujson.loads(result.content)
|
||||||
|
|
|
@ -18,7 +18,7 @@ def upload_emoji(request, user_profile):
|
||||||
emoji_name = request.POST.get('name', None)
|
emoji_name = request.POST.get('name', None)
|
||||||
emoji_url = request.POST.get('url', None)
|
emoji_url = request.POST.get('url', None)
|
||||||
try:
|
try:
|
||||||
check_add_realm_emoji(user_profile.realm, emoji_name, emoji_url)
|
check_add_realm_emoji(user_profile.realm, emoji_name, emoji_url, author=user_profile)
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
return json_error(e.messages[0])
|
return json_error(e.messages[0])
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
Loading…
Reference in New Issue