Merge pull request 'feat-IRONFANS-70' (#320) from feat-IRONFANS-70 into test

Reviewed-on: http://121.41.31.146:3000/wishpal_ironfan/service/pulls/320
This commit is contained in:
chenhao 2024-04-22 19:37:08 +08:00
commit bfc84392aa
4 changed files with 37 additions and 9 deletions

View File

@ -197,7 +197,7 @@ var ErrCodeMsgMap = map[ErrCode]string{
ErrCodeZoneCollaboratorSrvFail: "空间协作者表服务错误", ErrCodeZoneCollaboratorSrvFail: "空间协作者表服务错误",
ErrCodeZoneCollaboratorNotExist: "空间协作者表不存在", ErrCodeZoneCollaboratorNotExist: "空间协作者表不存在",
ErrCodeZoneCollaboratorCreateIsZTPOnlyOperation: "空间协作者表创建操作只有空间代运营可操作", ErrCodeZoneCollaboratorCreateIsZTPOnlyOperation: "空间协作者表创建操作只有空间代运营可操作",
ErrCodeZoneCollaboratorWrongCollaborator: "空间协作者不能设置成自己或者主播", ErrCodeZoneCollaboratorWrongCollaborator: "空间协作者不能设置成自己或者空间所有人",
ErrCodeZoneCollaboratorDuplicateKey: "用户已是该空间协作者!", ErrCodeZoneCollaboratorDuplicateKey: "用户已是该空间协作者!",
ErrCodeZoneMomentCreateTimesSrvFail: "空间动态创建频次表服务错误", ErrCodeZoneMomentCreateTimesSrvFail: "空间动态创建频次表服务错误",
@ -477,7 +477,7 @@ const (
ErrCodeZoneCollaboratorSrvFail ErrCode = -38001 // 空间协作者表服务错误 ErrCodeZoneCollaboratorSrvFail ErrCode = -38001 // 空间协作者表服务错误
ErrCodeZoneCollaboratorNotExist ErrCode = -38002 // 空间协作者表不存在 ErrCodeZoneCollaboratorNotExist ErrCode = -38002 // 空间协作者表不存在
ErrCodeZoneCollaboratorCreateIsZTPOnlyOperation ErrCode = -38003 // 空间协作者表创建操作只有空间代运营可操作 ErrCodeZoneCollaboratorCreateIsZTPOnlyOperation ErrCode = -38003 // 空间协作者表创建操作只有空间代运营可操作
ErrCodeZoneCollaboratorWrongCollaborator ErrCode = -38004 // 空间协作者不能设置成自己或者主播 ErrCodeZoneCollaboratorWrongCollaborator ErrCode = -38004 // 空间协作者不能设置成自己或者空间所有者
ErrCodeZoneCollaboratorDuplicateKey ErrCode = -38005 // 空间协作者重复创建 ErrCodeZoneCollaboratorDuplicateKey ErrCode = -38005 // 空间协作者重复创建
// MomentCreateTimes: 39xxx // MomentCreateTimes: 39xxx

View File

@ -550,11 +550,13 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon
ec = errcode.ErrCodeMomentSrvOk ec = errcode.ErrCodeMomentSrvOk
pType := int64(0) pType := int64(0)
mediaVisibleRange := int64(0)
switch req.ZoneMoment.GetCType() { switch req.ZoneMoment.GetCType() {
case consts.ZoneMomentCType_Free: case consts.ZoneMomentCType_Free:
pType = consts.AccountPunishment_BlockFromCreatingFreeZoneMoment pType = consts.AccountPunishment_BlockFromCreatingFreeZoneMoment
case consts.ZoneMomentCType_Paid: case consts.ZoneMomentCType_Paid:
pType = consts.AccountPunishment_BlockFromCreatingPaidZoneMoment pType = consts.AccountPunishment_BlockFromCreatingPaidZoneMoment
mediaVisibleRange = req.ZoneMoment.GetMediaVisibleRange()
} }
resultList := businessvalidator.NewAuthBusinessValidator(ctx, req). resultList := businessvalidator.NewAuthBusinessValidator(ctx, req).
@ -565,7 +567,7 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon
EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, pType, _DefaultAccountPunishment.OpListByMidAndType). EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, pType, _DefaultAccountPunishment.OpListByMidAndType).
EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(_DefaultZoneMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid). EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(_DefaultZoneMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid).
EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(_DefaultZoneMoment.OpCountByMidAndCType, req.GetBaseRequest().Mid, req.ZoneMoment.GetCType()). EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(_DefaultZoneMoment.OpCountByMidAndCType, req.GetBaseRequest().Mid, req.ZoneMoment.GetCType()).
EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, req.ZoneMoment.GetMediaVisibleRange()). EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, mediaVisibleRange).
Validate(). Validate().
Collect() Collect()
ec, _ = resultList[0].(errcode.ErrCode) ec, _ = resultList[0].(errcode.ErrCode)
@ -626,16 +628,15 @@ func (s *Service) ApiCreateZoneCollaboratorBusinessValidate(ctx *gin.Context, re
EnsureZoneThirdPartnerExist(). EnsureZoneThirdPartnerExist().
EnsureZoneCollaboratorCreaterIsZoneThirdPartner(req.GetBaseRequest().Mid). EnsureZoneCollaboratorCreaterIsZoneThirdPartner(req.GetBaseRequest().Mid).
EnsureIsNotOperatingHisOwn(util.DerefInt64(req.CollaboratorMid)). EnsureIsNotOperatingHisOwn(util.DerefInt64(req.CollaboratorMid)).
QueryAccountForUid(_DefaultAccount.OpListByMid, util.DerefInt64(req.CollaboratorMid)). EnsureZoneCollaboratorIsNotZoneOwner(_DefaultZone.GetByMid, util.DerefInt64(req.CollaboratorMid)).
EnsureIsNotThisRole(consts.Streamer).
Validate(). Validate().
Collect() Collect()
ec = result[0].(errcode.ErrCode) ec = result[0].(errcode.ErrCode)
if ec == errcode.ErrCodeOperationToSelfIsNotPermitted || ec == errcode.ErrCodeRolePrivilegesNotEnough { if ec == errcode.ErrCodeOperationToSelfIsNotPermitted {
ec = errcode.ErrCodeZoneCollaboratorWrongCollaborator ec = errcode.ErrCodeZoneCollaboratorWrongCollaborator
} }
if ec != errcode.ErrCodeOk { if ec != errcode.ErrCodeOk {
logger.Error("ApiGetAccountRelationCount business validation failed") logger.Error("ApiCreateZoneCollaborator business validation failed")
return return
} }

View File

@ -55,8 +55,8 @@ func (a *AuthBusinessValidator) EnsureIsOperatingHisOwn(reqMid int64) *AuthBusin
// 确认不对本人操作 // 确认不对本人操作
func (a *AuthBusinessValidator) EnsureIsNotOperatingHisOwn(Uid int64) *AuthBusinessValidator { func (a *AuthBusinessValidator) EnsureIsNotOperatingHisOwn(Uid int64) *AuthBusinessValidator {
a.oplist = append(a.oplist, func() { a.oplist = append(a.oplist, func() {
if a.OperMid != Uid { if a.OperMid == Uid {
logger.Error("Insufficient privileges: this operation is self-execute-only") logger.Error("Insufficient privileges: this operation is not permitted to operate on requestor himself")
a.ec = errcode.ErrCodeOperationToSelfIsNotPermitted a.ec = errcode.ErrCodeOperationToSelfIsNotPermitted
return return
} }
@ -537,6 +537,26 @@ func (l *AuthBusinessValidator) EnsureZoneCollaboratorCreaterIsZoneThirdPartner(
return l return l
} }
func (l *AuthBusinessValidator) EnsureZoneCollaboratorIsNotZoneOwner(fun func(ctx *gin.Context, mid int64) (*dbstruct.Zone, error), collaboratorMid int64) *AuthBusinessValidator {
l.oplist = append(l.oplist, func() {
zone, err := fun(l.ctx, collaboratorMid)
if err != nil {
l.ec = errcode.ErrCodeZoneSrvFail
return
}
if zone == nil {
return
}
if zone.GetId() == l.zoneThirdPartner.GetZid() {
l.ec = errcode.ErrCodeZoneCollaboratorWrongCollaborator
return
}
})
return l
}
// 执行校验 // 执行校验
func (a *AuthBusinessValidator) Validate() *AuthBusinessValidator { func (a *AuthBusinessValidator) Validate() *AuthBusinessValidator {
a.BusinessValidateStream.Validate() a.BusinessValidateStream.Validate()

View File

@ -31,3 +31,10 @@ func (p *ZoneThirdPartner) GetSharingRatio() float64 {
} }
return 0 return 0
} }
func (p *ZoneThirdPartner) GetZid() int64 {
if p != nil && p.Zid != nil {
return *p.Zid
}
return 0
}