mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-12 04:12:16 +00:00
admin add group with period in name (#3712)
* admin add group with period in name * user add group with period in name
This commit is contained in:
parent
00ec69ea27
commit
ad18e874b1
@ -117,7 +117,7 @@ class AdminGroups(APIView):
|
|||||||
group_name = group_name.strip()
|
group_name = group_name.strip()
|
||||||
# Check whether group name is validate.
|
# Check whether group name is validate.
|
||||||
if not validate_group_name(group_name):
|
if not validate_group_name(group_name):
|
||||||
error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen, single quote or underscore')
|
error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen, period, single quote or underscore')
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
# Check whether group name is duplicated.
|
# Check whether group name is duplicated.
|
||||||
|
@ -202,7 +202,7 @@ class Groups(APIView):
|
|||||||
|
|
||||||
# Check whether group name is validate.
|
# Check whether group name is validate.
|
||||||
if not validate_group_name(group_name):
|
if not validate_group_name(group_name):
|
||||||
error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen, single quote or underscore')
|
error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen, period, single quote or underscore')
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
# Check whether group name is duplicated.
|
# Check whether group name is duplicated.
|
||||||
|
@ -30,7 +30,7 @@ def validate_group_name(group_name):
|
|||||||
"""
|
"""
|
||||||
if len(group_name) > 255:
|
if len(group_name) > 255:
|
||||||
return False
|
return False
|
||||||
return re.match('^[\w\s\'-]+$', group_name, re.U)
|
return re.match('^[\w\s\'-.]+$', group_name, re.U)
|
||||||
|
|
||||||
def check_group_name_conflict(request, new_group_name):
|
def check_group_name_conflict(request, new_group_name):
|
||||||
"""Check if new group name conflict with existed group.
|
"""Check if new group name conflict with existed group.
|
||||||
|
@ -62,8 +62,8 @@ class GroupsTest(BaseTestCase):
|
|||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
|
|
||||||
url = reverse('api-v2.1-admin-groups')
|
url = reverse('api-v2.1-admin-groups')
|
||||||
limit_punctuation = """-'_"""
|
limit_punctuation = """-'_."""
|
||||||
group_name = randstring(5) + random.choice(limit_punctuation)
|
group_name = randstring(2) + random.choice(limit_punctuation) + randstring(2)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'group_name': group_name,
|
'group_name': group_name,
|
||||||
@ -83,8 +83,8 @@ class GroupsTest(BaseTestCase):
|
|||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
|
|
||||||
url = reverse('api-v2.1-admin-groups')
|
url = reverse('api-v2.1-admin-groups')
|
||||||
other_punctuation = """!"#$%&()*+,./:;<=>?@[\]^`{|}~"""
|
other_punctuation = """!"#$%&()*+,/:;<=>?@[\]^`{|}~"""
|
||||||
group_name = randstring(5) + random.choice(other_punctuation)
|
group_name = randstring(2) + random.choice(other_punctuation) + randstring(2)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'group_name': group_name,
|
'group_name': group_name,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import json
|
import json
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
import random
|
||||||
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from seaserv import seafile_api
|
from seaserv import seafile_api
|
||||||
@ -90,6 +91,26 @@ class GroupsTest(BaseTestCase):
|
|||||||
resp = self.client.post(self.url, {'group_name': self.group_name})
|
resp = self.client.post(self.url, {'group_name': self.group_name})
|
||||||
self.assertEqual(400, resp.status_code)
|
self.assertEqual(400, resp.status_code)
|
||||||
|
|
||||||
|
def test_can_create_by_limit_punctuation(self):
|
||||||
|
limit_punctuation = """-'_."""
|
||||||
|
new_group_name = randstring(2) + random.choice(limit_punctuation) + randstring(2)
|
||||||
|
|
||||||
|
resp = self.client.post(self.url, {'name': new_group_name})
|
||||||
|
self.assertEqual(201, resp.status_code)
|
||||||
|
|
||||||
|
json_resp = json.loads(resp.content)
|
||||||
|
assert json_resp['name'] == new_group_name
|
||||||
|
assert json_resp['owner'] == self.user.email
|
||||||
|
|
||||||
|
self.remove_group(json_resp['id'])
|
||||||
|
|
||||||
|
def test_can_not_create_by_other_punctuation(self):
|
||||||
|
other_punctuation = """!"#$%&()*+,/:;<=>?@[\]^`{|}~"""
|
||||||
|
new_group_name = randstring(2) + random.choice(other_punctuation) + randstring(2)
|
||||||
|
|
||||||
|
resp = self.client.post(self.url, {'name': new_group_name})
|
||||||
|
self.assertEqual(400, resp.status_code)
|
||||||
|
|
||||||
def test_can_not_create_group_with_invalid_name(self):
|
def test_can_not_create_group_with_invalid_name(self):
|
||||||
new_group_name = 'new%group-' + randstring(6)
|
new_group_name = 'new%group-' + randstring(6)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user