Skip to content

Commit 13733a2

Browse files
committed
Merge branch 'feat/1.0.7/short-id' into test
2 parents e97410c + 6f91bc8 commit 13733a2

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

internal/controller/vote_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (vc *VoteController) VoteUp(ctx *gin.Context) {
4141
}
4242
req.ObjectID = uid.DeShortID(req.ObjectID)
4343
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
44-
can, err := vc.rankService.CheckVotePermission(ctx, req.UserID, req.ObjectID, true)
44+
can, _, err := vc.rankService.CheckVotePermission(ctx, req.UserID, req.ObjectID, true)
4545
if err != nil {
4646
handler.HandleResponse(ctx, err, nil)
4747
return
@@ -78,7 +78,7 @@ func (vc *VoteController) VoteDown(ctx *gin.Context) {
7878
}
7979
req.ObjectID = uid.DeShortID(req.ObjectID)
8080
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
81-
can, err := vc.rankService.CheckVotePermission(ctx, req.UserID, req.ObjectID, false)
81+
can, _, err := vc.rankService.CheckVotePermission(ctx, req.UserID, req.ObjectID, false)
8282
if err != nil {
8383
handler.HandleResponse(ctx, err, nil)
8484
return

internal/service/question_service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
235235

236236
tagNameList := make([]string, 0)
237237
for _, tag := range req.Tags {
238+
tag.SlugName = strings.ReplaceAll(tag.SlugName, " ", "-")
238239
tagNameList = append(tagNameList, tag.SlugName)
239240
}
240241
Tags, tagerr := qs.tagCommon.GetTagListByNames(ctx, tagNameList)
@@ -495,6 +496,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
495496
tagNameList := make([]string, 0)
496497
oldtagNameList := make([]string, 0)
497498
for _, tag := range req.Tags {
499+
tag.SlugName = strings.ReplaceAll(tag.SlugName, " ", "-")
498500
tagNameList = append(tagNameList, tag.SlugName)
499501
}
500502
for _, tag := range oldTags {

internal/service/rank/rank_service.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (rs *RankService) CheckOperationPermission(ctx context.Context, userID stri
9090
}
9191
}
9292

93-
can = rs.checkUserRank(ctx, userInfo.ID, userInfo.Rank, PermissionPrefix+action)
93+
can, _ = rs.checkUserRank(ctx, userInfo.ID, userInfo.Rank, PermissionPrefix+action)
9494
return can, nil
9595
}
9696

@@ -117,7 +117,7 @@ func (rs *RankService) CheckOperationPermissions(ctx context.Context, userID str
117117
can[idx] = true
118118
continue
119119
}
120-
meetRank := rs.checkUserRank(ctx, userInfo.ID, userInfo.Rank, PermissionPrefix+action)
120+
meetRank, _ := rs.checkUserRank(ctx, userInfo.ID, userInfo.Rank, PermissionPrefix+action)
121121
can[idx] = meetRank
122122
}
123123
return can, nil
@@ -141,22 +141,22 @@ func (rs *RankService) CheckOperationObjectOwner(ctx context.Context, userID, ob
141141

142142
// CheckVotePermission verify that the user has vote permission
143143
func (rs *RankService) CheckVotePermission(ctx context.Context, userID, objectID string, voteUp bool) (
144-
can bool, err error) {
144+
can bool, rank int, err error) {
145145
if len(userID) == 0 || len(objectID) == 0 {
146-
return false, nil
146+
return false, 0, nil
147147
}
148148

149149
// get the rank of the current user
150150
userInfo, exist, err := rs.userCommon.GetUserBasicInfoByID(ctx, userID)
151151
if err != nil {
152-
return can, err
152+
return can, 0, err
153153
}
154154
if !exist {
155-
return can, nil
155+
return can, 0, nil
156156
}
157157
objectInfo, err := rs.objectInfoService.GetInfo(ctx, objectID)
158158
if err != nil {
159-
return can, err
159+
return can, 0, err
160160
}
161161
action := ""
162162
switch objectInfo.ObjectType {
@@ -179,13 +179,13 @@ func (rs *RankService) CheckVotePermission(ctx context.Context, userID, objectID
179179
action = permission.CommentVoteDown
180180
}
181181
}
182+
meetRank, rank := rs.checkUserRank(ctx, userInfo.ID, userInfo.Rank, PermissionPrefix+action)
182183
powerMapping := rs.getUserPowerMapping(ctx, userID)
183184
if powerMapping[action] {
184-
return true, nil
185+
return true, rank, nil
185186
}
186187

187-
meetRank := rs.checkUserRank(ctx, userInfo.ID, userInfo.Rank, PermissionPrefix+action)
188-
return meetRank, nil
188+
return meetRank, rank, nil
189189
}
190190

191191
// getUserPowerMapping get user power mapping
@@ -210,19 +210,19 @@ func (rs *RankService) getUserPowerMapping(ctx context.Context, userID string) (
210210

211211
// CheckRankPermission verify that the user meets the prestige criteria
212212
func (rs *RankService) checkUserRank(ctx context.Context, userID string, userRank int, action string) (
213-
can bool) {
213+
can bool, rank int) {
214214
// get the amount of rank required for the current operation
215215
requireRank, err := rs.configRepo.GetInt(action)
216216
if err != nil {
217217
log.Error(err)
218-
return false
218+
return false, requireRank
219219
}
220220
if userRank < requireRank || requireRank < 0 {
221221
log.Debugf("user %s want to do action %s, but rank %d < %d",
222222
userID, action, userRank, requireRank)
223-
return false
223+
return false, requireRank
224224
}
225-
return true
225+
return true, requireRank
226226
}
227227

228228
// GetRankPersonalWithPage get personal comment list page

internal/service/tag_common/tag_common.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ func (ts *TagCommonService) ExistRecommend(ctx context.Context, tags []*schema.T
200200
}
201201
tagNames := make([]string, 0)
202202
for _, item := range tags {
203+
item.SlugName = strings.ReplaceAll(item.SlugName, " ", "-")
203204
tagNames = append(tagNames, item.SlugName)
204205
}
205206
list, err := ts.GetTagListByNames(ctx, tagNames)
@@ -233,7 +234,7 @@ func (ts *TagCommonService) AddTag(ctx context.Context, req *schema.AddTagReq) (
233234
return nil, errors.BadRequest(reason.TagAlreadyExist)
234235
}
235236
tagInfo := &entity.Tag{
236-
SlugName: req.SlugName,
237+
SlugName: strings.ReplaceAll(req.SlugName, " ", "-"),
237238
DisplayName: req.DisplayName,
238239
OriginalText: req.OriginalText,
239240
ParsedText: req.ParsedText,
@@ -557,7 +558,7 @@ func (ts *TagCommonService) ObjectChangeTag(ctx context.Context, objectTagData *
557558
continue
558559
}
559560
item := &entity.Tag{}
560-
item.SlugName = tag.SlugName
561+
item.SlugName = strings.ReplaceAll(tag.SlugName, " ", "-")
561562
item.DisplayName = tag.DisplayName
562563
item.OriginalText = tag.OriginalText
563564
item.ParsedText = tag.ParsedText

0 commit comments

Comments
 (0)