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-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:48:07 +01:00
|
|
|
from zerver.lib.emoji import check_emoji_admin, check_valid_emoji_name, check_valid_emoji
|
2017-01-17 08:38:25 +01:00
|
|
|
from zerver.lib.request import JsonableError, REQ, has_request_variables
|
2017-01-30 21:40:35 +01:00
|
|
|
from zerver.lib.response import json_success
|
2016-02-12 21:08:56 +01:00
|
|
|
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
|
2017-02-11 05:26:24 +01:00
|
|
|
def upload_emoji(request, user_profile, emoji_name, url=REQ()):
|
2017-01-17 08:38:25 +01:00
|
|
|
# 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)
|
2017-01-30 21:40:35 +01:00
|
|
|
check_add_realm_emoji(user_profile.realm, emoji_name, url, author=user_profile)
|
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)
|
2017-01-17 08:48:07 +01:00
|
|
|
check_valid_emoji(user_profile.realm, emoji_name)
|
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()
|