Skip to content

Commit

Permalink
Remove no longer used validate endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Dec 18, 2019
1 parent 1e3dcc7 commit f1197af
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 362 deletions.
2 changes: 2 additions & 0 deletions hooks/msg_created_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/actions"
"github.com/nyaruka/goflow/utils/uuids"
)

func TestMsgCreated(t *testing.T) {
Expand All @@ -39,6 +40,7 @@ func TestMsgCreated(t *testing.T) {

templateAction := actions.NewSendMsg(newActionUUID(), "Template time", nil, nil, false)
templateAction.Templating = &actions.Templating{
UUID: uuids.UUID("db297d56-ec8c-4231-bbe8-030369777ae1"),
Template: &assets.TemplateReference{assets.TemplateUUID("9c22b594-fcab-4b29-9bcb-ce4404894a80"), "revive_issue"},
Variables: []string{"@contact.name", "tooth"},
}
Expand Down
48 changes: 0 additions & 48 deletions web/flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

func init() {
web.RegisterJSONRoute(http.MethodPost, "/mr/flow/migrate", web.RequireAuthToken(handleMigrate))
web.RegisterJSONRoute(http.MethodPost, "/mr/flow/validate", web.RequireAuthToken(handleValidate))
web.RegisterJSONRoute(http.MethodPost, "/mr/flow/inspect", web.RequireAuthToken(handleInspect))
web.RegisterJSONRoute(http.MethodPost, "/mr/flow/clone", web.RequireAuthToken(handleClone))
}
Expand Down Expand Up @@ -60,53 +59,6 @@ func handleMigrate(ctx context.Context, s *web.Server, r *http.Request) (interfa
return migrated, http.StatusOK, nil
}

// Validates a flow. If validation fails, we return the error. If it succeeds, we return
// the valid definition which will now include extracted dependencies. The provided flow
// definition can be in either legacy or new format, but the returned definition will
// always be in the new format. `org_id` is optional and determines whether we load and
// pass assets to the flow validation to find missing assets.
//
// Note that a invalid request to this endpoint will return a 400 status code, but that a
// valid request with a flow that fails validation will return a 422 status code.
//
// {
// "org_id": 1,
// "flow": { "uuid": "468621a8-32e6-4cd2-afc1-04416f7151f0", "nodes": [...]}
// }
//
type validateRequest struct {
OrgID models.OrgID `json:"org_id"`
Flow json.RawMessage `json:"flow" validate:"required"`
}

func handleValidate(ctx context.Context, s *web.Server, r *http.Request) (interface{}, int, error) {
request := &validateRequest{}
if err := utils.UnmarshalAndValidateWithLimit(r.Body, request, web.MaxRequestBytes); err != nil {
return errors.Wrapf(err, "request failed validation"), http.StatusBadRequest, nil
}

flow, err := goflow.ReadFlow(request.Flow)
if err != nil {
return errors.Wrapf(err, "unable to read flow"), http.StatusUnprocessableEntity, nil
}

// if we have an org ID, do asset validation
if request.OrgID != models.NilOrgID {
result, status, err := validate(s.CTX, s.DB, request.OrgID, flow)
if result != nil || err != nil {
return result, status, err
}
}

// this endpoint returns inspection results inside the definition
result, err := flow.MarshalWithInfo()
if err != nil {
return nil, http.StatusInternalServerError, errors.Wrapf(err, "unable to marshal flow")
}

return json.RawMessage(result), http.StatusOK, nil
}

// Inspects a flow, and returns metadata including the possible results generated by the flow,
// and dependencies in the flow. If `validate_with_org_id` is specified then the cloned flow
// will be validated against the assets of that org.
Expand Down
6 changes: 0 additions & 6 deletions web/flow/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ func TestServer(t *testing.T) {
{URL: "/mr/flow/migrate", Method: "POST", BodyFile: "migrate_minimal_legacy.json", Status: 200, ResponseFile: "migrate_minimal_legacy.response.json"},
{URL: "/mr/flow/migrate", Method: "POST", BodyFile: "migrate_legacy_with_version.json", Status: 200, ResponseFile: "migrate_legacy_with_version.response.json"},

{URL: "/mr/flow/validate", Method: "GET", Status: 405, Response: `{"error": "illegal method: GET"}`},
{URL: "/mr/flow/validate", Method: "POST", BodyFile: "validate_valid_legacy.json", Status: 200, ResponseFile: "validate_valid_legacy.response.json"},
{URL: "/mr/flow/validate", Method: "POST", BodyFile: "validate_invalid_legacy.json", Status: 422, ResponseFile: "validate_invalid_legacy.response.json"},
{URL: "/mr/flow/validate", Method: "POST", BodyFile: "validate_valid.json", Status: 200, ResponseFile: "validate_valid.response.json"},
{URL: "/mr/flow/validate", Method: "POST", BodyFile: "validate_invalid.json", Status: 422, ResponseFile: "validate_invalid.response.json"},

{URL: "/mr/flow/inspect", Method: "GET", Status: 405, Response: `{"error": "illegal method: GET"}`},
{URL: "/mr/flow/inspect", Method: "POST", BodyFile: "inspect_valid_legacy.json", Status: 200, ResponseFile: "inspect_valid_legacy.response.json"},
{URL: "/mr/flow/inspect", Method: "POST", BodyFile: "inspect_invalid_legacy.json", Status: 422, ResponseFile: "inspect_invalid_legacy.response.json"},
Expand Down
36 changes: 0 additions & 36 deletions web/flow/testdata/validate_invalid.json

This file was deleted.

3 changes: 0 additions & 3 deletions web/flow/testdata/validate_invalid.response.json

This file was deleted.

48 changes: 0 additions & 48 deletions web/flow/testdata/validate_invalid_legacy.json

This file was deleted.

3 changes: 0 additions & 3 deletions web/flow/testdata/validate_invalid_legacy.response.json

This file was deleted.

52 changes: 0 additions & 52 deletions web/flow/testdata/validate_valid.json

This file was deleted.

59 changes: 0 additions & 59 deletions web/flow/testdata/validate_valid.response.json

This file was deleted.

48 changes: 0 additions & 48 deletions web/flow/testdata/validate_valid_legacy.json

This file was deleted.

Loading

0 comments on commit f1197af

Please sign in to comment.