fix(task): restore functionality for creating task with org name
This is a partial rollback of changes #12004. Issue to track adding a test: #12089.pull/12098/head
parent
bf34b35fb4
commit
ecb37d7cc4
|
@ -435,6 +435,15 @@ func (h *TaskHandler) handlePostTask(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := h.populateTaskCreateOrg(ctx, &req.TaskCreate); err != nil {
|
||||
err = &platform.Error{
|
||||
Err: err,
|
||||
Msg: "could not identify organization",
|
||||
}
|
||||
EncodeError(ctx, err, w)
|
||||
return
|
||||
}
|
||||
|
||||
if !req.TaskCreate.OrganizationID.Valid() {
|
||||
err := &platform.Error{
|
||||
Code: platform.EInvalid,
|
||||
|
@ -1126,6 +1135,31 @@ func decodeRetryRunRequest(ctx context.Context, r *http.Request) (*retryRunReque
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (h *TaskHandler) populateTaskCreateOrg(ctx context.Context, tc *platform.TaskCreate) error {
|
||||
if tc.OrganizationID.Valid() && tc.Organization != "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !tc.OrganizationID.Valid() && tc.Organization == "" {
|
||||
return errors.New("missing orgID and organization name")
|
||||
}
|
||||
|
||||
if tc.OrganizationID.Valid() {
|
||||
o, err := h.OrganizationService.FindOrganizationByID(ctx, tc.OrganizationID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tc.Organization = o.Name
|
||||
} else {
|
||||
o, err := h.OrganizationService.FindOrganization(ctx, platform.OrganizationFilter{Name: &tc.Organization})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tc.OrganizationID = o.ID
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TaskService connects to Influx via HTTP using tokens to manage tasks.
|
||||
type TaskService struct {
|
||||
Addr string
|
||||
|
|
Loading…
Reference in New Issue