mirror of
https://github.com/harness/drone.git
synced 2025-05-08 13:51:03 +08:00
[CODE-621]: Move registration func out of controller struct
This commit is contained in:
parent
f18f142401
commit
71eab8e042
@ -11,25 +11,23 @@ import (
|
||||
"github.com/harness/gitness/types"
|
||||
)
|
||||
|
||||
type registrationCheck func(ctx context.Context) (bool, error)
|
||||
|
||||
type Controller struct {
|
||||
principalStore store.PrincipalStore
|
||||
config *types.Config
|
||||
IsUserRegistrationAllowed registrationCheck
|
||||
principalStore store.PrincipalStore
|
||||
config *types.Config
|
||||
}
|
||||
|
||||
func NewController(principalStore store.PrincipalStore, config *types.Config) *Controller {
|
||||
return &Controller{
|
||||
principalStore: principalStore,
|
||||
config: config,
|
||||
IsUserRegistrationAllowed: func(ctx context.Context) (bool, error) {
|
||||
usrCount, err := principalStore.CountUsers(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return usrCount == 0 || config.AllowSignUp, nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) IsUserRegistrationAllowed(ctx context.Context) (bool, error) {
|
||||
usrCount, err := c.principalStore.CountUsers(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return usrCount == 0 || c.config.AllowSignUp, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user