chore: update get workspace profile

This commit is contained in:
Steven
2023-09-24 09:42:05 +08:00
parent 0907ad2681
commit a1d1e0f0f2
4 changed files with 32 additions and 6 deletions

View File

@ -15,21 +15,24 @@ import (
"github.com/boojack/slash/api/auth"
apiv2pb "github.com/boojack/slash/proto/gen/api/v2"
storepb "github.com/boojack/slash/proto/gen/store"
"github.com/boojack/slash/server/service/license"
"github.com/boojack/slash/store"
)
type UserService struct {
apiv2pb.UnimplementedUserServiceServer
Secret string
Store *store.Store
Secret string
Store *store.Store
LicenseService *license.LicenseService
}
// NewUserService creates a new UserService.
func NewUserService(secret string, store *store.Store) *UserService {
func NewUserService(secret string, store *store.Store, licenseService *license.LicenseService) *UserService {
return &UserService{
Secret: secret,
Store: store,
Secret: secret,
Store: store,
LicenseService: licenseService,
}
}
@ -73,6 +76,16 @@ func (s *UserService) CreateUser(ctx context.Context, request *apiv2pb.CreateUse
return nil, status.Errorf(codes.Internal, "failed to hash password: %v", err)
}
if !s.LicenseService.IsFeatureEnabled(license.FeatureTypeUnlimitedAccounts) {
userList, err := s.Store.ListUsers(ctx, &store.FindUser{})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list users: %v", err)
}
if len(userList) >= 3 {
return nil, status.Errorf(codes.ResourceExhausted, "maximum number of users reached")
}
}
user, err := s.Store.CreateUser(ctx, &store.User{
Email: request.User.Email,
Nickname: request.User.Nickname,