mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-20 14:01:24 +00:00
chore: update user checks
This commit is contained in:
parent
8436d86661
commit
96f6fa4257
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/boojack/slash/api/auth"
|
"github.com/boojack/slash/api/auth"
|
||||||
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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -77,6 +78,16 @@ func (s *APIV1Service) registerAuthRoutes(g *echo.Group, secret string) {
|
|||||||
return echo.NewHTTPError(http.StatusForbidden, "sign up has been disabled")
|
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{}
|
signup := &SignUpRequest{}
|
||||||
if err := json.NewDecoder(c.Request().Body).Decode(signup); err != nil {
|
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)
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("malformatted signup request, err: %s", err)).SetInternal(err)
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
"github.com/boojack/slash/internal/util"
|
"github.com/boojack/slash/internal/util"
|
||||||
|
"github.com/boojack/slash/server/service/license"
|
||||||
"github.com/boojack/slash/store"
|
"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")
|
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{}
|
userCreate := &CreateUserRequest{}
|
||||||
if err := json.NewDecoder(c.Request().Body).Decode(userCreate); err != nil {
|
if err := json.NewDecoder(c.Request().Body).Decode(userCreate); err != nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post user request").SetInternal(err)
|
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post user request").SetInternal(err)
|
||||||
|
@ -81,7 +81,7 @@ func (s *UserService) CreateUser(ctx context.Context, request *apiv2pb.CreateUse
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "failed to list users: %v", err)
|
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")
|
return nil, status.Errorf(codes.ResourceExhausted, "maximum number of users reached")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -985,8 +985,9 @@
|
|||||||
|
|
||||||
| Field | Type | Label | Description |
|
| Field | Type | Label | Description |
|
||||||
| ----- | ---- | ----- | ----------- |
|
| ----- | ---- | ----- | ----------- |
|
||||||
| mode | [string](#string) | | |
|
| mode | [string](#string) | | Current workspace mode: dev, prod. |
|
||||||
| enable_signup | [bool](#bool) | | |
|
| 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_style | [string](#string) | | The custom style. |
|
||||||
| custom_script | [string](#string) | | The custom script. |
|
| custom_script | [string](#string) | | The custom script. |
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user