Skip to content

Commit

Permalink
Fix condition not returning error during initial login (#4927)
Browse files Browse the repository at this point in the history
* Fix an error creating a project when the password is default

Signed-off-by: DongYoung Kim <kwx4957@gmail.com>

* Separate logic into a single if block for better readability

Signed-off-by: DongYoung Kim <kwx4957@gmail.com>

* Fix condition not returning error during initial login

Signed-off-by: DongYoung Kim <kwx4957@gmail.com>

---------

Signed-off-by: DongYoung Kim <kwx4957@gmail.com>
  • Loading branch information
kwx4957 authored Oct 29, 2024
1 parent b17b093 commit 5f21a1e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
42 changes: 35 additions & 7 deletions chaoscenter/authentication/api/handlers/rest/project_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,12 @@ func CreateProject(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, userRequest.UserID)
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

// checking if project name is empty
Expand Down Expand Up @@ -456,8 +460,12 @@ func SendInvitation(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, c.MustGet("uid").(string))
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

// Validating member role
Expand Down Expand Up @@ -558,8 +566,12 @@ func AcceptInvitation(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, c.MustGet("uid").(string))
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

err = validations.RbacValidator(c.MustGet("uid").(string), member.ProjectID,
Expand Down Expand Up @@ -614,8 +626,12 @@ func DeclineInvitation(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, c.MustGet("uid").(string))
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

err = validations.RbacValidator(c.MustGet("uid").(string), member.ProjectID,
Expand Down Expand Up @@ -684,8 +700,12 @@ func LeaveProject(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, c.MustGet("uid").(string))
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

err = validations.RbacValidator(c.MustGet("uid").(string), member.ProjectID,
Expand Down Expand Up @@ -744,8 +764,12 @@ func RemoveInvitation(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, c.MustGet("uid").(string))
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

err = validations.RbacValidator(c.MustGet("uid").(string), member.ProjectID,
Expand Down Expand Up @@ -824,8 +848,12 @@ func UpdateProjectName(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, c.MustGet("uid").(string))
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

err = validations.RbacValidator(c.MustGet("uid").(string),
Expand Down
31 changes: 26 additions & 5 deletions chaoscenter/authentication/api/handlers/rest/user_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,18 @@ func UpdateUser(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, uid)
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

err = service.UpdateUser(&userRequest)
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
return
}
c.JSON(http.StatusOK, gin.H{"message": "User details updated successfully"})
}
Expand Down Expand Up @@ -554,8 +559,12 @@ func ResetPassword(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, uid)
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

if userPasswordRequest.NewPassword != "" {
Expand Down Expand Up @@ -610,8 +619,12 @@ func UpdateUserState(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, adminUser.ID)
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

if entities.Role(userRole) != entities.RoleAdmin {
Expand Down Expand Up @@ -689,8 +702,12 @@ func CreateApiToken(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, apiTokenRequest.UserID)
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

// Checking if user exists
Expand Down Expand Up @@ -785,8 +802,12 @@ func DeleteApiToken(service services.ApplicationService) gin.HandlerFunc {
initialLogin, err := CheckInitialLogin(service, deleteApiTokenRequest.UserID)
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
} else if initialLogin {
return
}

if initialLogin {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrPasswordNotUpdated))
return
}

token := deleteApiTokenRequest.Token
Expand Down

0 comments on commit 5f21a1e

Please sign in to comment.