mirror of https://github.com/harness/drone.git
[MISC] Change `User Sign-Up` Default Value (#399)
parent
dc7b0a3d44
commit
e9ec7d1933
|
@ -1,4 +1,3 @@
|
|||
GITNESS_TRACE=true
|
||||
GITNESS_WEBHOOK_ALLOW_LOOPBACK=true
|
||||
GITNESS_PRINCIPAL_ADMIN_PASSWORD=changeit
|
||||
GITNESS_ALLOW_SIGN_UP=true
|
||||
GITNESS_PRINCIPAL_ADMIN_PASSWORD=changeit
|
|
@ -23,11 +23,11 @@ func NewController(principalStore store.PrincipalStore, config *types.Config) *C
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Controller) IsUserRegistrationAllowed(ctx context.Context) (bool, error) {
|
||||
func (c *Controller) IsUserSignupAllowed(ctx context.Context) (bool, error) {
|
||||
usrCount, err := c.principalStore.CountUsers(ctx, &types.UserFilter{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return usrCount == 0 || c.config.AllowSignUp, nil
|
||||
return usrCount == 0 || c.config.AllowUserSignup, nil
|
||||
}
|
||||
|
|
|
@ -25,13 +25,13 @@ type RegisterInput struct {
|
|||
// This doesn't require auth, but has limited functionalities (unable to create admin user for example).
|
||||
func (c *Controller) Register(ctx context.Context, sysCtrl *system.Controller,
|
||||
in *RegisterInput) (*types.TokenResponse, error) {
|
||||
signUpAllowed, err := sysCtrl.IsUserRegistrationAllowed(ctx)
|
||||
signUpAllowed, err := sysCtrl.IsUserSignupAllowed(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !signUpAllowed {
|
||||
return nil, usererror.ErrForbidden
|
||||
return nil, usererror.Forbidden("User sign-up is disabled")
|
||||
}
|
||||
|
||||
user, err := c.CreateNoAuth(ctx, &CreateInput{
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
type ConfigOutput struct {
|
||||
SignUpAllowed bool `json:"sign_up_allowed"`
|
||||
UserSignupAllowed bool `json:"user_signup_allowed"`
|
||||
}
|
||||
|
||||
// HandleGetConfig returns an http.HandlerFunc that processes an http.Request
|
||||
|
@ -21,13 +21,13 @@ func HandleGetConfig(sysCtrl *system.Controller) http.HandlerFunc {
|
|||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
signUpAllowedCheck, err := sysCtrl.IsUserRegistrationAllowed(ctx)
|
||||
userSignupAllowed, err := sysCtrl.IsUserSignupAllowed(ctx)
|
||||
if err != nil {
|
||||
render.TranslatedUserError(w, err)
|
||||
return
|
||||
}
|
||||
render.JSON(w, http.StatusOK, ConfigOutput{
|
||||
SignUpAllowed: signUpAllowedCheck,
|
||||
UserSignupAllowed: userSignupAllowed,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,6 +116,11 @@ func BadRequestWithPayload(message string, values ...map[string]any) *Error {
|
|||
return NewWithPayload(http.StatusBadRequest, message, values...)
|
||||
}
|
||||
|
||||
// Forbidden returns a new user facing forbidden error.
|
||||
func Forbidden(message string) *Error {
|
||||
return New(http.StatusForbidden, message)
|
||||
}
|
||||
|
||||
// ConflictWithPayload returns a new user facing conflict error with payload.
|
||||
func ConflictWithPayload(message string, values ...map[string]any) *Error {
|
||||
return NewWithPayload(http.StatusConflict, message, values...)
|
||||
|
|
|
@ -21,7 +21,7 @@ type Config struct {
|
|||
// 5min should be enough for most git clones to complete.
|
||||
GracefulShutdownTime time.Duration `envconfig:"GITNESS_GRACEFUL_SHUTDOWN_TIME" default:"300s"`
|
||||
|
||||
AllowSignUp bool `envconfig:"GITNESS_ALLOW_SIGN_UP"`
|
||||
AllowUserSignup bool `envconfig:"GITNESS_ALLOW_USER_SIGNUP" default:"true"`
|
||||
|
||||
Profiler struct {
|
||||
Type string `envconfig:"GITNESS_PROFILER_TYPE"`
|
||||
|
|
|
@ -488,7 +488,7 @@ export interface RepoSymlinkContent {
|
|||
}
|
||||
|
||||
export interface SystemConfigOutput {
|
||||
sign_up_allowed?: boolean
|
||||
user_signup_allowed?: boolean
|
||||
}
|
||||
|
||||
export type TimeDuration = number | null
|
||||
|
|
|
@ -6982,7 +6982,7 @@ components:
|
|||
type: object
|
||||
SystemConfigOutput:
|
||||
properties:
|
||||
sign_up_allowed:
|
||||
user_signup_allowed:
|
||||
type: boolean
|
||||
type: object
|
||||
TimeDuration:
|
||||
|
|
Loading…
Reference in New Issue