2016-12-25 00:44:26 +01:00
|
|
|
from __future__ import absolute_import
|
2017-01-17 08:38:25 +01:00
|
|
|
|
2016-06-02 23:01:28 +02:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2016-02-12 21:08:56 +01:00
|
|
|
from django.core.exceptions import ValidationError
|
2016-12-20 15:41:30 +01:00
|
|
|
from django.utils.translation import ugettext as _
|
2016-12-25 00:44:26 +01:00
|
|
|
from typing import Text
|
2016-02-12 21:08:56 +01:00
|
|
|
|
2016-06-02 23:01:28 +02:00
|
|
|
from zerver.models import UserProfile
|
2017-01-17 08:42:52 +01:00
|
|
|
from zerver.lib.emoji import check_emoji_admin, check_valid_emoji_name
|
2017-01-17 08:38:25 +01:00
|
|
|
from zerver.lib.request import JsonableError, REQ, has_request_variables
|
2016-02-12 21:08:56 +01:00
|
|
|
from zerver.lib.response import json_success, json_error
|
|
|
|
from zerver.lib.actions import check_add_realm_emoji, do_remove_realm_emoji
|
|
|
|
|
|
|
|
def list_emoji(request, user_profile):
|
2016-06-02 23:01:28 +02:00
|
|
|
# type: (HttpRequest, UserProfile) -> HttpResponse
|
2016-12-20 15:41:30 +01:00
|
|
|
|
|
|
|
# We don't call check_emoji_admin here because the list of realm
|
|
|
|
# emoji is public.
|
2016-02-12 21:08:56 +01:00
|
|
|
return json_success({'emoji': user_profile.realm.get_emoji()})
|
|
|
|
|
2017-01-17 08:38:25 +01:00
|
|
|
@has_request_variables
|
|
|
|
def upload_emoji(request, user_profile, emoji_name=None, url=REQ()):
|
|
|
|
# type: (HttpRequest, UserProfile, Text, Text) -> HttpResponse
|
|
|
|
check_valid_emoji_name(emoji_name)
|
2016-12-20 15:41:30 +01:00
|
|
|
check_emoji_admin(user_profile)
|
2016-02-12 21:08:56 +01:00
|
|
|
try:
|
2017-01-17 08:38:25 +01:00
|
|
|
check_add_realm_emoji(user_profile.realm, emoji_name, url, author=user_profile)
|
2016-02-12 21:08:56 +01:00
|
|
|
except ValidationError as e:
|
2016-06-04 08:02:40 +02:00
|
|
|
return json_error(e.messages[0])
|
2016-02-12 21:08:56 +01:00
|
|
|
return json_success()
|
|
|
|
|
|
|
|
def delete_emoji(request, user_profile, emoji_name):
|
2016-12-25 00:44:26 +01:00
|
|
|
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
|
2016-12-20 15:41:30 +01:00
|
|
|
check_emoji_admin(user_profile)
|
2016-02-12 21:08:56 +01:00
|
|
|
do_remove_realm_emoji(user_profile.realm, emoji_name)
|
2016-10-21 07:34:04 +02:00
|
|
|
return json_success()
|