mirror of
https://github.com/harness/drone.git
synced 2025-05-21 19:39:59 +08:00
[MISC] Change User Sign-Up
Default Value (#399)
This commit is contained in:
parent
dc7b0a3d44
commit
e9ec7d1933
@ -1,4 +1,3 @@
|
|||||||
GITNESS_TRACE=true
|
GITNESS_TRACE=true
|
||||||
GITNESS_WEBHOOK_ALLOW_LOOPBACK=true
|
GITNESS_WEBHOOK_ALLOW_LOOPBACK=true
|
||||||
GITNESS_PRINCIPAL_ADMIN_PASSWORD=changeit
|
GITNESS_PRINCIPAL_ADMIN_PASSWORD=changeit
|
||||||
GITNESS_ALLOW_SIGN_UP=true
|
|
@ -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{})
|
usrCount, err := c.principalStore.CountUsers(ctx, &types.UserFilter{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
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).
|
// 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,
|
func (c *Controller) Register(ctx context.Context, sysCtrl *system.Controller,
|
||||||
in *RegisterInput) (*types.TokenResponse, error) {
|
in *RegisterInput) (*types.TokenResponse, error) {
|
||||||
signUpAllowed, err := sysCtrl.IsUserRegistrationAllowed(ctx)
|
signUpAllowed, err := sysCtrl.IsUserSignupAllowed(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !signUpAllowed {
|
if !signUpAllowed {
|
||||||
return nil, usererror.ErrForbidden
|
return nil, usererror.Forbidden("User sign-up is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := c.CreateNoAuth(ctx, &CreateInput{
|
user, err := c.CreateNoAuth(ctx, &CreateInput{
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ConfigOutput struct {
|
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
|
// 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) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
signUpAllowedCheck, err := sysCtrl.IsUserRegistrationAllowed(ctx)
|
userSignupAllowed, err := sysCtrl.IsUserSignupAllowed(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.TranslatedUserError(w, err)
|
render.TranslatedUserError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
render.JSON(w, http.StatusOK, ConfigOutput{
|
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...)
|
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.
|
// ConflictWithPayload returns a new user facing conflict error with payload.
|
||||||
func ConflictWithPayload(message string, values ...map[string]any) *Error {
|
func ConflictWithPayload(message string, values ...map[string]any) *Error {
|
||||||
return NewWithPayload(http.StatusConflict, message, values...)
|
return NewWithPayload(http.StatusConflict, message, values...)
|
||||||
|
@ -21,7 +21,7 @@ type Config struct {
|
|||||||
// 5min should be enough for most git clones to complete.
|
// 5min should be enough for most git clones to complete.
|
||||||
GracefulShutdownTime time.Duration `envconfig:"GITNESS_GRACEFUL_SHUTDOWN_TIME" default:"300s"`
|
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 {
|
Profiler struct {
|
||||||
Type string `envconfig:"GITNESS_PROFILER_TYPE"`
|
Type string `envconfig:"GITNESS_PROFILER_TYPE"`
|
||||||
|
@ -488,7 +488,7 @@ export interface RepoSymlinkContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface SystemConfigOutput {
|
export interface SystemConfigOutput {
|
||||||
sign_up_allowed?: boolean
|
user_signup_allowed?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TimeDuration = number | null
|
export type TimeDuration = number | null
|
||||||
|
@ -6982,7 +6982,7 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
SystemConfigOutput:
|
SystemConfigOutput:
|
||||||
properties:
|
properties:
|
||||||
sign_up_allowed:
|
user_signup_allowed:
|
||||||
type: boolean
|
type: boolean
|
||||||
type: object
|
type: object
|
||||||
TimeDuration:
|
TimeDuration:
|
||||||
|
Loading…
Reference in New Issue
Block a user