mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-04 07:43:28 +08:00
Merge pull request #229 from LydiaCai1203/feat-invite-users-limit-v2
feat: 免费版本用户限制 100
This commit is contained in:
@@ -33,6 +33,7 @@ type UserUsecase interface {
|
||||
OAuthCallback(ctx *web.Context, req *OAuthCallbackReq) error
|
||||
ExportCompletionData(ctx context.Context) (*ExportCompletionDataResp, error)
|
||||
GetUserByApiKey(ctx context.Context, apiKey string) (*db.User, error)
|
||||
GetUserCount(ctx context.Context) (int64, error)
|
||||
}
|
||||
|
||||
type UserRepo interface {
|
||||
@@ -60,6 +61,7 @@ type UserRepo interface {
|
||||
SaveAdminLoginHistory(ctx context.Context, adminID, ip string) error
|
||||
SaveUserLoginHistory(ctx context.Context, userID, ip string, session *VSCodeSession) error
|
||||
ExportCompletionData(ctx context.Context) ([]*CompletionData, error)
|
||||
GetUserCount(ctx context.Context) (int64, error)
|
||||
}
|
||||
|
||||
type ProfileUpdateReq struct {
|
||||
|
||||
@@ -431,6 +431,23 @@ func (h *UserHandler) LoginHistory(c *web.Context) error {
|
||||
// @Router /api/v1/user/invite [get]
|
||||
func (h *UserHandler) Invite(c *web.Context) error {
|
||||
user := middleware.GetAdmin(c)
|
||||
|
||||
edition := c.Get("edition")
|
||||
if edition == nil {
|
||||
return errcode.ErrPermission
|
||||
}
|
||||
|
||||
// 如果是 Free 版本 user 表不允许超过 100 人
|
||||
if edition.(int) == 0 {
|
||||
count, err := h.usecase.GetUserCount(c.Request().Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count >= 100 {
|
||||
return errcode.ErrUserLimit
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := h.usecase.Invite(c.Request().Context(), user.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -603,3 +603,11 @@ func (r *UserRepo) ExportCompletionData(ctx context.Context) ([]*domain.Completi
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *UserRepo) GetUserCount(ctx context.Context) (int64, error) {
|
||||
count, err := r.db.User.Query().Count(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int64(count), nil
|
||||
}
|
||||
|
||||
@@ -686,3 +686,7 @@ func (u *UserUsecase) ExportCompletionData(ctx context.Context) (*domain.ExportC
|
||||
Data: data,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *UserUsecase) GetUserCount(ctx context.Context) (int64, error) {
|
||||
return u.repo.GetUserCount(ctx)
|
||||
}
|
||||
|
||||
Submodule backend/pro updated: 5c132972b3...cb3420b603
Reference in New Issue
Block a user