Esempio n. 1
0
    def handle(self, *args, **options):
        # type: (*Any, **str) -> None
        realm = get_realm(options["string_id"])
        if options["op"] == "show":
            for name, url in six.iteritems(realm.get_emoji()):
                print(name, url)
            sys.exit(0)

        name = options['name']
        if name is None:
            self.print_help("./manage.py", "realm_emoji")
            sys.exit(1)

        if options["op"] == "add":
            img_url = options['img_url']
            if img_url is None:
                self.print_help("./manage.py", "realm_emoji")
                sys.exit(1)
            check_add_realm_emoji(realm, name, img_url)
            sys.exit(0)
        elif options["op"] == "remove":
            do_remove_realm_emoji(realm, name)
            sys.exit(0)
        else:
            self.print_help("./manage.py", "realm_emoji")
            sys.exit(1)
Esempio n. 2
0
    def handle(self, *args, **options):
        realm = Realm.objects.get(domain=options["domain"])
        if options["op"] == "show":
            for name, url in realm.get_emoji().iteritems():
                print name, url
            sys.exit(0)

        name = options['name']
        if name is None:
            self.print_help("python manage.py", "realm_emoji")
            sys.exit(1)

        if options["op"] == "add":
            img_url = options['img_url']
            if img_url is None:
                self.print_help("python manage.py", "realm_emoji")
                sys.exit(1)
            do_add_realm_emoji(realm, name, img_url)
            sys.exit(0)
        elif options["op"] == "remove":
            do_remove_realm_emoji(realm, name)
            sys.exit(0)
        else:
            self.print_help("python manage.py", "realm_emoji")
            sys.exit(1)
Esempio n. 3
0
    def handle(self, *args: Any, **options: str) -> None:
        realm = self.get_realm(options)
        assert realm is not None  # Should be ensured by parser
        if options["op"] == "show":
            for name, url in realm.get_emoji().items():
                print(name, url)
            sys.exit(0)

        name = options['name']
        if name is None:
            self.print_help("./manage.py", "realm_emoji")
            sys.exit(1)

        if options["op"] == "add":
            img_url = options['img_url']
            if img_url is None:
                self.print_help("./manage.py", "realm_emoji")
                sys.exit(1)
            check_add_realm_emoji(realm, name, img_url)
            sys.exit(0)
        elif options["op"] == "remove":
            do_remove_realm_emoji(realm, name)
            sys.exit(0)
        else:
            self.print_help("./manage.py", "realm_emoji")
            sys.exit(1)
Esempio n. 4
0
    def handle(self, *args, **options):
        realm = get_realm(options["domain"])
        if options["op"] == "show":
            for name, url in six.iteritems(realm.get_emoji()):
                print(name, url)
            sys.exit(0)

        name = options['name']
        if name is None:
            self.print_help("python2.7 manage.py", "realm_emoji")
            sys.exit(1)

        if options["op"] == "add":
            img_url = options['img_url']
            if img_url is None:
                self.print_help("python2.7 manage.py", "realm_emoji")
                sys.exit(1)
            check_add_realm_emoji(realm, name, img_url)
            sys.exit(0)
        elif options["op"] == "remove":
            do_remove_realm_emoji(realm, name)
            sys.exit(0)
        else:
            self.print_help("python2.7 manage.py", "realm_emoji")
            sys.exit(1)
Esempio n. 5
0
    def handle(self, *args, **options):
        realm = get_realm(options["domain"])
        if options["op"] == "show":
            for name, url in realm.get_emoji().iteritems():
                print(name, url)
            sys.exit(0)

        name = options['name']
        if name is None:
            self.print_help("python2.7 manage.py", "realm_emoji")
            sys.exit(1)

        if options["op"] == "add":
            img_url = options['img_url']
            if img_url is None:
                self.print_help("python2.7 manage.py", "realm_emoji")
                sys.exit(1)
            do_add_realm_emoji(realm, name, img_url)
            sys.exit(0)
        elif options["op"] == "remove":
            do_remove_realm_emoji(realm, name)
            sys.exit(0)
        else:
            self.print_help("python2.7 manage.py", "realm_emoji")
            sys.exit(1)
Esempio n. 6
0
    def handle(self, *args, **options):
        # type: (*Any, **str) -> None
        realm = get_realm_by_string_id(options["string_id"])
        if options["op"] == "show":
            for name, url in six.iteritems(realm.get_emoji()):
                print(name, url)
            sys.exit(0)

        name = options['name']
        if name is None:
            self.print_help("./manage.py", "realm_emoji")
            sys.exit(1)

        if options["op"] == "add":
            img_url = options['img_url']
            if img_url is None:
                self.print_help("./manage.py", "realm_emoji")
                sys.exit(1)
            check_add_realm_emoji(realm, name, img_url)
            sys.exit(0)
        elif options["op"] == "remove":
            do_remove_realm_emoji(realm, name)
            sys.exit(0)
        else:
            self.print_help("./manage.py", "realm_emoji")
            sys.exit(1)
Esempio n. 7
0
    def handle(self, *args: Any, **options: str) -> None:
        realm = self.get_realm(options)
        assert realm is not None  # Should be ensured by parser
        if options["op"] == "show":
            for name, url in realm.get_emoji().items():
                print(name, url)
            sys.exit(0)

        name = options['name']
        if name is None:
            self.print_help("./manage.py", "realm_emoji")
            sys.exit(1)

        if options["op"] == "add":
            img_url = options['img_url']
            if img_url is None:
                self.print_help("./manage.py", "realm_emoji")
                sys.exit(1)
            check_add_realm_emoji(realm, name, img_url)
            sys.exit(0)
        elif options["op"] == "remove":
            do_remove_realm_emoji(realm, name)
            sys.exit(0)
        else:
            self.print_help("./manage.py", "realm_emoji")
            sys.exit(1)
Esempio n. 8
0
def delete_emoji(request: HttpRequest, user_profile: UserProfile, emoji_name: str) -> HttpResponse:
    if not RealmEmoji.objects.filter(
        realm=user_profile.realm, name=emoji_name, deactivated=False
    ).exists():
        raise JsonableError(_("Emoji '{}' does not exist").format(emoji_name))
    check_emoji_admin(user_profile, emoji_name)
    do_remove_realm_emoji(user_profile.realm, emoji_name)
    return json_success()
Esempio n. 9
0
def delete_emoji(request: HttpRequest, user_profile: UserProfile,
                 emoji_name: str) -> HttpResponse:
    if not RealmEmoji.objects.filter(realm=user_profile.realm,
                                     name=emoji_name,
                                     deactivated=False).exists():
        raise JsonableError(_("Emoji '%s' does not exist" % (emoji_name,)))
    check_emoji_admin(user_profile, emoji_name)
    do_remove_realm_emoji(user_profile.realm, emoji_name)
    return json_success()
Esempio n. 10
0
    def test_realm_emoji(self):
        def emoji_img(name, url):
            return '<img alt="%s" class="emoji" src="%s" title="%s">' % (name, url, name)

        zulip_realm = get_realm('zulip.com')
        url = "https://zulip.com/test_realm_emoji.png"
        do_add_realm_emoji(zulip_realm, "test", url)

        # Needs to mock an actual message because that's how bugdown obtains the realm
        msg = Message(sender=get_user_profile_by_email("*****@*****.**"))
        converted = bugdown.convert(":test:", "zulip.com", msg)
        self.assertEqual(converted, '<p>%s</p>' %(emoji_img(':test:', url)))

        do_remove_realm_emoji(zulip_realm, 'test')
        converted = bugdown.convert(":test:", "zulip.com", msg)
        self.assertEqual(converted, '<p>:test:</p>')
Esempio n. 11
0
    def test_realm_emoji(self):
        def emoji_img(name, url):
            return '<img alt="%s" class="emoji" src="%s" title="%s">' % (
                name, url, name)

        zulip_realm = get_realm('zulip.com')
        url = "https://zulip.com/test_realm_emoji.png"
        do_add_realm_emoji(zulip_realm, "test", url)

        # Needs to mock an actual message because that's how bugdown obtains the realm
        msg = Message(sender=get_user_profile_by_email("*****@*****.**"))
        converted = bugdown.convert(":test:", "zulip.com", msg)
        self.assertEqual(converted, '<p>%s</p>' % (emoji_img(':test:', url)))

        do_remove_realm_emoji(zulip_realm, 'test')
        converted = bugdown.convert(":test:", "zulip.com", msg)
        self.assertEqual(converted, '<p>:test:</p>')
Esempio n. 12
0
    def test_realm_emoji_events(self):
        schema_checker = check_dict([
            ('type', equals('realm_emoji')),
            ('op', equals('update')),
            ('realm_emoji', check_dict([])),
        ])
        events = self.do_test(lambda: do_add_realm_emoji(get_realm("zulip.com"), "my_emoji",
                                                         "https://realm.com/my_emoji"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        events = self.do_test(lambda: do_remove_realm_emoji(get_realm("zulip.com"), "my_emoji"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)
Esempio n. 13
0
    def test_realm_emoji_events(self):
        schema_checker = check_dict([
            ('type', equals('realm_emoji')),
            ('op', equals('update')),
            ('realm_emoji', check_dict([])),
        ])
        events = self.do_test(lambda: do_add_realm_emoji(get_realm("zulip.com"), "my_emoji",
                                                         "https://realm.com/my_emoji"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        events = self.do_test(lambda: do_remove_realm_emoji(get_realm("zulip.com"), "my_emoji"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)
Esempio n. 14
0
def delete_emoji(request, user_profile, emoji_name):
    # type: (HttpRequest, UserProfile, Text) -> HttpResponse
    check_emoji_admin(user_profile)
    check_valid_emoji(user_profile.realm, emoji_name)
    do_remove_realm_emoji(user_profile.realm, emoji_name)
    return json_success()
Esempio n. 15
0
def delete_emoji(request, user_profile, emoji_name):
    # type: (HttpRequest, UserProfile, Text) -> HttpResponse
    check_emoji_admin(user_profile)
    check_valid_emoji(user_profile.realm, emoji_name)
    do_remove_realm_emoji(user_profile.realm, emoji_name)
    return json_success()
Esempio n. 16
0
def delete_emoji(request, user_profile, emoji_name):
    do_remove_realm_emoji(user_profile.realm, emoji_name)
    return json_success({})
Esempio n. 17
0
def delete_emoji(request, user_profile, emoji_name):
    # type: (HttpRequest, UserProfile, text_type) -> HttpResponse
    do_remove_realm_emoji(user_profile.realm, emoji_name)
    return json_success({})
Esempio n. 18
0
def delete_emoji(request, user_profile, emoji_name):
    # type: (HttpRequest, UserProfile, text_type) -> HttpResponse
    do_remove_realm_emoji(user_profile.realm, emoji_name)
    return json_success({})
Esempio n. 19
0
def delete_emoji(request, user_profile, emoji_name):
    do_remove_realm_emoji(user_profile.realm, emoji_name)
    return json_success({})