mirror of
				https://github.com/aykhans/slash-e.git
				synced 2025-10-31 08:59:59 +00:00 
			
		
		
		
	chore: update get workspace profile
This commit is contained in:
		| @@ -15,21 +15,24 @@ import ( | |||||||
| 	"github.com/boojack/slash/api/auth" | 	"github.com/boojack/slash/api/auth" | ||||||
| 	apiv2pb "github.com/boojack/slash/proto/gen/api/v2" | 	apiv2pb "github.com/boojack/slash/proto/gen/api/v2" | ||||||
| 	storepb "github.com/boojack/slash/proto/gen/store" | 	storepb "github.com/boojack/slash/proto/gen/store" | ||||||
|  | 	"github.com/boojack/slash/server/service/license" | ||||||
| 	"github.com/boojack/slash/store" | 	"github.com/boojack/slash/store" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type UserService struct { | type UserService struct { | ||||||
| 	apiv2pb.UnimplementedUserServiceServer | 	apiv2pb.UnimplementedUserServiceServer | ||||||
|  |  | ||||||
| 	Secret string | 	Secret         string | ||||||
| 	Store  *store.Store | 	Store          *store.Store | ||||||
|  | 	LicenseService *license.LicenseService | ||||||
| } | } | ||||||
|  |  | ||||||
| // NewUserService creates a new UserService. | // 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{ | 	return &UserService{ | ||||||
| 		Secret: secret, | 		Secret:         secret, | ||||||
| 		Store:  store, | 		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) | 		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{ | 	user, err := s.Store.CreateUser(ctx, &store.User{ | ||||||
| 		Email:        request.User.Email, | 		Email:        request.User.Email, | ||||||
| 		Nickname:     request.User.Nickname, | 		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.RegisterSubscriptionServiceServer(grpcServer, NewSubscriptionService(profile, store, licenseService)) | ||||||
| 	apiv2pb.RegisterWorkspaceServiceServer(grpcServer, NewWorkspaceService(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.RegisterUserSettingServiceServer(grpcServer, NewUserSettingService(store)) | ||||||
| 	apiv2pb.RegisterShortcutServiceServer(grpcServer, NewShortcutService(secret, store)) | 	apiv2pb.RegisterShortcutServiceServer(grpcServer, NewShortcutService(secret, store)) | ||||||
| 	reflection.Register(grpcServer) | 	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) { | func (s *WorkspaceService) GetWorkspaceProfile(ctx context.Context, _ *apiv2pb.GetWorkspaceProfileRequest) (*apiv2pb.GetWorkspaceProfileResponse, error) { | ||||||
| 	profile := &apiv2pb.WorkspaceProfile{ | 	profile := &apiv2pb.WorkspaceProfile{ | ||||||
| 		Mode: s.Profile.Mode, | 		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{}) | 	workspaceSetting, err := s.GetWorkspaceSetting(ctx, &apiv2pb.GetWorkspaceSettingRequest{}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, status.Errorf(codes.Internal, "failed to get workspace setting: %v", err) | 		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) | 	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 { | func (s *LicenseService) IsFeatureEnabled(feature FeatureType) bool { | ||||||
| 	matrix, ok := FeatureMatrix[feature] | 	matrix, ok := FeatureMatrix[feature] | ||||||
| 	if !ok { | 	if !ok { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Steven
					Steven