mirror of
https://github.com/harness/drone.git
synced 2025-05-06 04:19:58 +08:00
[CODE-617]: Lint issues
This commit is contained in:
parent
fe9bc1a4db
commit
b8c239ed6d
@ -7,19 +7,17 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/harness/gitness/internal/api/usererror"
|
"github.com/harness/gitness/internal/api/usererror"
|
||||||
"github.com/harness/gitness/internal/token"
|
"github.com/harness/gitness/internal/token"
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
// Register creates a new user and returns a new session token on success.
|
||||||
* Register creates a new user and returns a new session token on success.
|
// This differs from the Create method as it doesn't require auth, but has limited
|
||||||
* This differs from the Create method as it doesn't require auth, but has limited
|
// functionalities (unable to create admin user for example).
|
||||||
* functionalities (unable to create admin user for example).
|
|
||||||
*/
|
|
||||||
func (c *Controller) Register(ctx context.Context,
|
func (c *Controller) Register(ctx context.Context,
|
||||||
in *CreateInput, config *types.Config) (*types.TokenResponse, error) {
|
in *CreateInput, config *types.Config) (*types.TokenResponse, error) {
|
||||||
|
|
||||||
signUpFlag := config.AllowSignUp
|
signUpFlag := config.AllowSignUp
|
||||||
if !signUpFlag {
|
if !signUpFlag {
|
||||||
return nil, usererror.BadRequest("User sign-up is disabled.")
|
return nil, usererror.BadRequest("User sign-up is disabled.")
|
||||||
|
@ -11,11 +11,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// RegisterCheck checks the DB and env config flag to return boolean
|
// RegisterCheck checks the DB and env config flag to return boolean
|
||||||
// which represents if a user sign-up is allowed or not
|
// which represents if a user sign-up is allowed or not.
|
||||||
|
func (c *Controller) RegisterCheck(ctx context.Context, config *types.Config) (*bool, error) {
|
||||||
func (c *Controller) RegisterCheck(ctx context.Context,
|
|
||||||
config *types.Config) (*bool, error) {
|
|
||||||
|
|
||||||
usrCount, err := c.principalStore.CountUsers(ctx)
|
usrCount, err := c.principalStore.CountUsers(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// HandleRegisterCheck returns an http.HandlerFunc that processes an http.Request
|
// HandleRegisterCheck returns an http.HandlerFunc that processes an http.Request
|
||||||
// and returns a boolean true/false if user registration is allowed or not
|
// and returns a boolean true/false if user registration is allowed or not.
|
||||||
func HandleRegisterCheck(userCtrl *user.Controller, config *types.Config) http.HandlerFunc {
|
func HandleRegisterCheck(userCtrl *user.Controller, config *types.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
@ -24,6 +24,10 @@ type registerRequest struct {
|
|||||||
user.CreateInput
|
user.CreateInput
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type registrationCheckResponse struct {
|
||||||
|
Allowed bool `json:"allowed"`
|
||||||
|
}
|
||||||
|
|
||||||
// helper function that constructs the openapi specification
|
// helper function that constructs the openapi specification
|
||||||
// for the account registration and login endpoints.
|
// for the account registration and login endpoints.
|
||||||
func buildAccount(reflector *openapi3.Reflector) {
|
func buildAccount(reflector *openapi3.Reflector) {
|
||||||
@ -55,4 +59,13 @@ func buildAccount(reflector *openapi3.Reflector) {
|
|||||||
_ = reflector.SetJSONResponse(&onRegister, new(usererror.Error), http.StatusInternalServerError)
|
_ = reflector.SetJSONResponse(&onRegister, new(usererror.Error), http.StatusInternalServerError)
|
||||||
_ = reflector.SetJSONResponse(&onRegister, new(usererror.Error), http.StatusBadRequest)
|
_ = reflector.SetJSONResponse(&onRegister, new(usererror.Error), http.StatusBadRequest)
|
||||||
_ = reflector.Spec.AddOperation(http.MethodPost, "/register", onRegister)
|
_ = reflector.Spec.AddOperation(http.MethodPost, "/register", onRegister)
|
||||||
|
|
||||||
|
onRegistrationCheck := openapi3.Operation{}
|
||||||
|
onRegistrationCheck.WithTags("account")
|
||||||
|
onRegistrationCheck.WithMapOfAnything(map[string]interface{}{"operationId": "onRegistrationCheck"})
|
||||||
|
_ = reflector.SetRequest(&onRegistrationCheck, nil, http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&onRegistrationCheck, new(registrationCheckResponse), http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&onRegistrationCheck, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&onRegistrationCheck, new(usererror.Error), http.StatusBadRequest)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/registration-check", onRegistrationCheck)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user