mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-05 00:43:53 +00:00
create group can use single quote (#3265)
* admin create group can use single quote * user create group can use single quote, update error_msg
This commit is contained in:
@@ -117,7 +117,7 @@ class AdminGroups(APIView):
|
||||
group_name = group_name.strip()
|
||||
# Check whether group name is validate.
|
||||
if not validate_group_name(group_name):
|
||||
error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen or underscore')
|
||||
error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen, single quote or underscore')
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
# Check whether group name is duplicated.
|
||||
|
@@ -202,7 +202,7 @@ class Groups(APIView):
|
||||
|
||||
# Check whether group name is validate.
|
||||
if not validate_group_name(group_name):
|
||||
error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen or underscore')
|
||||
error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen, single quote or underscore')
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
# Check whether group name is duplicated.
|
||||
|
@@ -30,7 +30,7 @@ def validate_group_name(group_name):
|
||||
"""
|
||||
if len(group_name) > 255:
|
||||
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):
|
||||
"""Check if new group name conflict with existed group.
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import random
|
||||
from django.core.urlresolvers import reverse
|
||||
from seahub.test_utils import BaseTestCase
|
||||
from tests.common.utils import randstring
|
||||
@@ -57,6 +58,42 @@ class GroupsTest(BaseTestCase):
|
||||
|
||||
self.remove_group(json_resp['id'])
|
||||
|
||||
def test_can_create_by_limit_punctuation(self):
|
||||
self.login_as(self.admin)
|
||||
|
||||
url = reverse('api-v2.1-admin-groups')
|
||||
limit_punctuation = """-'_"""
|
||||
group_name = randstring(5) + random.choice(limit_punctuation)
|
||||
|
||||
data = {
|
||||
'group_name': group_name,
|
||||
'group_owner': self.user.email
|
||||
}
|
||||
|
||||
resp = self.client.post(url, data)
|
||||
self.assertEqual(201, resp.status_code)
|
||||
|
||||
json_resp = json.loads(resp.content)
|
||||
assert json_resp['name'] == group_name
|
||||
assert json_resp['owner'] == self.user.email
|
||||
|
||||
self.remove_group(json_resp['id'])
|
||||
|
||||
def test_can_not_create_by_other_punctuation(self):
|
||||
self.login_as(self.admin)
|
||||
|
||||
url = reverse('api-v2.1-admin-groups')
|
||||
other_punctuation = """!"#$%&()*+,./:;<=>?@[\]^`{|}~"""
|
||||
group_name = randstring(5) + random.choice(other_punctuation)
|
||||
|
||||
data = {
|
||||
'group_name': group_name,
|
||||
'group_owner': self.user.email
|
||||
}
|
||||
|
||||
resp = self.client.post(url, data)
|
||||
self.assertEqual(400, resp.status_code)
|
||||
|
||||
def test_create_without_group_owner(self):
|
||||
self.login_as(self.admin)
|
||||
|
||||
|
@@ -59,8 +59,8 @@ class GroupsApiTest(ApiTestBase):
|
||||
# check group is really removed
|
||||
groups = self.get(GROUPS_URL).json()['groups']
|
||||
for group in groups:
|
||||
|
||||
self.assertNotEqual(group['id'], group_id)
|
||||
|
||||
def test_add_remove_group_with_hyphen(self):
|
||||
data = {'group_name': randstring(4) + '-' + randstring(4)}
|
||||
info = self.put(GROUPS_URL, data=data).json()
|
||||
@@ -75,8 +75,22 @@ class GroupsApiTest(ApiTestBase):
|
||||
for group in groups:
|
||||
self.assertNotEqual(group['id'], group_id)
|
||||
|
||||
def test_add_remove_group_with_blank_and_hyphen(self):
|
||||
data = {'group_name': randstring(4) + '-' + randstring(4) + ' ' + randstring(4)}
|
||||
def test_add_remove_group_with_single_quote(self):
|
||||
data = {'group_name': randstring(4) + "'" + randstring(4)}
|
||||
info = self.put(GROUPS_URL, data=data).json()
|
||||
self.assertTrue(info['success'])
|
||||
group_id = info['group_id']
|
||||
self.assertGreater(group_id, 0)
|
||||
url = urljoin(GROUPS_URL, str(group_id))
|
||||
self.delete(url)
|
||||
|
||||
# check group is really removed
|
||||
groups = self.get(GROUPS_URL).json()['groups']
|
||||
for group in groups:
|
||||
self.assertNotEqual(group['id'], group_id)
|
||||
|
||||
def test_add_remove_group_with_blank_and_hyphen_and_single_quote(self):
|
||||
data = {'group_name': randstring(2) + '-' + randstring(2) + ' ' + randstring(2) + "'" + randstring(2)}
|
||||
info = self.put(GROUPS_URL, data=data).json()
|
||||
self.assertTrue(info['success'])
|
||||
group_id = info['group_id']
|
||||
|
Reference in New Issue
Block a user