From 1419a25e7960e021bdca83239e492aae8d3014cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Thu, 26 Jan 2023 15:22:59 +0100 Subject: [PATCH] Make names required for resources --- server/automation/service/workflow.go | 9 +++++ .../service/workflow_actions.gen.go | 34 +++++++++++++++++++ .../automation/service/workflow_actions.yaml | 3 ++ server/system/service/dal_connection.go | 8 +++++ .../service/dal_connection_actions.gen.go | 34 +++++++++++++++++++ .../service/dal_connection_actions.yaml | 3 ++ server/system/service/template.go | 11 +++++- server/system/service/template_actions.gen.go | 34 +++++++++++++++++++ server/system/service/template_actions.yaml | 3 ++ 9 files changed, 138 insertions(+), 1 deletion(-) diff --git a/server/automation/service/workflow.go b/server/automation/service/workflow.go index 93e635f29..9f934812f 100644 --- a/server/automation/service/workflow.go +++ b/server/automation/service/workflow.go @@ -204,6 +204,10 @@ func (svc *workflow) Create(ctx context.Context, new *types.Workflow) (wf *types return WorkflowErrNotAllowedToCreate() } + if new.Meta.Name == "" { + return WorkflowErrMissingName() + } + if !handle.IsValid(new.Handle) { return WorkflowErrInvalidHandle() } @@ -263,6 +267,10 @@ func (svc *workflow) Create(ctx context.Context, new *types.Workflow) (wf *types // Update modifies existing workflow resource in the store func (svc *workflow) Update(ctx context.Context, upd *types.Workflow) (*types.Workflow, error) { return svc.updater(ctx, upd.ID, WorkflowActionUpdate, func(ctx context.Context, res *types.Workflow) (workflowChanges, error) { + if upd.Meta.Name == "" { + return workflowUnchanged, WorkflowErrMissingName() + } + if !svc.ac.CanUpdateWorkflow(ctx, res) { return workflowUnchanged, WorkflowErrNotAllowedToUpdate() } @@ -319,6 +327,7 @@ func (svc *workflow) updater(ctx context.Context, workflowID uint64, action func ) err = store.Tx(ctx, svc.store, func(ctx context.Context, s store.Storer) (err error) { + res, err = loadWorkflow(ctx, s, workflowID) if err != nil { return diff --git a/server/automation/service/workflow_actions.gen.go b/server/automation/service/workflow_actions.gen.go index fdb1996ff..ecf56ff73 100644 --- a/server/automation/service/workflow_actions.gen.go +++ b/server/automation/service/workflow_actions.gen.go @@ -585,6 +585,40 @@ func WorkflowErrInvalidHandle(mm ...*workflowActionProps) *errors.Error { return e } +// WorkflowErrMissingName returns "automation:workflow.missingName" as *errors.Error +// +// +// This function is auto-generated. +// +func WorkflowErrMissingName(mm ...*workflowActionProps) *errors.Error { + var p = &workflowActionProps{} + if len(mm) > 0 { + p = mm[0] + } + + var e = errors.New( + errors.KindInternal, + + p.Format("missing name", nil), + + errors.Meta("type", "missingName"), + errors.Meta("resource", "automation:workflow"), + + errors.Meta(workflowPropsMetaKey{}, p), + + // translation namespace & key + errors.Meta(locale.ErrorMetaNamespace{}, "automation"), + errors.Meta(locale.ErrorMetaKey{}, "workflow.errors.missingName"), + + errors.StackSkip(1), + ) + + if len(mm) > 0 { + } + + return e +} + // WorkflowErrStaleData returns "automation:workflow.staleData" as *errors.Error // // diff --git a/server/automation/service/workflow_actions.yaml b/server/automation/service/workflow_actions.yaml index e4573ebf7..a2282ca28 100644 --- a/server/automation/service/workflow_actions.yaml +++ b/server/automation/service/workflow_actions.yaml @@ -68,6 +68,9 @@ errors: - error: invalidHandle message: "invalid handle" + - error: missingName + message: "missing name" + - error: staleData message: "stale data" severity: warning diff --git a/server/system/service/dal_connection.go b/server/system/service/dal_connection.go index 9fc06adcb..2d2795a18 100644 --- a/server/system/service/dal_connection.go +++ b/server/system/service/dal_connection.go @@ -82,6 +82,10 @@ func (svc *dalConnection) Create(ctx context.Context, new *types.DalConnection) ) err = func() (err error) { + if new.Meta.Name == "" { + return DalConnectionErrMissingName() + } + if !svc.ac.CanCreateDalConnection(ctx) { return DalConnectionErrNotAllowedToCreate(qProps) } @@ -122,6 +126,10 @@ func (svc *dalConnection) Update(ctx context.Context, upd *types.DalConnection) ) err = func() (err error) { + if upd.Meta.Name == "" { + return DalConnectionErrMissingName() + } + if old, err = loadDalConnection(ctx, svc.store, upd.ID); err != nil { return DalConnectionErrNotFound(cProps) } diff --git a/server/system/service/dal_connection_actions.gen.go b/server/system/service/dal_connection_actions.gen.go index 7235a2f62..2767b4ace 100644 --- a/server/system/service/dal_connection_actions.gen.go +++ b/server/system/service/dal_connection_actions.gen.go @@ -461,6 +461,40 @@ func DalConnectionErrInvalidID(mm ...*dalConnectionActionProps) *errors.Error { return e } +// DalConnectionErrMissingName returns "system:dal-connection.missingName" as *errors.Error +// +// +// This function is auto-generated. +// +func DalConnectionErrMissingName(mm ...*dalConnectionActionProps) *errors.Error { + var p = &dalConnectionActionProps{} + if len(mm) > 0 { + p = mm[0] + } + + var e = errors.New( + errors.KindInternal, + + p.Format("missing name", nil), + + errors.Meta("type", "missingName"), + errors.Meta("resource", "system:dal-connection"), + + errors.Meta(dalConnectionPropsMetaKey{}, p), + + // translation namespace & key + errors.Meta(locale.ErrorMetaNamespace{}, "system"), + errors.Meta(locale.ErrorMetaKey{}, "dal-connection.errors.missingName"), + + errors.StackSkip(1), + ) + + if len(mm) > 0 { + } + + return e +} + // DalConnectionErrInvalidEndpoint returns "system:dal-connection.invalidEndpoint" as *errors.Error // // diff --git a/server/system/service/dal_connection_actions.yaml b/server/system/service/dal_connection_actions.yaml index 6fb6545f9..67e621b75 100644 --- a/server/system/service/dal_connection_actions.yaml +++ b/server/system/service/dal_connection_actions.yaml @@ -56,6 +56,9 @@ errors: message: "invalid ID" severity: warning + - error: missingName + message: "missing name" + - error: invalidEndpoint message: "invalid DSN" severity: warning diff --git a/server/system/service/template.go b/server/system/service/template.go index 12fbba911..497edbe37 100644 --- a/server/system/service/template.go +++ b/server/system/service/template.go @@ -4,11 +4,12 @@ import ( "bytes" "context" "fmt" - "github.com/cortezaproject/corteza/server/pkg/errors" "io" "strconv" "strings" + "github.com/cortezaproject/corteza/server/pkg/errors" + "github.com/cortezaproject/corteza/server/pkg/actionlog" "github.com/cortezaproject/corteza/server/pkg/handle" "github.com/cortezaproject/corteza/server/pkg/label" @@ -197,6 +198,10 @@ func (svc template) Create(ctx context.Context, new *types.Template) (tpl *types return TemplateErrInvalidHandle() } + if new.Meta.Short == "" { + return TemplateErrMissingShort() + } + if !svc.ac.CanCreateTemplate(ctx) { return TemplateErrNotAllowedToCreate() } @@ -233,6 +238,10 @@ func (svc template) Update(ctx context.Context, upd *types.Template) (tpl *types return TemplateErrInvalidHandle() } + if upd.Meta.Short == "" { + return TemplateErrMissingShort() + } + if tpl, err = loadTemplate(ctx, svc.store, upd.ID); err != nil { return } diff --git a/server/system/service/template_actions.gen.go b/server/system/service/template_actions.gen.go index c40780eda..f591f0d82 100644 --- a/server/system/service/template_actions.gen.go +++ b/server/system/service/template_actions.gen.go @@ -543,6 +543,40 @@ func TemplateErrInvalidHandle(mm ...*templateActionProps) *errors.Error { return e } +// TemplateErrMissingShort returns "system:template.missingShort" as *errors.Error +// +// +// This function is auto-generated. +// +func TemplateErrMissingShort(mm ...*templateActionProps) *errors.Error { + var p = &templateActionProps{} + if len(mm) > 0 { + p = mm[0] + } + + var e = errors.New( + errors.KindInternal, + + p.Format("missing short name", nil), + + errors.Meta("type", "missingShort"), + errors.Meta("resource", "system:template"), + + errors.Meta(templatePropsMetaKey{}, p), + + // translation namespace & key + errors.Meta(locale.ErrorMetaNamespace{}, "system"), + errors.Meta(locale.ErrorMetaKey{}, "template.errors.missingShort"), + + errors.StackSkip(1), + ) + + if len(mm) > 0 { + } + + return e +} + // TemplateErrCannotRenderPartial returns "system:template.cannotRenderPartial" as *errors.Error // // diff --git a/server/system/service/template_actions.yaml b/server/system/service/template_actions.yaml index db73ae055..fb6457410 100644 --- a/server/system/service/template_actions.yaml +++ b/server/system/service/template_actions.yaml @@ -63,6 +63,9 @@ errors: message: "invalid handle" severity: warning + - error: missingShort + message: "missing short name" + - error: cannotRenderPartial message: "cannot render partial templates"