MCPcopy
hub / github.com/apache/answer / UpdateComment

Method UpdateComment

internal/controller/comment_controller.go:190–230  ·  view source on GitHub ↗

UpdateComment update comment @Summary update comment @Description update comment @Tags Comment @Accept json @Produce json @Security ApiKeyAuth @Param data body schema.UpdateCommentReq true "comment" @Success 200 {object} handler.RespBody @Router /answer/api/v1/comment [put]

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

188// @Success 200 {object} handler.RespBody
189// @Router /answer/api/v1/comment [put]
190func (cc *CommentController) UpdateComment(ctx *gin.Context) {
191 req := &schema.UpdateCommentReq{}
192 if handler.BindAndCheck(ctx, req) {
193 return
194 }
195
196 req.UserID = middleware.GetLoginUserIDFromContext(ctx)
197 req.IsAdmin = middleware.GetIsAdminFromContext(ctx)
198 canList, err := cc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
199 permission.CommentEdit,
200 permission.LinkUrlLimit,
201 })
202 if err != nil {
203 handler.HandleResponse(ctx, err, nil)
204 return
205 }
206 req.CanEdit = canList[0] || cc.rankService.CheckOperationObjectOwner(ctx, req.UserID, req.CommentID)
207 linkUrlLimitUser := canList[1]
208 if !req.CanEdit {
209 handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
210 return
211 }
212
213 if !req.IsAdmin || !linkUrlLimitUser {
214 captchaPass := cc.actionService.ActionRecordVerifyCaptcha(ctx, entity.CaptchaActionEdit, req.UserID, req.CaptchaID, req.CaptchaCode)
215 if !captchaPass {
216 errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{
217 ErrorField: "captcha_code",
218 ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.CaptchaVerificationFailed),
219 })
220 handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields)
221 return
222 }
223 }
224
225 resp, err := cc.commentService.UpdateComment(ctx, req)
226 if !req.IsAdmin || !linkUrlLimitUser {
227 cc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionEdit, req.UserID)
228 }
229 handler.HandleResponse(ctx, err, resp)
230}
231
232// GetCommentWithPage get comment page
233// @Summary get comment page

Callers

nothing calls this directly

Calls 10

BindAndCheckFunction · 0.92
GetIsAdminFromContextFunction · 0.92
HandleResponseFunction · 0.92
TrFunction · 0.92
GetLangByCtxFunction · 0.92
ActionRecordAddMethod · 0.80

Tested by

no test coverage detected