chore: tweak feature matrix

This commit is contained in:
Steven
2024-08-12 21:29:57 +08:00
parent 00e2a6fd96
commit 7c31fd444c
13 changed files with 176 additions and 198 deletions

View File

@ -218,7 +218,7 @@ func (s *APIV1Service) checkSeatAvailability(ctx context.Context) error {
return status.Errorf(codes.Internal, fmt.Sprintf("failed to list users, err: %s", err))
}
seats := s.LicenseService.GetSubscription().Seats
if len(userList) > int(seats) {
if len(userList) >= int(seats) {
return status.Errorf(codes.FailedPrecondition, "maximum number of users %d reached", seats)
}
}

View File

@ -14,7 +14,6 @@ import (
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
storepb "github.com/yourselfhosted/slash/proto/gen/store"
"github.com/yourselfhosted/slash/server/service/license"
"github.com/yourselfhosted/slash/store"
)
@ -63,14 +62,8 @@ func (s *APIV1Service) CreateUser(ctx context.Context, request *v1pb.CreateUserR
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) >= 5 {
return nil, status.Errorf(codes.ResourceExhausted, "maximum number of users reached")
}
if err := s.checkSeatAvailability(ctx); err != nil {
return nil, err
}
user, err := s.Store.CreateUser(ctx, &store.User{

View File

@ -24,6 +24,7 @@ func (s *APIV1Service) GetWorkspaceProfile(ctx context.Context, _ *v1pb.GetWorks
// Load subscription plan from license service.
subscription := s.LicenseService.GetSubscription()
workspaceProfile.Plan = subscription.Plan
workspaceProfile.Features = subscription.Features
owner, err := s.GetInstanceOwner(ctx)
if err != nil {

View File

@ -33,7 +33,8 @@ func NewLicenseService(profile *profile.Profile, store *store.Store) *LicenseSer
Profile: profile,
Store: store,
cachedSubscription: &v1pb.Subscription{
Plan: v1pb.PlanType_FREE,
Plan: v1pb.PlanType_FREE,
Seats: 5,
},
}
}
@ -45,8 +46,10 @@ func (s *LicenseService) LoadSubscription(ctx context.Context) (*v1pb.Subscripti
if err != nil {
return nil, errors.Wrap(err, "failed to get workspace setting")
}
subscription := &v1pb.Subscription{
Plan: v1pb.PlanType_FREE,
Plan: v1pb.PlanType_FREE,
Seats: 5,
}
licenseKey := ""
if workspaceSettingGeneral != nil {