mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-20 14:01:24 +00:00
chore: update get workspace profile
This commit is contained in:
parent
0907ad2681
commit
a1d1e0f0f2
@ -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,
|
||||
|
@ -36,7 +36,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store
|
||||
)
|
||||
apiv2pb.RegisterSubscriptionServiceServer(grpcServer, NewSubscriptionService(profile, store, licenseService))
|
||||
apiv2pb.RegisterWorkspaceServiceServer(grpcServer, NewWorkspaceService(profile, store, licenseService))
|
||||
apiv2pb.RegisterUserServiceServer(grpcServer, NewUserService(secret, store))
|
||||
apiv2pb.RegisterUserServiceServer(grpcServer, NewUserService(secret, store, licenseService))
|
||||
apiv2pb.RegisterUserSettingServiceServer(grpcServer, NewUserSettingService(store))
|
||||
apiv2pb.RegisterShortcutServiceServer(grpcServer, NewShortcutService(secret, store))
|
||||
reflection.Register(grpcServer)
|
||||
|
@ -33,7 +33,16 @@ func NewWorkspaceService(profile *profile.Profile, store *store.Store, licenseSe
|
||||
func (s *WorkspaceService) GetWorkspaceProfile(ctx context.Context, _ *apiv2pb.GetWorkspaceProfileRequest) (*apiv2pb.GetWorkspaceProfileResponse, error) {
|
||||
profile := &apiv2pb.WorkspaceProfile{
|
||||
Mode: s.Profile.Mode,
|
||||
Plan: apiv2pb.PlanType_PRO,
|
||||
}
|
||||
|
||||
// Load subscription plan from license service.
|
||||
subscription, err := s.LicenseService.GetSubscription(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get subscription: %v", err)
|
||||
}
|
||||
profile.Plan = subscription.Plan
|
||||
|
||||
workspaceSetting, err := s.GetWorkspaceSetting(ctx, &apiv2pb.GetWorkspaceSettingRequest{})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get workspace setting: %v", err)
|
||||
|
@ -96,6 +96,10 @@ func (s *LicenseService) UpdateSubscription(ctx context.Context, licenseKey stri
|
||||
return s.LoadSubscription(ctx)
|
||||
}
|
||||
|
||||
func (s *LicenseService) GetSubscription(ctx context.Context) (*apiv2pb.Subscription, error) {
|
||||
return s.LoadSubscription(ctx)
|
||||
}
|
||||
|
||||
func (s *LicenseService) IsFeatureEnabled(feature FeatureType) bool {
|
||||
matrix, ok := FeatureMatrix[feature]
|
||||
if !ok {
|
||||
|
Loading…
x
Reference in New Issue
Block a user