fix(tag): can not set synonym as tag itself

This commit is contained in:
LinkinStar 2022-12-08 10:43:45 +08:00
parent 0ae6ddaa67
commit b9ed2e5050
4 changed files with 8 additions and 0 deletions

View File

@ -109,6 +109,8 @@ backend:
other: "Should not contain synonym tags." other: "Should not contain synonym tags."
cannot_update: cannot_update:
other: "No permission to update." other: "No permission to update."
cannot_set_synonym_as_itself:
other: "You cannot set the synonym of the current tag as itself."
theme: theme:
not_found: not_found:
other: "Theme not found." other: "Theme not found."

View File

@ -97,6 +97,8 @@ backend:
other: "不应包含同义词标签。" other: "不应包含同义词标签。"
cannot_update: cannot_update:
other: "没有更新标签权限。" other: "没有更新标签权限。"
cannot_set_synonym_as_itself:
other: "你无法将当前标签的同义词设置为当前标签自己"
theme: theme:
not_found: not_found:
other: "主题未找到" other: "主题未找到"

View File

@ -58,4 +58,5 @@ const (
RevisionReviewUnderway = "error.revision.review_underway" RevisionReviewUnderway = "error.revision.review_underway"
RevisionNoPermission = "error.revision.no_permission" RevisionNoPermission = "error.revision.no_permission"
UserCannotUpdateYourRole = "error.user.cannot_update_your_role" UserCannotUpdateYourRole = "error.user.cannot_update_your_role"
TagCannotSetSynonymAsItself = "error.tag.cannot_set_synonym_as_itself"
) )

View File

@ -216,6 +216,9 @@ func (ts *TagService) UpdateTagSynonym(ctx context.Context, req *schema.UpdateTa
// find all exist tag // find all exist tag
for _, item := range req.SynonymTagList { for _, item := range req.SynonymTagList {
if item.SlugName == mainTagInfo.SlugName {
return errors.BadRequest(reason.TagCannotSetSynonymAsItself)
}
addSynonymTagList = append(addSynonymTagList, item.SlugName) addSynonymTagList = append(addSynonymTagList, item.SlugName)
} }
tagListInDB, err := ts.tagCommonService.GetTagListByNames(ctx, addSynonymTagList) tagListInDB, err := ts.tagCommonService.GetTagListByNames(ctx, addSynonymTagList)