diff --git a/pkg/roles/handlers.go b/pkg/roles/handlers.go index 5d4791df8..4412290fa 100644 --- a/pkg/roles/handlers.go +++ b/pkg/roles/handlers.go @@ -199,8 +199,21 @@ func (a *API) handleCreate(w http.ResponseWriter, r *http.Request) { return } + + if role.ID != "" { + w.WriteHeader(http.StatusBadRequest) + json.NewEncoder(w).Encode( + types.Response{ + Message: "Role ID field is not allowed to be passed in", + Status: http.StatusBadRequest, + }, + ) + + return + } + user := a.userFromContext(r.Context()) - err = a.service.CreateRole(r.Context(), user.ID, role.ID) + err = a.service.CreateRole(r.Context(), user.ID, role.Name) if err != nil { @@ -218,7 +231,7 @@ func (a *API) handleCreate(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusCreated) json.NewEncoder(w).Encode( types.Response{ - Message: fmt.Sprintf("Created role %s", role.ID), + Message: fmt.Sprintf("Created role %s", role.Name), Status: http.StatusCreated, }, ) diff --git a/pkg/roles/handlers_test.go b/pkg/roles/handlers_test.go index cd1e12a83..8904b4997 100644 --- a/pkg/roles/handlers_test.go +++ b/pkg/roles/handlers_test.go @@ -1205,7 +1205,7 @@ func TestHandleCreate(t *testing.T) { mockService := NewMockServiceInterface(ctrl) upr := new(Role) - upr.ID = test.input + upr.Name = test.input payload, _ := json.Marshal(upr) req := httptest.NewRequest(http.MethodPost, "/api/v0/roles", bytes.NewReader(payload))