drone/internal/api/controller/user/register_check.go
2023-07-20 19:03:25 +05:30

28 lines
676 B
Go

// Copyright 2022 Harness Inc. All rights reserved.
// Use of this source code is governed by the Polyform Free Trial License
// that can be found in the LICENSE.md file for this repository.
package user
import (
"context"
"github.com/harness/gitness/types"
)
// RegisterCheck checks the DB and env config flag to return boolean
// which represents if a user sign-up is allowed or not.
func (c *Controller) RegisterCheck(ctx context.Context, config *types.Config) (*bool, error) {
usrCount, err := c.principalStore.CountUsers(ctx)
if err != nil {
return nil, err
}
check := false
if usrCount == 0 || config.AllowSignUp {
check = true
}
return &check, nil
}