限制非管理员用户ppt制作数量
This commit is contained in:
parent
fe14227d9f
commit
8a316003be
15
dao/im.go
15
dao/im.go
|
|
@ -164,3 +164,18 @@ func FindBaseSessionMessageStatisticsInfo() (int64, int64, int64, error) {
|
||||||
}
|
}
|
||||||
return sessionCount, messageCount, todayMessageCount, nil
|
return sessionCount, messageCount, todayMessageCount, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindUserSessionCount(userID, sessionType int) int64 {
|
||||||
|
var sessionCount int64
|
||||||
|
var db2 *gorm.DB
|
||||||
|
if proto.Config.SERVER_SQL_LOG {
|
||||||
|
db2 = DB.Debug()
|
||||||
|
} else {
|
||||||
|
db2 = DB
|
||||||
|
}
|
||||||
|
if err := db2.Model(&Session{}).Where("user_id = ? and type = ?", userID, sessionType).Count(&sessionCount).Error; err != nil {
|
||||||
|
log.Println("find user session count error:", err)
|
||||||
|
}
|
||||||
|
log.Println("user session count:", sessionCount)
|
||||||
|
return sessionCount
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -490,6 +490,12 @@ func CreateSparkPPTSOutline(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "file name is empty", "code": proto.ParameterError, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "file name is empty", "code": proto.ParameterError, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
err3 := service.CheckUserCreatePPTSessionPermission(userID)
|
||||||
|
if err3 != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": "user create ppt session permission error", "code": proto.ParameterError, "message": err3.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var base proto.SparkCreatePPTBaseInfo
|
var base proto.SparkCreatePPTBaseInfo
|
||||||
base.UserID = userID
|
base.UserID = userID
|
||||||
log.Println("create outline user id:", userID)
|
log.Println("create outline user id:", userID)
|
||||||
|
|
|
||||||
|
|
@ -257,3 +257,16 @@ func ReceiveSparkSession(userID, sessionID int, channel string, msg proto.WSMess
|
||||||
Spark(modelParam, msg.Msg, channel, sessionID, userID, int(model.ID))
|
Spark(modelParam, msg.Msg, channel, sessionID, userID, int(model.ID))
|
||||||
return resErr, resID
|
return resErr, resID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckUserCreatePPTSessionPermission(userID int) error {
|
||||||
|
sessionCount := dao.FindUserSessionCount(userID, proto.SessionTypeUserCreatePPT)
|
||||||
|
var err error
|
||||||
|
user := GetUserByIDWithCache(userID)
|
||||||
|
if user.Role == "admin" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if sessionCount > 3 {
|
||||||
|
err = errors.New("create ppt session count exceed limit")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue