Skip to content

Commit

Permalink
refactor: pass in passwordMinLength to invalidPasswordError instead o…
Browse files Browse the repository at this point in the history
…f whole config (#1078)

Co-authored-by: joel@joellee.org <joel@joellee.org>
  • Loading branch information
J0 and joel@joellee.org authored Apr 14, 2023
1 parent 1aa8447 commit c2691e4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (a *API) adminUserUpdate(w http.ResponseWriter, r *http.Request) error {

if params.Password != nil {
if len(*params.Password) < config.PasswordMinLength {
return invalidPasswordLengthError(config)
return invalidPasswordLengthError(config.PasswordMinLength)
}

if terr := user.UpdatePassword(tx, *params.Password); terr != nil {
Expand Down Expand Up @@ -284,7 +284,7 @@ func (a *API) adminUserUpdate(w http.ResponseWriter, r *http.Request) error {
})

if err != nil {
if errors.Is(err, invalidPasswordLengthError(config)) {
if errors.Is(err, invalidPasswordLengthError(config.PasswordMinLength)) {
return err
}
return internalServerError("Error updating user").WithInternalError(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func (e *OAuthError) Cause() error {
return e
}

func invalidPasswordLengthError(config *conf.GlobalConfiguration) *HTTPError {
return unprocessableEntityError(fmt.Sprintf("Password should be at least %d characters", config.PasswordMinLength))
func invalidPasswordLengthError(passwordMinLength int) *HTTPError {
return unprocessableEntityError(fmt.Sprintf("Password should be at least %d characters", passwordMinLength))
}

func invalidSignupError(config *conf.GlobalConfiguration) *HTTPError {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (a *API) UserUpdate(w http.ResponseWriter, r *http.Request) error {
var terr error
if params.Password != nil {
if len(*params.Password) < config.PasswordMinLength {
return invalidPasswordLengthError(config)
return invalidPasswordLengthError(config.PasswordMinLength)
}

isPasswordUpdated := false
Expand Down

0 comments on commit c2691e4

Please sign in to comment.