Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix condition not returning error during initial login #4927

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading