mirror of
https://github.com/harness/drone.git
synced 2025-05-12 23:20:10 +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"
|
"github.com/harness/gitness/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type registrationCheck func(ctx context.Context) (bool, error)
|
|
||||||
|
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
principalStore store.PrincipalStore
|
principalStore store.PrincipalStore
|
||||||
config *types.Config
|
config *types.Config
|
||||||
IsUserRegistrationAllowed registrationCheck
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController(principalStore store.PrincipalStore, config *types.Config) *Controller {
|
func NewController(principalStore store.PrincipalStore, config *types.Config) *Controller {
|
||||||
return &Controller{
|
return &Controller{
|
||||||
principalStore: principalStore,
|
principalStore: principalStore,
|
||||||
config: config,
|
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