mirror of https://github.com/zulip/zulip.git
models: Fix the URL validation code in `RealmFilter` model.
This commit is contained in:
parent
205d0993ef
commit
f2c04576bd
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.2 on 2017-07-22 13:44
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
import zerver.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('zerver', '0093_subscription_event_log_backfill'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='realmfilter',
|
||||
name='url_format_string',
|
||||
field=models.TextField(validators=[django.core.validators.URLValidator(), zerver.models.filter_format_validator]),
|
||||
),
|
||||
]
|
|
@ -468,7 +468,7 @@ def filter_format_validator(value):
|
|||
class RealmFilter(models.Model):
|
||||
realm = models.ForeignKey(Realm, on_delete=CASCADE) # type: Realm
|
||||
pattern = models.TextField(validators=[filter_pattern_validator]) # type: Text
|
||||
url_format_string = models.TextField(validators=[URLValidator, filter_format_validator]) # type: Text
|
||||
url_format_string = models.TextField(validators=[URLValidator(), filter_format_validator]) # type: Text
|
||||
|
||||
class Meta(object):
|
||||
unique_together = ("realm", "pattern")
|
||||
|
|
|
@ -43,6 +43,11 @@ class RealmFilterTest(ZulipTestCase):
|
|||
data['pattern'] = 'ZUL-(?P<id>\d+)'
|
||||
data['url_format_string'] = '$fgfg'
|
||||
result = self.client_post("/json/realm/filters", info=data)
|
||||
self.assert_json_error(result, 'Enter a valid URL.')
|
||||
|
||||
data['pattern'] = 'ZUL-(?P<id>\d+)'
|
||||
data['url_format_string'] = 'https://realm.com/my_realm_filter/'
|
||||
result = self.client_post("/json/realm/filters", info=data)
|
||||
self.assert_json_error(result, 'URL format string must be in the following format: `https://example.com/%(\\w+)s`')
|
||||
|
||||
data['url_format_string'] = 'https://realm.com/my_realm_filter/%(id)s'
|
||||
|
|
Loading…
Reference in New Issue