diff --git a/api/v1/auth.go b/api/v1/auth.go index 46bea57..9747d8a 100644 --- a/api/v1/auth.go +++ b/api/v1/auth.go @@ -13,6 +13,7 @@ import ( "github.com/boojack/slash/api/auth" storepb "github.com/boojack/slash/proto/gen/store" + "github.com/boojack/slash/server/service/license" "github.com/boojack/slash/store" ) @@ -77,6 +78,16 @@ func (s *APIV1Service) registerAuthRoutes(g *echo.Group, secret string) { return echo.NewHTTPError(http.StatusForbidden, "sign up has been disabled") } + if !s.LicenseService.IsFeatureEnabled(license.FeatureTypeUnlimitedAccounts) { + userList, err := s.Store.ListUsers(ctx, &store.FindUser{}) + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, "Failed to list users").SetInternal(err) + } + if len(userList) >= 5 { + return echo.NewHTTPError(http.StatusBadRequest, "Maximum number of users reached") + } + } + signup := &SignUpRequest{} if err := json.NewDecoder(c.Request().Body).Decode(signup); err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("malformatted signup request, err: %s", err)).SetInternal(err) diff --git a/api/v1/user.go b/api/v1/user.go index 81776d2..7075f0b 100644 --- a/api/v1/user.go +++ b/api/v1/user.go @@ -11,6 +11,7 @@ import ( "golang.org/x/crypto/bcrypt" "github.com/boojack/slash/internal/util" + "github.com/boojack/slash/server/service/license" "github.com/boojack/slash/store" ) @@ -102,6 +103,16 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) { return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized to create user") } + if !s.LicenseService.IsFeatureEnabled(license.FeatureTypeUnlimitedAccounts) { + userList, err := s.Store.ListUsers(ctx, &store.FindUser{}) + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, "Failed to list users").SetInternal(err) + } + if len(userList) >= 5 { + return echo.NewHTTPError(http.StatusBadRequest, "Maximum number of users reached") + } + } + userCreate := &CreateUserRequest{} if err := json.NewDecoder(c.Request().Body).Decode(userCreate); err != nil { return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post user request").SetInternal(err) diff --git a/api/v2/user_service.go b/api/v2/user_service.go index 21b1f37..dfe77d3 100644 --- a/api/v2/user_service.go +++ b/api/v2/user_service.go @@ -81,7 +81,7 @@ func (s *UserService) CreateUser(ctx context.Context, request *apiv2pb.CreateUse if err != nil { return nil, status.Errorf(codes.Internal, "failed to list users: %v", err) } - if len(userList) >= 3 { + if len(userList) >= 5 { return nil, status.Errorf(codes.ResourceExhausted, "maximum number of users reached") } } diff --git a/proto/gen/api/v2/README.md b/proto/gen/api/v2/README.md index 8812764..aa2c257 100644 --- a/proto/gen/api/v2/README.md +++ b/proto/gen/api/v2/README.md @@ -985,8 +985,9 @@ | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| mode | [string](#string) | | | -| enable_signup | [bool](#bool) | | | +| mode | [string](#string) | | Current workspace mode: dev, prod. | +| plan | [PlanType](#slash-api-v2-PlanType) | | The workspace plan. | +| enable_signup | [bool](#bool) | | Whether to enable other users to sign up. | | custom_style | [string](#string) | | The custom style. | | custom_script | [string](#string) | | The custom script. |