server/tags: fix changing name case
This commit is contained in:
parent
7e5deee76b
commit
07237bc2bc
|
@ -27,6 +27,9 @@ def _lower_list(names):
|
||||||
def _check_name_intersection(names1, names2):
|
def _check_name_intersection(names1, names2):
|
||||||
return len(set(_lower_list(names1)).intersection(_lower_list(names2))) > 0
|
return len(set(_lower_list(names1)).intersection(_lower_list(names2))) > 0
|
||||||
|
|
||||||
|
def _check_name_intersection_case_sensitive(names1, names2):
|
||||||
|
return len(set(names1).intersection(names2)) > 0
|
||||||
|
|
||||||
def sort_tags(tags):
|
def sort_tags(tags):
|
||||||
default_category = tag_categories.try_get_default_category()
|
default_category = tag_categories.try_get_default_category()
|
||||||
default_category_name = default_category.name if default_category else None
|
default_category_name = default_category.name if default_category else None
|
||||||
|
@ -222,14 +225,11 @@ def update_tag_names(tag, names):
|
||||||
if len(existing_tags):
|
if len(existing_tags):
|
||||||
raise TagAlreadyExistsError(
|
raise TagAlreadyExistsError(
|
||||||
'One of names is already used by another tag.')
|
'One of names is already used by another tag.')
|
||||||
tag_names_to_remove = []
|
for tag_name in tag.names[:]:
|
||||||
for tag_name in tag.names:
|
if not _check_name_intersection_case_sensitive([tag_name.name], names):
|
||||||
if not _check_name_intersection([tag_name.name], names):
|
|
||||||
tag_names_to_remove.append(tag_name)
|
|
||||||
for tag_name in tag_names_to_remove:
|
|
||||||
tag.names.remove(tag_name)
|
tag.names.remove(tag_name)
|
||||||
for name in names:
|
for name in names:
|
||||||
if not _check_name_intersection(_get_plain_names(tag), [name]):
|
if not _check_name_intersection_case_sensitive(_get_plain_names(tag), [name]):
|
||||||
tag.names.append(db.TagName(name))
|
tag.names.append(db.TagName(name))
|
||||||
|
|
||||||
def update_tag_implications(tag, relations):
|
def update_tag_implications(tag, relations):
|
||||||
|
|
|
@ -134,12 +134,12 @@ def test_reusing_own_name(test_ctx, dup_name):
|
||||||
input={'names': [dup_name, 'tag3'], 'version': 1},
|
input={'names': [dup_name, 'tag3'], 'version': 1},
|
||||||
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)),
|
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)),
|
||||||
'tag1')
|
'tag1')
|
||||||
assert result['names'] == ['tag1', 'tag3']
|
assert result['names'] == [dup_name, 'tag3']
|
||||||
assert tags.try_get_tag_by_name('tag2') is None
|
assert tags.try_get_tag_by_name('tag2') is None
|
||||||
tag1 = tags.get_tag_by_name('tag1')
|
tag1 = tags.get_tag_by_name('tag1')
|
||||||
tag2 = tags.get_tag_by_name('tag3')
|
tag2 = tags.get_tag_by_name('tag3')
|
||||||
assert tag1.tag_id == tag2.tag_id
|
assert tag1.tag_id == tag2.tag_id
|
||||||
assert [name.name for name in tag1.names] == ['tag1', 'tag3']
|
assert [name.name for name in tag1.names] == [dup_name, 'tag3']
|
||||||
|
|
||||||
def test_duplicating_names(test_ctx):
|
def test_duplicating_names(test_ctx):
|
||||||
db.session.add(
|
db.session.add(
|
||||||
|
|
Loading…
Reference in New Issue