Make names required for resources
This commit is contained in:
@@ -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
|
||||
|
||||
34
server/automation/service/workflow_actions.gen.go
generated
34
server/automation/service/workflow_actions.gen.go
generated
@@ -575,6 +575,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
|
||||
//
|
||||
//
|
||||
|
||||
@@ -68,6 +68,9 @@ errors:
|
||||
- error: invalidHandle
|
||||
message: "invalid handle"
|
||||
|
||||
- error: missingName
|
||||
message: "missing name"
|
||||
|
||||
- error: staleData
|
||||
message: "stale data"
|
||||
severity: warning
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
34
server/system/service/dal_connection_actions.gen.go
generated
34
server/system/service/dal_connection_actions.gen.go
generated
@@ -453,6 +453,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
|
||||
//
|
||||
//
|
||||
|
||||
@@ -56,6 +56,9 @@ errors:
|
||||
message: "invalid ID"
|
||||
severity: warning
|
||||
|
||||
- error: missingName
|
||||
message: "missing name"
|
||||
|
||||
- error: invalidEndpoint
|
||||
message: "invalid DSN"
|
||||
severity: warning
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
34
server/system/service/template_actions.gen.go
generated
34
server/system/service/template_actions.gen.go
generated
@@ -535,6 +535,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
|
||||
//
|
||||
//
|
||||
|
||||
@@ -63,6 +63,9 @@ errors:
|
||||
message: "invalid handle"
|
||||
severity: warning
|
||||
|
||||
- error: missingShort
|
||||
message: "missing short name"
|
||||
|
||||
- error: cannotRenderPartial
|
||||
message: "cannot render partial templates"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user