Define base DAL schema alteration resource
This commit is contained in:
@@ -31,6 +31,7 @@ component: schema.#component & {
|
||||
"user": user
|
||||
"dal-connection": dal_connection
|
||||
"dal-sensitivity-level": dal_sensitivity_level
|
||||
"dal-schema-alteration": dal_schema_alteration
|
||||
}
|
||||
|
||||
rbac: operations: {
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/codegen/schema"
|
||||
)
|
||||
|
||||
dal_schema_alteration: {
|
||||
features: {
|
||||
labels: false
|
||||
checkFn: false
|
||||
}
|
||||
|
||||
model: {
|
||||
// lengths for the lang, resource fields are now a bit shorter
|
||||
// Reason for that is supported index length in MySQL
|
||||
attributes: {
|
||||
id: schema.IdField
|
||||
batchID: {
|
||||
goType: "uint64"
|
||||
dal: { type: "ID" }
|
||||
}
|
||||
dependsOn: {
|
||||
goType: "uint64"
|
||||
dal: { type: "Ref", refModelResType: "corteza::system:dal-schema-alteration" }
|
||||
}
|
||||
|
||||
kind: {
|
||||
dal: { type: "Text", length: 256 }
|
||||
}
|
||||
params: {
|
||||
goType: "*types.DalSchemaAlterationParams"
|
||||
dal: { type: "JSON", defaultEmptyObject: true }
|
||||
omitSetter: true
|
||||
omitGetter: true
|
||||
}
|
||||
|
||||
created_at: schema.SortableTimestampNowField
|
||||
updated_at: schema.SortableTimestampNilField
|
||||
deleted_at: schema.SortableTimestampNilField
|
||||
completed_at: schema.SortableTimestampNilField
|
||||
created_by: schema.AttributeUserRef
|
||||
updated_by: schema.AttributeUserRef
|
||||
deleted_by: schema.AttributeUserRef
|
||||
completed_by: schema.AttributeUserRef
|
||||
}
|
||||
|
||||
indexes: {
|
||||
"primary": { attribute: "id" }
|
||||
"unique_alteration": {
|
||||
fields: [
|
||||
{ attribute: "id", modifiers: [ "LOWERCASE" ] },
|
||||
{ attribute: "batchID", modifiers: [ "LOWERCASE" ] },
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
envoy: {
|
||||
// Not needed for this resource (yet)
|
||||
omit: true
|
||||
}
|
||||
|
||||
filter: {
|
||||
struct: {
|
||||
alteration_id: {goType: "[]uint64", ident: "alterationID" }
|
||||
batch_id: {goType: "[]uint64", ident: "batchID" }
|
||||
kind: {}
|
||||
deleted: {goType: "filter.State", storeIdent: "deleted_at"}
|
||||
completed: {goType: "filter.State", storeIdent: "completed_at"}
|
||||
}
|
||||
|
||||
byValue: ["kind", "alteration_id"]
|
||||
byNilState: ["deleted"]
|
||||
}
|
||||
|
||||
store: {
|
||||
api: {
|
||||
lookups: [
|
||||
{
|
||||
fields: ["id"]
|
||||
description: """
|
||||
searches for resource translation by ID
|
||||
It also returns deleted resource translations.
|
||||
"""
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+1
@@ -71,6 +71,7 @@ func (e StoreEncoder) Prepare(ctx context.Context, p envoyx.EncodeParams, rt str
|
||||
return e.prepareDalConnection(ctx, p, s, nn)
|
||||
case types.DalSensitivityLevelResourceType:
|
||||
return e.prepareDalSensitivityLevel(ctx, p, s, nn)
|
||||
|
||||
default:
|
||||
return e.prepare(ctx, p, s, rt, nn)
|
||||
}
|
||||
|
||||
Generated
+1
@@ -160,6 +160,7 @@ func (e YamlEncoder) Encode(ctx context.Context, p envoyx.EncodeParams, rt strin
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
default:
|
||||
out, err = e.encode(ctx, out, p, rt, nodes, tt)
|
||||
if err != nil {
|
||||
|
||||
Generated
+154
@@ -1117,6 +1117,159 @@ var DalConnection = &dal.Model{
|
||||
},
|
||||
}
|
||||
|
||||
var DalSchemaAlteration = &dal.Model{
|
||||
Ident: "dal_schema_alterations",
|
||||
ResourceType: types.DalSchemaAlterationResourceType,
|
||||
|
||||
Attributes: dal.AttributeSet{
|
||||
&dal.Attribute{
|
||||
Ident: "ID",
|
||||
Type: &dal.TypeID{},
|
||||
Store: &dal.CodecAlias{Ident: "id"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "BatchID",
|
||||
Type: &dal.TypeID{},
|
||||
Store: &dal.CodecAlias{Ident: "batchID"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "DependsOn",
|
||||
Type: &dal.TypeRef{
|
||||
RefAttribute: "id",
|
||||
RefModel: &dal.ModelRef{
|
||||
ResourceType: "corteza::system:dal-schema-alteration",
|
||||
},
|
||||
},
|
||||
Store: &dal.CodecAlias{Ident: "dependsOn"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "Kind",
|
||||
Type: &dal.TypeText{Length: 256},
|
||||
Store: &dal.CodecAlias{Ident: "kind"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "Params",
|
||||
Type: &dal.TypeJSON{
|
||||
DefaultValue: "{}",
|
||||
},
|
||||
Store: &dal.CodecAlias{Ident: "params"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "CreatedAt", Sortable: true,
|
||||
Type: &dal.TypeTimestamp{
|
||||
DefaultCurrentTimestamp: true, Timezone: true, Precision: -1,
|
||||
},
|
||||
Store: &dal.CodecAlias{Ident: "created_at"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "UpdatedAt", Sortable: true,
|
||||
Type: &dal.TypeTimestamp{Nullable: true, Timezone: true, Precision: -1},
|
||||
Store: &dal.CodecAlias{Ident: "updated_at"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "DeletedAt", Sortable: true,
|
||||
Type: &dal.TypeTimestamp{Nullable: true, Timezone: true, Precision: -1},
|
||||
Store: &dal.CodecAlias{Ident: "deleted_at"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "CompletedAt", Sortable: true,
|
||||
Type: &dal.TypeTimestamp{Nullable: true, Timezone: true, Precision: -1},
|
||||
Store: &dal.CodecAlias{Ident: "completed_at"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "CreatedBy",
|
||||
Type: &dal.TypeRef{HasDefault: true,
|
||||
DefaultValue: 0,
|
||||
|
||||
RefAttribute: "id",
|
||||
RefModel: &dal.ModelRef{
|
||||
ResourceType: "corteza::system:user",
|
||||
},
|
||||
},
|
||||
Store: &dal.CodecAlias{Ident: "created_by"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "UpdatedBy",
|
||||
Type: &dal.TypeRef{HasDefault: true,
|
||||
DefaultValue: 0,
|
||||
|
||||
RefAttribute: "id",
|
||||
RefModel: &dal.ModelRef{
|
||||
ResourceType: "corteza::system:user",
|
||||
},
|
||||
},
|
||||
Store: &dal.CodecAlias{Ident: "updated_by"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "DeletedBy",
|
||||
Type: &dal.TypeRef{HasDefault: true,
|
||||
DefaultValue: 0,
|
||||
|
||||
RefAttribute: "id",
|
||||
RefModel: &dal.ModelRef{
|
||||
ResourceType: "corteza::system:user",
|
||||
},
|
||||
},
|
||||
Store: &dal.CodecAlias{Ident: "deleted_by"},
|
||||
},
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "CompletedBy",
|
||||
Type: &dal.TypeRef{HasDefault: true,
|
||||
DefaultValue: 0,
|
||||
|
||||
RefAttribute: "id",
|
||||
RefModel: &dal.ModelRef{
|
||||
ResourceType: "corteza::system:user",
|
||||
},
|
||||
},
|
||||
Store: &dal.CodecAlias{Ident: "completed_by"},
|
||||
},
|
||||
},
|
||||
|
||||
Indexes: dal.IndexSet{
|
||||
&dal.Index{
|
||||
Ident: "PRIMARY",
|
||||
Type: "BTREE",
|
||||
|
||||
Fields: []*dal.IndexField{
|
||||
{
|
||||
AttributeIdent: "ID",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
&dal.Index{
|
||||
Ident: "dal_schema_alterations_uniqueAlteration",
|
||||
Type: "BTREE",
|
||||
Unique: true,
|
||||
|
||||
Fields: []*dal.IndexField{
|
||||
{
|
||||
AttributeIdent: "ID",
|
||||
Modifiers: []dal.IndexFieldModifier{"LOWERCASE"},
|
||||
},
|
||||
|
||||
{
|
||||
AttributeIdent: "BatchID",
|
||||
Modifiers: []dal.IndexFieldModifier{"LOWERCASE"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var DalSensitivityLevel = &dal.Model{
|
||||
Ident: "dal_sensitivity_levels",
|
||||
ResourceType: types.DalSensitivityLevelResourceType,
|
||||
@@ -2493,6 +2646,7 @@ func init() {
|
||||
AuthSession,
|
||||
Credential,
|
||||
DalConnection,
|
||||
DalSchemaAlteration,
|
||||
DalSensitivityLevel,
|
||||
DataPrivacyRequest,
|
||||
DataPrivacyRequestComment,
|
||||
|
||||
@@ -914,6 +914,65 @@ endpoints:
|
||||
required: true
|
||||
title: Connection ID
|
||||
|
||||
- title: Data access layer schema alterations
|
||||
path: "/dal/schema/alterations"
|
||||
entrypoint: dalSchemaAlteration
|
||||
authentication:
|
||||
- Client ID
|
||||
- Session ID
|
||||
imports:
|
||||
apis:
|
||||
- name: list
|
||||
method: GET
|
||||
title: Search schema alterations
|
||||
path: "/"
|
||||
parameters:
|
||||
get:
|
||||
- name: alterationID
|
||||
type: "[]string"
|
||||
title: Filter by alteration ID
|
||||
- name: batchID
|
||||
type: "uint64"
|
||||
title: Filter by batch ID
|
||||
- type: string
|
||||
name: kind
|
||||
title: Search by kind
|
||||
- name: deleted
|
||||
title: Exclude (0, default), include (1) or return only (2) deleted alterations
|
||||
type: uint
|
||||
- name: completed
|
||||
title: Exclude (0, default), include (1) or return only (2) completed alterations
|
||||
type: uint
|
||||
- type: bool
|
||||
name: incTotal
|
||||
title: Include total counter
|
||||
|
||||
# We'll drop these two because they don't make sense to be here
|
||||
# - name: create
|
||||
# method: POST
|
||||
|
||||
# - name: update
|
||||
# method: PUT
|
||||
|
||||
- name: read
|
||||
method: GET
|
||||
title: Read alteration details
|
||||
path: "/{alterationID}"
|
||||
parameters:
|
||||
path: [ { type: uint64, name: alterationID, required: true, title: "Alteration ID" } ]
|
||||
- name: delete
|
||||
method: DELETE
|
||||
title: Remove alteration
|
||||
path: "/{alterationID}"
|
||||
parameters:
|
||||
path: [ { type: uint64, name: alterationID, required: true, title: "Alteration ID" } ]
|
||||
- name: undelete
|
||||
method: POST
|
||||
title: Undelete alteration
|
||||
path: "/{alterationID}/undelete"
|
||||
parameters:
|
||||
path: [ { type: uint64, name: alterationID, required: true, title: "Alteration ID" } ]
|
||||
|
||||
|
||||
- title: Data access layer connections
|
||||
path: "/dal/connections"
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/api"
|
||||
"github.com/cortezaproject/corteza/server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
DalSchemaAlteration struct {
|
||||
svc alterationService
|
||||
federationSvc federationNodeService
|
||||
|
||||
alterationAc alterationAccessController
|
||||
}
|
||||
|
||||
alterationPayload struct {
|
||||
*types.DalSchemaAlteration
|
||||
|
||||
CanGrant bool `json:"canGrant"`
|
||||
CanUpdateSchemaAlteration bool `json:"canUpdateSchemaAlteration"`
|
||||
CanDeleteSchemaAlteration bool `json:"canDeleteSchemaAlteration"`
|
||||
CanManageDalConfig bool `json:"canManageDalConfig"`
|
||||
}
|
||||
|
||||
alterationSetPayload struct {
|
||||
Filter types.DalSchemaAlterationFilter `json:"filter"`
|
||||
Set []*alterationPayload `json:"set"`
|
||||
}
|
||||
|
||||
alterationAccessController interface {
|
||||
CanGrant(context.Context) bool
|
||||
// @todo?
|
||||
}
|
||||
|
||||
alterationService interface {
|
||||
Search(ctx context.Context, filter types.DalSchemaAlterationFilter) (types.DalSchemaAlterationSet, types.DalSchemaAlterationFilter, error)
|
||||
FindByID(ctx context.Context, ID uint64) (*types.DalSchemaAlteration, error)
|
||||
DeleteByID(ctx context.Context, ID uint64) error
|
||||
UndeleteByID(ctx context.Context, ID uint64) error
|
||||
}
|
||||
)
|
||||
|
||||
func (DalSchemaAlteration) New() *DalSchemaAlteration {
|
||||
return &DalSchemaAlteration{
|
||||
svc: service.DefaultDalSchemaAlteration,
|
||||
|
||||
alterationAc: service.DefaultAccessControl,
|
||||
}
|
||||
}
|
||||
|
||||
func (ctrl DalSchemaAlteration) List(ctx context.Context, r *request.DalSchemaAlterationList) (interface{}, error) {
|
||||
var (
|
||||
err error
|
||||
set types.DalSchemaAlterationSet
|
||||
|
||||
f = types.DalSchemaAlterationFilter{
|
||||
AlterationID: r.AlterationID,
|
||||
BatchID: r.BatchID,
|
||||
Kind: r.Kind,
|
||||
|
||||
Deleted: filter.State(r.Deleted),
|
||||
Completed: filter.State(r.Completed),
|
||||
}
|
||||
)
|
||||
|
||||
if f.Deleted == 0 {
|
||||
f.Deleted = filter.StateExcluded
|
||||
}
|
||||
if f.Completed == 0 {
|
||||
f.Completed = filter.StateExcluded
|
||||
}
|
||||
|
||||
f.IncTotal = r.IncTotal
|
||||
|
||||
set, f, err = ctrl.svc.Search(ctx, f)
|
||||
return ctrl.makeFilterPayload(ctx, set, f, err)
|
||||
}
|
||||
|
||||
func (ctrl DalSchemaAlteration) Read(ctx context.Context, r *request.DalSchemaAlterationRead) (interface{}, error) {
|
||||
res, err := ctrl.svc.FindByID(ctx, r.AlterationID)
|
||||
return ctrl.makePayload(ctx, res, err)
|
||||
}
|
||||
|
||||
func (ctrl DalSchemaAlteration) Delete(ctx context.Context, r *request.DalSchemaAlterationDelete) (interface{}, error) {
|
||||
return api.OK(), ctrl.svc.DeleteByID(ctx, r.AlterationID)
|
||||
}
|
||||
|
||||
func (ctrl DalSchemaAlteration) Undelete(ctx context.Context, r *request.DalSchemaAlterationUndelete) (interface{}, error) {
|
||||
return api.OK(), ctrl.svc.UndeleteByID(ctx, r.AlterationID)
|
||||
}
|
||||
|
||||
func (ctrl DalSchemaAlteration) makePayload(ctx context.Context, res *types.DalSchemaAlteration, err error) (*alterationPayload, error) {
|
||||
if err != nil || res == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pl := &alterationPayload{
|
||||
DalSchemaAlteration: res,
|
||||
|
||||
CanGrant: ctrl.alterationAc.CanGrant(ctx),
|
||||
}
|
||||
|
||||
return pl, nil
|
||||
}
|
||||
|
||||
func (ctrl DalSchemaAlteration) makeFilterPayload(ctx context.Context, rr types.DalSchemaAlterationSet, f types.DalSchemaAlterationFilter, err error) (*alterationSetPayload, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := &alterationSetPayload{Filter: f, Set: make([]*alterationPayload, len(rr))}
|
||||
for i := range rr {
|
||||
out.Set[i], _ = ctrl.makePayload(ctx, rr[i], nil)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package handlers
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
//
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/cortezaproject/corteza/server/pkg/api"
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type (
|
||||
// Internal API interface
|
||||
DalSchemaAlterationAPI interface {
|
||||
List(context.Context, *request.DalSchemaAlterationList) (interface{}, error)
|
||||
Read(context.Context, *request.DalSchemaAlterationRead) (interface{}, error)
|
||||
Delete(context.Context, *request.DalSchemaAlterationDelete) (interface{}, error)
|
||||
Undelete(context.Context, *request.DalSchemaAlterationUndelete) (interface{}, error)
|
||||
}
|
||||
|
||||
// HTTP API interface
|
||||
DalSchemaAlteration struct {
|
||||
List func(http.ResponseWriter, *http.Request)
|
||||
Read func(http.ResponseWriter, *http.Request)
|
||||
Delete func(http.ResponseWriter, *http.Request)
|
||||
Undelete func(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
)
|
||||
|
||||
func NewDalSchemaAlteration(h DalSchemaAlterationAPI) *DalSchemaAlteration {
|
||||
return &DalSchemaAlteration{
|
||||
List: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewDalSchemaAlterationList()
|
||||
if err := params.Fill(r); err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
value, err := h.List(r.Context(), params)
|
||||
if err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
api.Send(w, r, value)
|
||||
},
|
||||
Read: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewDalSchemaAlterationRead()
|
||||
if err := params.Fill(r); err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
value, err := h.Read(r.Context(), params)
|
||||
if err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
api.Send(w, r, value)
|
||||
},
|
||||
Delete: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewDalSchemaAlterationDelete()
|
||||
if err := params.Fill(r); err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
value, err := h.Delete(r.Context(), params)
|
||||
if err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
api.Send(w, r, value)
|
||||
},
|
||||
Undelete: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewDalSchemaAlterationUndelete()
|
||||
if err := params.Fill(r); err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
value, err := h.Undelete(r.Context(), params)
|
||||
if err != nil {
|
||||
api.Send(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
api.Send(w, r, value)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (h DalSchemaAlteration) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(middlewares...)
|
||||
r.Get("/dal/schema/alterations/", h.List)
|
||||
r.Get("/dal/schema/alterations/{alterationID}", h.Read)
|
||||
r.Delete("/dal/schema/alterations/{alterationID}", h.Delete)
|
||||
r.Post("/dal/schema/alterations/{alterationID}/undelete", h.Undelete)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
package request
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
//
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza/server/pkg/payload"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// dummy vars to prevent
|
||||
// unused imports complain
|
||||
var (
|
||||
_ = chi.URLParam
|
||||
_ = multipart.ErrMessageTooLarge
|
||||
_ = payload.ParseUint64s
|
||||
_ = strings.ToLower
|
||||
_ = io.EOF
|
||||
_ = fmt.Errorf
|
||||
_ = json.NewEncoder
|
||||
)
|
||||
|
||||
type (
|
||||
// Internal API interface
|
||||
DalSchemaAlterationList struct {
|
||||
// AlterationID GET parameter
|
||||
//
|
||||
// Filter by alteration ID
|
||||
AlterationID []string
|
||||
|
||||
// BatchID GET parameter
|
||||
//
|
||||
// Filter by batch ID
|
||||
BatchID uint64 `json:",string"`
|
||||
|
||||
// Kind GET parameter
|
||||
//
|
||||
// Search by kind
|
||||
Kind string
|
||||
|
||||
// Deleted GET parameter
|
||||
//
|
||||
// Exclude (0, default), include (1) or return only (2) deleted alterations
|
||||
Deleted uint
|
||||
|
||||
// Completed GET parameter
|
||||
//
|
||||
// Exclude (0, default), include (1) or return only (2) completed alterations
|
||||
Completed uint
|
||||
|
||||
// IncTotal GET parameter
|
||||
//
|
||||
// Include total counter
|
||||
IncTotal bool
|
||||
}
|
||||
|
||||
DalSchemaAlterationRead struct {
|
||||
// AlterationID PATH parameter
|
||||
//
|
||||
// Alteration ID
|
||||
AlterationID uint64 `json:",string"`
|
||||
}
|
||||
|
||||
DalSchemaAlterationDelete struct {
|
||||
// AlterationID PATH parameter
|
||||
//
|
||||
// Alteration ID
|
||||
AlterationID uint64 `json:",string"`
|
||||
}
|
||||
|
||||
DalSchemaAlterationUndelete struct {
|
||||
// AlterationID PATH parameter
|
||||
//
|
||||
// Alteration ID
|
||||
AlterationID uint64 `json:",string"`
|
||||
}
|
||||
)
|
||||
|
||||
// NewDalSchemaAlterationList request
|
||||
func NewDalSchemaAlterationList() *DalSchemaAlterationList {
|
||||
return &DalSchemaAlterationList{}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationList) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"alterationID": r.AlterationID,
|
||||
"batchID": r.BatchID,
|
||||
"kind": r.Kind,
|
||||
"deleted": r.Deleted,
|
||||
"completed": r.Completed,
|
||||
"incTotal": r.IncTotal,
|
||||
}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationList) GetAlterationID() []string {
|
||||
return r.AlterationID
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationList) GetBatchID() uint64 {
|
||||
return r.BatchID
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationList) GetKind() string {
|
||||
return r.Kind
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationList) GetDeleted() uint {
|
||||
return r.Deleted
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationList) GetCompleted() uint {
|
||||
return r.Completed
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationList) GetIncTotal() bool {
|
||||
return r.IncTotal
|
||||
}
|
||||
|
||||
// Fill processes request and fills internal variables
|
||||
func (r *DalSchemaAlterationList) Fill(req *http.Request) (err error) {
|
||||
|
||||
{
|
||||
// GET params
|
||||
tmp := req.URL.Query()
|
||||
|
||||
if val, ok := tmp["alterationID[]"]; ok {
|
||||
r.AlterationID, err = val, nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if val, ok := tmp["alterationID"]; ok {
|
||||
r.AlterationID, err = val, nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["batchID"]; ok && len(val) > 0 {
|
||||
r.BatchID, err = payload.ParseUint64(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["kind"]; ok && len(val) > 0 {
|
||||
r.Kind, err = val[0], nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["deleted"]; ok && len(val) > 0 {
|
||||
r.Deleted, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["completed"]; ok && len(val) > 0 {
|
||||
r.Completed, err = payload.ParseUint(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["incTotal"]; ok && len(val) > 0 {
|
||||
r.IncTotal, err = payload.ParseBool(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// NewDalSchemaAlterationRead request
|
||||
func NewDalSchemaAlterationRead() *DalSchemaAlterationRead {
|
||||
return &DalSchemaAlterationRead{}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationRead) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"alterationID": r.AlterationID,
|
||||
}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationRead) GetAlterationID() uint64 {
|
||||
return r.AlterationID
|
||||
}
|
||||
|
||||
// Fill processes request and fills internal variables
|
||||
func (r *DalSchemaAlterationRead) Fill(req *http.Request) (err error) {
|
||||
|
||||
{
|
||||
var val string
|
||||
// path params
|
||||
|
||||
val = chi.URLParam(req, "alterationID")
|
||||
r.AlterationID, err = payload.ParseUint64(val), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// NewDalSchemaAlterationDelete request
|
||||
func NewDalSchemaAlterationDelete() *DalSchemaAlterationDelete {
|
||||
return &DalSchemaAlterationDelete{}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationDelete) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"alterationID": r.AlterationID,
|
||||
}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationDelete) GetAlterationID() uint64 {
|
||||
return r.AlterationID
|
||||
}
|
||||
|
||||
// Fill processes request and fills internal variables
|
||||
func (r *DalSchemaAlterationDelete) Fill(req *http.Request) (err error) {
|
||||
|
||||
{
|
||||
var val string
|
||||
// path params
|
||||
|
||||
val = chi.URLParam(req, "alterationID")
|
||||
r.AlterationID, err = payload.ParseUint64(val), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// NewDalSchemaAlterationUndelete request
|
||||
func NewDalSchemaAlterationUndelete() *DalSchemaAlterationUndelete {
|
||||
return &DalSchemaAlterationUndelete{}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationUndelete) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"alterationID": r.AlterationID,
|
||||
}
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r DalSchemaAlterationUndelete) GetAlterationID() uint64 {
|
||||
return r.AlterationID
|
||||
}
|
||||
|
||||
// Fill processes request and fills internal variables
|
||||
func (r *DalSchemaAlterationUndelete) Fill(req *http.Request) (err error) {
|
||||
|
||||
{
|
||||
var val string
|
||||
// path params
|
||||
|
||||
val = chi.URLParam(req, "alterationID")
|
||||
r.AlterationID, err = payload.ParseUint64(val), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/actionlog"
|
||||
"github.com/cortezaproject/corteza/server/pkg/errors"
|
||||
"github.com/cortezaproject/corteza/server/store"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
dalSchemaAlteration struct {
|
||||
actionlog actionlog.Recorder
|
||||
ac dalSchemaAlterationAccessController
|
||||
|
||||
store store.Storer
|
||||
}
|
||||
|
||||
dalSchemaAlterationAccessController interface {
|
||||
}
|
||||
)
|
||||
|
||||
func DalSchemaAlteration() *dalSchemaAlteration {
|
||||
return &dalSchemaAlteration{
|
||||
ac: DefaultAccessControl,
|
||||
store: DefaultStore,
|
||||
actionlog: DefaultActionlog,
|
||||
}
|
||||
}
|
||||
|
||||
func (svc dalSchemaAlteration) FindByID(ctx context.Context, dalSchemaAlterationID uint64) (a *types.DalSchemaAlteration, err error) {
|
||||
var (
|
||||
uaProps = &dalSchemaAlterationActionProps{dalSchemaAlteration: &types.DalSchemaAlteration{ID: dalSchemaAlterationID}}
|
||||
)
|
||||
|
||||
err = func() error {
|
||||
a, err = loadDalSchemaAlteration(ctx, svc.store, dalSchemaAlterationID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
uaProps.setDalSchemaAlteration(a)
|
||||
|
||||
// if !svc.ac.CanReadDalSchemaAlteration(ctx, u) {
|
||||
// return DalSchemaAlterationErrNotAllowedToRead()
|
||||
// }
|
||||
|
||||
return nil
|
||||
}()
|
||||
|
||||
return a, svc.recordAction(ctx, uaProps, DalSchemaAlterationActionLookup, err)
|
||||
}
|
||||
|
||||
// Search interacts with backend storage and
|
||||
//
|
||||
// @todo rename to Search() for consistency
|
||||
func (svc dalSchemaAlteration) Search(ctx context.Context, filter types.DalSchemaAlterationFilter) (aa types.DalSchemaAlterationSet, f types.DalSchemaAlterationFilter, err error) {
|
||||
var (
|
||||
uaProps = &dalSchemaAlterationActionProps{filter: &filter}
|
||||
)
|
||||
|
||||
// For each fetched item, store backend will check if it is valid or not
|
||||
// if !svc.ac.CanReadDalSchemaAlteration(ctx, res) {
|
||||
// return false, nil
|
||||
// }
|
||||
|
||||
// return true, nil
|
||||
// }
|
||||
|
||||
err = func() error {
|
||||
// if !svc.ac.CanSearchDalSchemaAlterations(ctx) {
|
||||
// return DalSchemaAlterationErrNotAllowedToSearch()
|
||||
// }
|
||||
|
||||
aa, f, err = store.SearchDalSchemaAlterations(ctx, svc.store, filter)
|
||||
return err
|
||||
}()
|
||||
|
||||
return aa, f, svc.recordAction(ctx, uaProps, DalSchemaAlterationActionSearch, err)
|
||||
}
|
||||
|
||||
func (svc dalSchemaAlteration) DeleteByID(ctx context.Context, dalSchemaAlterationID uint64) (err error) {
|
||||
var (
|
||||
u *types.DalSchemaAlteration
|
||||
uaProps = &dalSchemaAlterationActionProps{dalSchemaAlteration: &types.DalSchemaAlteration{ID: dalSchemaAlterationID}}
|
||||
)
|
||||
|
||||
err = func() (err error) {
|
||||
if u, err = loadDalSchemaAlteration(ctx, svc.store, dalSchemaAlterationID); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// if !svc.ac.CanDeleteDalSchemaAlteration(ctx, u) {
|
||||
// return DalSchemaAlterationErrNotAllowedToDelete()
|
||||
// }
|
||||
|
||||
// if err = svc.eventbus.WaitFor(ctx, event.DalSchemaAlterationBeforeDelete(nil, u)); err != nil {
|
||||
// return
|
||||
// }
|
||||
|
||||
u.DeletedAt = now()
|
||||
if err = store.UpdateDalSchemaAlteration(ctx, svc.store, u); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// _ = svc.eventbus.WaitFor(ctx, event.DalSchemaAlterationAfterDelete(nil, u))
|
||||
return nil
|
||||
}()
|
||||
|
||||
return svc.recordAction(ctx, uaProps, DalSchemaAlterationActionDelete, err)
|
||||
}
|
||||
|
||||
func (svc dalSchemaAlteration) UndeleteByID(ctx context.Context, dalSchemaAlterationID uint64) (err error) {
|
||||
var (
|
||||
u *types.DalSchemaAlteration
|
||||
uaProps = &dalSchemaAlterationActionProps{dalSchemaAlteration: &types.DalSchemaAlteration{ID: dalSchemaAlterationID}}
|
||||
)
|
||||
|
||||
err = func() (err error) {
|
||||
if u, err = loadDalSchemaAlteration(ctx, svc.store, dalSchemaAlterationID); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
uaProps.setDalSchemaAlteration(u)
|
||||
|
||||
// if err = uniqueDalSchemaAlterationCheck(ctx, svc.store, u); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if !svc.ac.CanDeleteDalSchemaAlteration(ctx, u) {
|
||||
// return DalSchemaAlterationErrNotAllowedToDelete()
|
||||
// }
|
||||
|
||||
u.DeletedAt = nil
|
||||
if err = store.UpdateDalSchemaAlteration(ctx, svc.store, u); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return nil
|
||||
}()
|
||||
|
||||
return svc.recordAction(ctx, uaProps, DalSchemaAlterationActionUndelete, err)
|
||||
|
||||
}
|
||||
|
||||
func loadDalSchemaAlteration(ctx context.Context, s store.DalSchemaAlterations, ID uint64) (res *types.DalSchemaAlteration, err error) {
|
||||
if ID == 0 {
|
||||
return nil, DalSchemaAlterationErrInvalidID()
|
||||
}
|
||||
|
||||
if res, err = store.LookupDalSchemaAlterationByID(ctx, s, ID); errors.IsNotFound(err) {
|
||||
return nil, DalSchemaAlterationErrNotFound()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// // uniqueDalSchemaAlterationCheck verifies dalSchemaAlteration's email, dalSchemaAlterationname and handle
|
||||
// func uniqueDalSchemaAlterationCheck(ctx context.Context, s store.Storer, u *types.DalSchemaAlteration) (err error) {
|
||||
// isUnique := func(field string) bool {
|
||||
// f := types.DalSchemaAlterationFilter{
|
||||
// // If dalSchemaAlteration exists and is deleted -- not a dup
|
||||
// Deleted: filter.StateExcluded,
|
||||
|
||||
// // If dalSchemaAlteration exists and is suspended -- duplicate
|
||||
// Suspended: filter.StateInclusive,
|
||||
// }
|
||||
|
||||
// f.Limit = 1
|
||||
|
||||
// switch field {
|
||||
// case "email":
|
||||
// if u.Email == "" {
|
||||
// return true
|
||||
// }
|
||||
|
||||
// f.Email = u.Email
|
||||
|
||||
// case "dalSchemaAlterationname":
|
||||
// if u.DalSchemaAlterationname == "" {
|
||||
// return true
|
||||
// }
|
||||
|
||||
// f.DalSchemaAlterationname = u.DalSchemaAlterationname
|
||||
// case "handle":
|
||||
// if u.Handle == "" {
|
||||
// return true
|
||||
// }
|
||||
|
||||
// f.Handle = u.Handle
|
||||
// }
|
||||
|
||||
// set, _, err := store.SearchDalSchemaAlterations(ctx, s, f)
|
||||
// if err != nil || len(set) > 1 {
|
||||
// // In case of error or multiple dalSchemaAlterations returned
|
||||
// return false
|
||||
// }
|
||||
|
||||
// return len(set) == 0 || set[0].ID == u.ID
|
||||
// }
|
||||
|
||||
// if !isUnique("email") {
|
||||
// return DalSchemaAlterationErrEmailNotUnique()
|
||||
// }
|
||||
|
||||
// if !isUnique("dalSchemaAlterationname") {
|
||||
// return DalSchemaAlterationErrDalSchemaAlterationnameNotUnique()
|
||||
// }
|
||||
|
||||
// if !isUnique("handle") {
|
||||
// return DalSchemaAlterationErrHandleNotUnique()
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// }
|
||||
@@ -0,0 +1,671 @@
|
||||
package service
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// system/service/dal_schema_alteration_actions.yaml
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza/server/pkg/actionlog"
|
||||
"github.com/cortezaproject/corteza/server/pkg/errors"
|
||||
"github.com/cortezaproject/corteza/server/pkg/locale"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
dalSchemaAlterationActionProps struct {
|
||||
dalSchemaAlteration *types.DalSchemaAlteration
|
||||
new *types.DalSchemaAlteration
|
||||
update *types.DalSchemaAlteration
|
||||
existing *types.DalSchemaAlteration
|
||||
filter *types.DalSchemaAlterationFilter
|
||||
}
|
||||
|
||||
dalSchemaAlterationAction struct {
|
||||
timestamp time.Time
|
||||
resource string
|
||||
action string
|
||||
log string
|
||||
severity actionlog.Severity
|
||||
|
||||
// prefix for error when action fails
|
||||
errorMessage string
|
||||
|
||||
props *dalSchemaAlterationActionProps
|
||||
}
|
||||
|
||||
dalSchemaAlterationLogMetaKey struct{}
|
||||
dalSchemaAlterationPropsMetaKey struct{}
|
||||
)
|
||||
|
||||
var (
|
||||
// just a placeholder to cover template cases w/o fmt package use
|
||||
_ = fmt.Println
|
||||
)
|
||||
|
||||
// *********************************************************************************************************************
|
||||
// *********************************************************************************************************************
|
||||
// Props methods
|
||||
// setDalSchemaAlteration updates dalSchemaAlterationActionProps's dalSchemaAlteration
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func (p *dalSchemaAlterationActionProps) setDalSchemaAlteration(dalSchemaAlteration *types.DalSchemaAlteration) *dalSchemaAlterationActionProps {
|
||||
p.dalSchemaAlteration = dalSchemaAlteration
|
||||
return p
|
||||
}
|
||||
|
||||
// setNew updates dalSchemaAlterationActionProps's new
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func (p *dalSchemaAlterationActionProps) setNew(new *types.DalSchemaAlteration) *dalSchemaAlterationActionProps {
|
||||
p.new = new
|
||||
return p
|
||||
}
|
||||
|
||||
// setUpdate updates dalSchemaAlterationActionProps's update
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func (p *dalSchemaAlterationActionProps) setUpdate(update *types.DalSchemaAlteration) *dalSchemaAlterationActionProps {
|
||||
p.update = update
|
||||
return p
|
||||
}
|
||||
|
||||
// setExisting updates dalSchemaAlterationActionProps's existing
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func (p *dalSchemaAlterationActionProps) setExisting(existing *types.DalSchemaAlteration) *dalSchemaAlterationActionProps {
|
||||
p.existing = existing
|
||||
return p
|
||||
}
|
||||
|
||||
// setFilter updates dalSchemaAlterationActionProps's filter
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func (p *dalSchemaAlterationActionProps) setFilter(filter *types.DalSchemaAlterationFilter) *dalSchemaAlterationActionProps {
|
||||
p.filter = filter
|
||||
return p
|
||||
}
|
||||
|
||||
// Serialize converts dalSchemaAlterationActionProps to actionlog.Meta
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func (p dalSchemaAlterationActionProps) Serialize() actionlog.Meta {
|
||||
var (
|
||||
m = make(actionlog.Meta)
|
||||
)
|
||||
|
||||
if p.dalSchemaAlteration != nil {
|
||||
m.Set("dalSchemaAlteration.ID", p.dalSchemaAlteration.ID, true)
|
||||
}
|
||||
if p.new != nil {
|
||||
m.Set("new.ID", p.new.ID, true)
|
||||
}
|
||||
if p.update != nil {
|
||||
m.Set("update.ID", p.update.ID, true)
|
||||
}
|
||||
if p.existing != nil {
|
||||
m.Set("existing.ID", p.existing.ID, true)
|
||||
}
|
||||
if p.filter != nil {
|
||||
m.Set("filter.alterationID", p.filter.AlterationID, true)
|
||||
m.Set("filter.batchID", p.filter.BatchID, true)
|
||||
m.Set("filter.kind", p.filter.Kind, true)
|
||||
m.Set("filter.deleted", p.filter.Deleted, true)
|
||||
m.Set("filter.completed", p.filter.Completed, true)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// tr translates string and replaces meta value placeholder with values
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func (p dalSchemaAlterationActionProps) Format(in string, err error) string {
|
||||
var (
|
||||
pairs = []string{"{{err}}"}
|
||||
// first non-empty string
|
||||
fns = func(ii ...interface{}) string {
|
||||
for _, i := range ii {
|
||||
if s := fmt.Sprintf("%v", i); len(s) > 0 {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
pairs = append(pairs, err.Error())
|
||||
} else {
|
||||
pairs = append(pairs, "nil")
|
||||
}
|
||||
|
||||
if p.dalSchemaAlteration != nil {
|
||||
// replacement for "{{dalSchemaAlteration}}" (in order how fields are defined)
|
||||
pairs = append(
|
||||
pairs,
|
||||
"{{dalSchemaAlteration}}",
|
||||
fns(
|
||||
p.dalSchemaAlteration.ID,
|
||||
),
|
||||
)
|
||||
pairs = append(pairs, "{{dalSchemaAlteration.ID}}", fns(p.dalSchemaAlteration.ID))
|
||||
}
|
||||
|
||||
if p.new != nil {
|
||||
// replacement for "{{new}}" (in order how fields are defined)
|
||||
pairs = append(
|
||||
pairs,
|
||||
"{{new}}",
|
||||
fns(
|
||||
p.new.ID,
|
||||
),
|
||||
)
|
||||
pairs = append(pairs, "{{new.ID}}", fns(p.new.ID))
|
||||
}
|
||||
|
||||
if p.update != nil {
|
||||
// replacement for "{{update}}" (in order how fields are defined)
|
||||
pairs = append(
|
||||
pairs,
|
||||
"{{update}}",
|
||||
fns(
|
||||
p.update.ID,
|
||||
),
|
||||
)
|
||||
pairs = append(pairs, "{{update.ID}}", fns(p.update.ID))
|
||||
}
|
||||
|
||||
if p.existing != nil {
|
||||
// replacement for "{{existing}}" (in order how fields are defined)
|
||||
pairs = append(
|
||||
pairs,
|
||||
"{{existing}}",
|
||||
fns(
|
||||
p.existing.ID,
|
||||
),
|
||||
)
|
||||
pairs = append(pairs, "{{existing.ID}}", fns(p.existing.ID))
|
||||
}
|
||||
|
||||
if p.filter != nil {
|
||||
// replacement for "{{filter}}" (in order how fields are defined)
|
||||
pairs = append(
|
||||
pairs,
|
||||
"{{filter}}",
|
||||
fns(
|
||||
p.filter.AlterationID,
|
||||
p.filter.BatchID,
|
||||
p.filter.Kind,
|
||||
p.filter.Deleted,
|
||||
p.filter.Completed,
|
||||
),
|
||||
)
|
||||
pairs = append(pairs, "{{filter.alterationID}}", fns(p.filter.AlterationID))
|
||||
pairs = append(pairs, "{{filter.batchID}}", fns(p.filter.BatchID))
|
||||
pairs = append(pairs, "{{filter.kind}}", fns(p.filter.Kind))
|
||||
pairs = append(pairs, "{{filter.deleted}}", fns(p.filter.Deleted))
|
||||
pairs = append(pairs, "{{filter.completed}}", fns(p.filter.Completed))
|
||||
}
|
||||
return strings.NewReplacer(pairs...).Replace(in)
|
||||
}
|
||||
|
||||
// *********************************************************************************************************************
|
||||
// *********************************************************************************************************************
|
||||
// Action methods
|
||||
|
||||
// String returns loggable description as string
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func (a *dalSchemaAlterationAction) String() string {
|
||||
var props = &dalSchemaAlterationActionProps{}
|
||||
|
||||
if a.props != nil {
|
||||
props = a.props
|
||||
}
|
||||
|
||||
return props.Format(a.log, nil)
|
||||
}
|
||||
|
||||
func (e *dalSchemaAlterationAction) ToAction() *actionlog.Action {
|
||||
return &actionlog.Action{
|
||||
Resource: e.resource,
|
||||
Action: e.action,
|
||||
Severity: e.severity,
|
||||
Description: e.String(),
|
||||
Meta: e.props.Serialize(),
|
||||
}
|
||||
}
|
||||
|
||||
// *********************************************************************************************************************
|
||||
// *********************************************************************************************************************
|
||||
// Action constructors
|
||||
|
||||
// DalSchemaAlterationActionSearch returns "system:dal-schema-alteration.search" action
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationActionSearch(props ...*dalSchemaAlterationActionProps) *dalSchemaAlterationAction {
|
||||
a := &dalSchemaAlterationAction{
|
||||
timestamp: time.Now(),
|
||||
resource: "system:dal-schema-alteration",
|
||||
action: "search",
|
||||
log: "searched for matching dalSchemaAlterations",
|
||||
severity: actionlog.Info,
|
||||
}
|
||||
|
||||
if len(props) > 0 {
|
||||
a.props = props[0]
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// DalSchemaAlterationActionLookup returns "system:dal-schema-alteration.lookup" action
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationActionLookup(props ...*dalSchemaAlterationActionProps) *dalSchemaAlterationAction {
|
||||
a := &dalSchemaAlterationAction{
|
||||
timestamp: time.Now(),
|
||||
resource: "system:dal-schema-alteration",
|
||||
action: "lookup",
|
||||
log: "looked-up for a {{dalSchemaAlteration}}",
|
||||
severity: actionlog.Info,
|
||||
}
|
||||
|
||||
if len(props) > 0 {
|
||||
a.props = props[0]
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// DalSchemaAlterationActionDelete returns "system:dal-schema-alteration.delete" action
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationActionDelete(props ...*dalSchemaAlterationActionProps) *dalSchemaAlterationAction {
|
||||
a := &dalSchemaAlterationAction{
|
||||
timestamp: time.Now(),
|
||||
resource: "system:dal-schema-alteration",
|
||||
action: "delete",
|
||||
log: "deleted {{dalSchemaAlteration}}",
|
||||
severity: actionlog.Notice,
|
||||
}
|
||||
|
||||
if len(props) > 0 {
|
||||
a.props = props[0]
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// DalSchemaAlterationActionUndelete returns "system:dal-schema-alteration.undelete" action
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationActionUndelete(props ...*dalSchemaAlterationActionProps) *dalSchemaAlterationAction {
|
||||
a := &dalSchemaAlterationAction{
|
||||
timestamp: time.Now(),
|
||||
resource: "system:dal-schema-alteration",
|
||||
action: "undelete",
|
||||
log: "undeleted {{dalSchemaAlteration}}",
|
||||
severity: actionlog.Notice,
|
||||
}
|
||||
|
||||
if len(props) > 0 {
|
||||
a.props = props[0]
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// *********************************************************************************************************************
|
||||
// *********************************************************************************************************************
|
||||
// Error constructors
|
||||
|
||||
// DalSchemaAlterationErrGeneric returns "system:dal-schema-alteration.generic" as *errors.Error
|
||||
//
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationErrGeneric(mm ...*dalSchemaAlterationActionProps) *errors.Error {
|
||||
var p = &dalSchemaAlterationActionProps{}
|
||||
if len(mm) > 0 {
|
||||
p = mm[0]
|
||||
}
|
||||
|
||||
var e = errors.New(
|
||||
errors.KindInternal,
|
||||
|
||||
p.Format("failed to complete request due to internal error", nil),
|
||||
|
||||
errors.Meta("type", "generic"),
|
||||
errors.Meta("resource", "system:dal-schema-alteration"),
|
||||
|
||||
// action log entry; no formatting, it will be applied inside recordAction fn.
|
||||
errors.Meta(dalSchemaAlterationLogMetaKey{}, "{err}"),
|
||||
errors.Meta(dalSchemaAlterationPropsMetaKey{}, p),
|
||||
|
||||
// translation namespace & key
|
||||
errors.Meta(locale.ErrorMetaNamespace{}, "system"),
|
||||
errors.Meta(locale.ErrorMetaKey{}, "dal-schema-alteration.errors.generic"),
|
||||
|
||||
errors.StackSkip(1),
|
||||
)
|
||||
|
||||
if len(mm) > 0 {
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// DalSchemaAlterationErrNotFound returns "system:dal-schema-alteration.notFound" as *errors.Error
|
||||
//
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationErrNotFound(mm ...*dalSchemaAlterationActionProps) *errors.Error {
|
||||
var p = &dalSchemaAlterationActionProps{}
|
||||
if len(mm) > 0 {
|
||||
p = mm[0]
|
||||
}
|
||||
|
||||
var e = errors.New(
|
||||
errors.KindInternal,
|
||||
|
||||
p.Format("dalSchemaAlteration not found", nil),
|
||||
|
||||
errors.Meta("type", "notFound"),
|
||||
errors.Meta("resource", "system:dal-schema-alteration"),
|
||||
|
||||
errors.Meta(dalSchemaAlterationPropsMetaKey{}, p),
|
||||
|
||||
// translation namespace & key
|
||||
errors.Meta(locale.ErrorMetaNamespace{}, "system"),
|
||||
errors.Meta(locale.ErrorMetaKey{}, "dal-schema-alteration.errors.notFound"),
|
||||
|
||||
errors.StackSkip(1),
|
||||
)
|
||||
|
||||
if len(mm) > 0 {
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// DalSchemaAlterationErrInvalidID returns "system:dal-schema-alteration.invalidID" as *errors.Error
|
||||
//
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationErrInvalidID(mm ...*dalSchemaAlterationActionProps) *errors.Error {
|
||||
var p = &dalSchemaAlterationActionProps{}
|
||||
if len(mm) > 0 {
|
||||
p = mm[0]
|
||||
}
|
||||
|
||||
var e = errors.New(
|
||||
errors.KindInternal,
|
||||
|
||||
p.Format("invalid ID", nil),
|
||||
|
||||
errors.Meta("type", "invalidID"),
|
||||
errors.Meta("resource", "system:dal-schema-alteration"),
|
||||
|
||||
errors.Meta(dalSchemaAlterationPropsMetaKey{}, p),
|
||||
|
||||
// translation namespace & key
|
||||
errors.Meta(locale.ErrorMetaNamespace{}, "system"),
|
||||
errors.Meta(locale.ErrorMetaKey{}, "dal-schema-alteration.errors.invalidID"),
|
||||
|
||||
errors.StackSkip(1),
|
||||
)
|
||||
|
||||
if len(mm) > 0 {
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// DalSchemaAlterationErrNotAllowedToRead returns "system:dal-schema-alteration.notAllowedToRead" as *errors.Error
|
||||
//
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationErrNotAllowedToRead(mm ...*dalSchemaAlterationActionProps) *errors.Error {
|
||||
var p = &dalSchemaAlterationActionProps{}
|
||||
if len(mm) > 0 {
|
||||
p = mm[0]
|
||||
}
|
||||
|
||||
var e = errors.New(
|
||||
errors.KindInternal,
|
||||
|
||||
p.Format("not allowed to read this dal schema alteration", nil),
|
||||
|
||||
errors.Meta("type", "notAllowedToRead"),
|
||||
errors.Meta("resource", "system:dal-schema-alteration"),
|
||||
|
||||
// action log entry; no formatting, it will be applied inside recordAction fn.
|
||||
errors.Meta(dalSchemaAlterationLogMetaKey{}, "failed to read {{dalSchemaAlteration.ID}}; insufficient permissions"),
|
||||
errors.Meta(dalSchemaAlterationPropsMetaKey{}, p),
|
||||
|
||||
// translation namespace & key
|
||||
errors.Meta(locale.ErrorMetaNamespace{}, "system"),
|
||||
errors.Meta(locale.ErrorMetaKey{}, "dal-schema-alteration.errors.notAllowedToRead"),
|
||||
|
||||
errors.StackSkip(1),
|
||||
)
|
||||
|
||||
if len(mm) > 0 {
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// DalSchemaAlterationErrNotAllowedToSearch returns "system:dal-schema-alteration.notAllowedToSearch" as *errors.Error
|
||||
//
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationErrNotAllowedToSearch(mm ...*dalSchemaAlterationActionProps) *errors.Error {
|
||||
var p = &dalSchemaAlterationActionProps{}
|
||||
if len(mm) > 0 {
|
||||
p = mm[0]
|
||||
}
|
||||
|
||||
var e = errors.New(
|
||||
errors.KindInternal,
|
||||
|
||||
p.Format("not allowed to list or search dal schema alterations", nil),
|
||||
|
||||
errors.Meta("type", "notAllowedToSearch"),
|
||||
errors.Meta("resource", "system:dal-schema-alteration"),
|
||||
|
||||
// action log entry; no formatting, it will be applied inside recordAction fn.
|
||||
errors.Meta(dalSchemaAlterationLogMetaKey{}, "failed to search for dal schema alterations; insufficient permissions"),
|
||||
errors.Meta(dalSchemaAlterationPropsMetaKey{}, p),
|
||||
|
||||
// translation namespace & key
|
||||
errors.Meta(locale.ErrorMetaNamespace{}, "system"),
|
||||
errors.Meta(locale.ErrorMetaKey{}, "dal-schema-alteration.errors.notAllowedToSearch"),
|
||||
|
||||
errors.StackSkip(1),
|
||||
)
|
||||
|
||||
if len(mm) > 0 {
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// DalSchemaAlterationErrNotAllowedToListUsers returns "system:dal-schema-alteration.notAllowedToListUsers" as *errors.Error
|
||||
//
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationErrNotAllowedToListUsers(mm ...*dalSchemaAlterationActionProps) *errors.Error {
|
||||
var p = &dalSchemaAlterationActionProps{}
|
||||
if len(mm) > 0 {
|
||||
p = mm[0]
|
||||
}
|
||||
|
||||
var e = errors.New(
|
||||
errors.KindInternal,
|
||||
|
||||
p.Format("not allowed to list dal schema alterations", nil),
|
||||
|
||||
errors.Meta("type", "notAllowedToListUsers"),
|
||||
errors.Meta("resource", "system:dal-schema-alteration"),
|
||||
|
||||
// action log entry; no formatting, it will be applied inside recordAction fn.
|
||||
errors.Meta(dalSchemaAlterationLogMetaKey{}, "failed to list dalSchemaAlteration; insufficient permissions"),
|
||||
errors.Meta(dalSchemaAlterationPropsMetaKey{}, p),
|
||||
|
||||
// translation namespace & key
|
||||
errors.Meta(locale.ErrorMetaNamespace{}, "system"),
|
||||
errors.Meta(locale.ErrorMetaKey{}, "dal-schema-alteration.errors.notAllowedToListUsers"),
|
||||
|
||||
errors.StackSkip(1),
|
||||
)
|
||||
|
||||
if len(mm) > 0 {
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// DalSchemaAlterationErrNotAllowedToDelete returns "system:dal-schema-alteration.notAllowedToDelete" as *errors.Error
|
||||
//
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationErrNotAllowedToDelete(mm ...*dalSchemaAlterationActionProps) *errors.Error {
|
||||
var p = &dalSchemaAlterationActionProps{}
|
||||
if len(mm) > 0 {
|
||||
p = mm[0]
|
||||
}
|
||||
|
||||
var e = errors.New(
|
||||
errors.KindInternal,
|
||||
|
||||
p.Format("not allowed to delete this dal schema alteration", nil),
|
||||
|
||||
errors.Meta("type", "notAllowedToDelete"),
|
||||
errors.Meta("resource", "system:dal-schema-alteration"),
|
||||
|
||||
// action log entry; no formatting, it will be applied inside recordAction fn.
|
||||
errors.Meta(dalSchemaAlterationLogMetaKey{}, "failed to delete {{dalSchemaAlteration.ID}}; insufficient permissions"),
|
||||
errors.Meta(dalSchemaAlterationPropsMetaKey{}, p),
|
||||
|
||||
// translation namespace & key
|
||||
errors.Meta(locale.ErrorMetaNamespace{}, "system"),
|
||||
errors.Meta(locale.ErrorMetaKey{}, "dal-schema-alteration.errors.notAllowedToDelete"),
|
||||
|
||||
errors.StackSkip(1),
|
||||
)
|
||||
|
||||
if len(mm) > 0 {
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// DalSchemaAlterationErrNotAllowedToUndelete returns "system:dal-schema-alteration.notAllowedToUndelete" as *errors.Error
|
||||
//
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func DalSchemaAlterationErrNotAllowedToUndelete(mm ...*dalSchemaAlterationActionProps) *errors.Error {
|
||||
var p = &dalSchemaAlterationActionProps{}
|
||||
if len(mm) > 0 {
|
||||
p = mm[0]
|
||||
}
|
||||
|
||||
var e = errors.New(
|
||||
errors.KindInternal,
|
||||
|
||||
p.Format("not allowed to undelete this dal schema alteration", nil),
|
||||
|
||||
errors.Meta("type", "notAllowedToUndelete"),
|
||||
errors.Meta("resource", "system:dal-schema-alteration"),
|
||||
|
||||
// action log entry; no formatting, it will be applied inside recordAction fn.
|
||||
errors.Meta(dalSchemaAlterationLogMetaKey{}, "failed to undelete {{dalSchemaAlteration.ID}}; insufficient permissions"),
|
||||
errors.Meta(dalSchemaAlterationPropsMetaKey{}, p),
|
||||
|
||||
// translation namespace & key
|
||||
errors.Meta(locale.ErrorMetaNamespace{}, "system"),
|
||||
errors.Meta(locale.ErrorMetaKey{}, "dal-schema-alteration.errors.notAllowedToUndelete"),
|
||||
|
||||
errors.StackSkip(1),
|
||||
)
|
||||
|
||||
if len(mm) > 0 {
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// *********************************************************************************************************************
|
||||
// *********************************************************************************************************************
|
||||
|
||||
// recordAction is a service helper function wraps function that can return error
|
||||
//
|
||||
// It will wrap unrecognized/internal errors with generic errors.
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func (svc dalSchemaAlteration) recordAction(ctx context.Context, props *dalSchemaAlterationActionProps, actionFn func(...*dalSchemaAlterationActionProps) *dalSchemaAlterationAction, err error) error {
|
||||
if svc.actionlog == nil || actionFn == nil {
|
||||
// action log disabled or no action fn passed, return error as-is
|
||||
return err
|
||||
} else if err == nil {
|
||||
// action completed w/o error, record it
|
||||
svc.actionlog.Record(ctx, actionFn(props).ToAction())
|
||||
return nil
|
||||
}
|
||||
|
||||
a := actionFn(props).ToAction()
|
||||
|
||||
// Extracting error information and recording it as action
|
||||
a.Error = err.Error()
|
||||
|
||||
switch c := err.(type) {
|
||||
case *errors.Error:
|
||||
m := c.Meta()
|
||||
|
||||
a.Error = err.Error()
|
||||
a.Severity = actionlog.Severity(m.AsInt("severity"))
|
||||
a.Description = props.Format(m.AsString(dalSchemaAlterationLogMetaKey{}), err)
|
||||
|
||||
if p, has := m[dalSchemaAlterationPropsMetaKey{}]; has {
|
||||
a.Meta = p.(*dalSchemaAlterationActionProps).Serialize()
|
||||
}
|
||||
|
||||
svc.actionlog.Record(ctx, a)
|
||||
default:
|
||||
svc.actionlog.Record(ctx, a)
|
||||
}
|
||||
|
||||
// Original error is passed on
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
# List of loggable service actions
|
||||
|
||||
resource: system:dal-schema-alteration
|
||||
service: dalSchemaAlteration
|
||||
|
||||
# Default sensitivity for actions
|
||||
defaultActionSeverity: notice
|
||||
|
||||
# default severity for errors
|
||||
defaultErrorSeverity: alert
|
||||
|
||||
import:
|
||||
- github.com/cortezaproject/corteza/server/system/types
|
||||
|
||||
props:
|
||||
- name: dalSchemaAlteration
|
||||
type: "*types.DalSchemaAlteration"
|
||||
fields: [ ID ]
|
||||
- name: new
|
||||
type: "*types.DalSchemaAlteration"
|
||||
fields: [ ID ]
|
||||
- name: update
|
||||
type: "*types.DalSchemaAlteration"
|
||||
fields: [ ID ]
|
||||
- name: existing
|
||||
type: "*types.DalSchemaAlteration"
|
||||
fields: [ ID ]
|
||||
- name: filter
|
||||
type: "*types.DalSchemaAlterationFilter"
|
||||
fields: [ alterationID, batchID, kind, deleted, completed ]
|
||||
|
||||
actions:
|
||||
- action: search
|
||||
log: "searched for matching dalSchemaAlterations"
|
||||
severity: info
|
||||
|
||||
- action: lookup
|
||||
log: "looked-up for a {{dalSchemaAlteration}}"
|
||||
severity: info
|
||||
|
||||
- action: delete
|
||||
log: "deleted {{dalSchemaAlteration}}"
|
||||
|
||||
- action: undelete
|
||||
log: "undeleted {{dalSchemaAlteration}}"
|
||||
|
||||
errors:
|
||||
- error: notFound
|
||||
message: "dalSchemaAlteration not found"
|
||||
severity: warning
|
||||
|
||||
- error: invalidID
|
||||
message: "invalid ID"
|
||||
severity: warning
|
||||
|
||||
- error: notAllowedToRead
|
||||
message: "not allowed to read this dal schema alteration"
|
||||
log: "failed to read {{dalSchemaAlteration.ID}}; insufficient permissions"
|
||||
|
||||
- error: notAllowedToSearch
|
||||
message: "not allowed to list or search dal schema alterations"
|
||||
log: "failed to search for dal schema alterations; insufficient permissions"
|
||||
|
||||
- error: notAllowedToListUsers
|
||||
message: "not allowed to list dal schema alterations"
|
||||
log: "failed to list dalSchemaAlteration; insufficient permissions"
|
||||
|
||||
- error: notAllowedToDelete
|
||||
message: "not allowed to delete this dal schema alteration"
|
||||
log: "failed to delete {{dalSchemaAlteration.ID}}; insufficient permissions"
|
||||
|
||||
- error: notAllowedToUndelete
|
||||
message: "not allowed to undelete this dal schema alteration"
|
||||
log: "failed to undelete {{dalSchemaAlteration.ID}}; insufficient permissions"
|
||||
@@ -79,6 +79,7 @@ var (
|
||||
DefaultCredentials *credentials
|
||||
DefaultDalConnection *dalConnection
|
||||
DefaultDalSensitivityLevel *dalSensitivityLevel
|
||||
DefaultDalSchemaAlteration *dalSchemaAlteration
|
||||
DefaultRole *role
|
||||
DefaultApplication *application
|
||||
DefaultReminder ReminderService
|
||||
@@ -157,9 +158,8 @@ func Initialize(ctx context.Context, log *zap.Logger, s store.Storer, ws websock
|
||||
DefaultDalConnection = Connection(ctx, dal.Service(), c.DB)
|
||||
|
||||
DefaultDalSensitivityLevel = SensitivityLevel(ctx, dal.Service())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
DefaultDalSchemaAlteration = DalSchemaAlteration()
|
||||
|
||||
if DefaultObjectStore == nil {
|
||||
var (
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/sql"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/filter"
|
||||
)
|
||||
|
||||
type (
|
||||
DalSchemaAlteration struct {
|
||||
ID uint64 `json:"alterationID,string"`
|
||||
BatchID uint64 `json:"batchID,string"`
|
||||
DependsOn uint64 `json:"dependsOn,string"`
|
||||
|
||||
Kind string `json:"kind"`
|
||||
Params *DalSchemaAlterationParams `json:"params"`
|
||||
|
||||
CreatedAt time.Time `json:"createdAt,omitempty"`
|
||||
CreatedBy uint64 `json:"createdBy,string" `
|
||||
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
|
||||
UpdatedBy uint64 `json:"updatedBy,string,omitempty"`
|
||||
DeletedAt *time.Time `json:"deletedAt,omitempty"`
|
||||
DeletedBy uint64 `json:"deletedBy,string,omitempty"`
|
||||
|
||||
CompletedAt *time.Time `json:"completedAt,omitempty"`
|
||||
CompletedBy uint64 `json:"completedBy,string,omitempty"`
|
||||
}
|
||||
|
||||
DalSchemaAlterationParams struct {
|
||||
}
|
||||
|
||||
DalSchemaAlterationFilter struct {
|
||||
AlterationID []string `json:"alterationID"`
|
||||
BatchID uint64 `json:"batchID,string"`
|
||||
Kind string `json:"kind"`
|
||||
|
||||
Deleted filter.State `json:"deleted"`
|
||||
Completed filter.State `json:"completed"`
|
||||
|
||||
// Standard helpers for paging and sorting
|
||||
filter.Sorting
|
||||
filter.Paging
|
||||
}
|
||||
)
|
||||
|
||||
func (meta *DalSchemaAlterationParams) Scan(src any) error { return sql.ParseJSON(src, meta) }
|
||||
func (meta *DalSchemaAlterationParams) Value() (driver.Value, error) { return json.Marshal(meta) }
|
||||
+64
@@ -823,3 +823,67 @@ func (r *DalSensitivityLevel) SetValue(name string, pos uint, value any) (err er
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r DalSchemaAlteration) GetID() uint64 { return r.ID }
|
||||
|
||||
func (r *DalSchemaAlteration) GetValue(name string, pos uint) (any, error) {
|
||||
switch name {
|
||||
case "batchID", "BatchID":
|
||||
return r.BatchID, nil
|
||||
case "completedAt", "CompletedAt":
|
||||
return r.CompletedAt, nil
|
||||
case "completedBy", "CompletedBy":
|
||||
return r.CompletedBy, nil
|
||||
case "createdAt", "CreatedAt":
|
||||
return r.CreatedAt, nil
|
||||
case "createdBy", "CreatedBy":
|
||||
return r.CreatedBy, nil
|
||||
case "deletedAt", "DeletedAt":
|
||||
return r.DeletedAt, nil
|
||||
case "deletedBy", "DeletedBy":
|
||||
return r.DeletedBy, nil
|
||||
case "dependsOn", "DependsOn":
|
||||
return r.DependsOn, nil
|
||||
case "id", "ID":
|
||||
return r.ID, nil
|
||||
case "kind", "Kind":
|
||||
return r.Kind, nil
|
||||
case "updatedAt", "UpdatedAt":
|
||||
return r.UpdatedAt, nil
|
||||
case "updatedBy", "UpdatedBy":
|
||||
return r.UpdatedBy, nil
|
||||
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *DalSchemaAlteration) SetValue(name string, pos uint, value any) (err error) {
|
||||
switch name {
|
||||
case "batchID", "BatchID":
|
||||
return cast2.Uint64(value, &r.BatchID)
|
||||
case "completedAt", "CompletedAt":
|
||||
return cast2.TimePtr(value, &r.CompletedAt)
|
||||
case "completedBy", "CompletedBy":
|
||||
return cast2.Uint64(value, &r.CompletedBy)
|
||||
case "createdAt", "CreatedAt":
|
||||
return cast2.Time(value, &r.CreatedAt)
|
||||
case "createdBy", "CreatedBy":
|
||||
return cast2.Uint64(value, &r.CreatedBy)
|
||||
case "deletedAt", "DeletedAt":
|
||||
return cast2.TimePtr(value, &r.DeletedAt)
|
||||
case "deletedBy", "DeletedBy":
|
||||
return cast2.Uint64(value, &r.DeletedBy)
|
||||
case "dependsOn", "DependsOn":
|
||||
return cast2.Uint64(value, &r.DependsOn)
|
||||
case "id", "ID":
|
||||
return cast2.Uint64(value, &r.ID)
|
||||
case "kind", "Kind":
|
||||
return cast2.String(value, &r.Kind)
|
||||
case "updatedAt", "UpdatedAt":
|
||||
return cast2.TimePtr(value, &r.UpdatedAt)
|
||||
case "updatedBy", "UpdatedBy":
|
||||
return cast2.Uint64(value, &r.UpdatedBy)
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Generated
+1
@@ -30,5 +30,6 @@ const (
|
||||
UserResourceType = "corteza::system:user"
|
||||
DalConnectionResourceType = "corteza::system:dal-connection"
|
||||
DalSensitivityLevelResourceType = "corteza::system:dal-sensitivity-level"
|
||||
DalSchemaAlterationResourceType = "corteza::system:dal-schema-alteration"
|
||||
ComponentResourceType = "corteza::system"
|
||||
)
|
||||
|
||||
Generated
+61
@@ -70,6 +70,11 @@ type (
|
||||
// This type is auto-generated.
|
||||
DalConnectionSet []*DalConnection
|
||||
|
||||
// DalSchemaAlterationSet slice of DalSchemaAlteration
|
||||
//
|
||||
// This type is auto-generated.
|
||||
DalSchemaAlterationSet []*DalSchemaAlteration
|
||||
|
||||
// DalSensitivityLevelSet slice of DalSensitivityLevel
|
||||
//
|
||||
// This type is auto-generated.
|
||||
@@ -709,6 +714,62 @@ func (set DalConnectionSet) IDs() (IDs []uint64) {
|
||||
return
|
||||
}
|
||||
|
||||
// Walk iterates through every slice item and calls w(DalSchemaAlteration) err
|
||||
//
|
||||
// This function is auto-generated.
|
||||
func (set DalSchemaAlterationSet) Walk(w func(*DalSchemaAlteration) error) (err error) {
|
||||
for i := range set {
|
||||
if err = w(set[i]); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Filter iterates through every slice item, calls f(DalSchemaAlteration) (bool, err) and return filtered slice
|
||||
//
|
||||
// This function is auto-generated.
|
||||
func (set DalSchemaAlterationSet) Filter(f func(*DalSchemaAlteration) (bool, error)) (out DalSchemaAlterationSet, err error) {
|
||||
var ok bool
|
||||
out = DalSchemaAlterationSet{}
|
||||
for i := range set {
|
||||
if ok, err = f(set[i]); err != nil {
|
||||
return
|
||||
} else if ok {
|
||||
out = append(out, set[i])
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FindByID finds items from slice by its ID property
|
||||
//
|
||||
// This function is auto-generated.
|
||||
func (set DalSchemaAlterationSet) FindByID(ID uint64) *DalSchemaAlteration {
|
||||
for i := range set {
|
||||
if set[i].ID == ID {
|
||||
return set[i]
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IDs returns a slice of uint64s from all items in the set
|
||||
//
|
||||
// This function is auto-generated.
|
||||
func (set DalSchemaAlterationSet) IDs() (IDs []uint64) {
|
||||
IDs = make([]uint64, len(set))
|
||||
|
||||
for i := range set {
|
||||
IDs[i] = set[i].ID
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Walk iterates through every slice item and calls w(DalSensitivityLevel) err
|
||||
//
|
||||
// This function is auto-generated.
|
||||
|
||||
Generated
+90
@@ -958,6 +958,96 @@ func TestDalConnectionSetIDs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDalSchemaAlterationSetWalk(t *testing.T) {
|
||||
var (
|
||||
value = make(DalSchemaAlterationSet, 3)
|
||||
req = require.New(t)
|
||||
)
|
||||
|
||||
// check walk with no errors
|
||||
{
|
||||
err := value.Walk(func(*DalSchemaAlteration) error {
|
||||
return nil
|
||||
})
|
||||
req.NoError(err)
|
||||
}
|
||||
|
||||
// check walk with error
|
||||
req.Error(value.Walk(func(*DalSchemaAlteration) error { return fmt.Errorf("walk error") }))
|
||||
}
|
||||
|
||||
func TestDalSchemaAlterationSetFilter(t *testing.T) {
|
||||
var (
|
||||
value = make(DalSchemaAlterationSet, 3)
|
||||
req = require.New(t)
|
||||
)
|
||||
|
||||
// filter nothing
|
||||
{
|
||||
set, err := value.Filter(func(*DalSchemaAlteration) (bool, error) {
|
||||
return true, nil
|
||||
})
|
||||
req.NoError(err)
|
||||
req.Equal(len(set), len(value))
|
||||
}
|
||||
|
||||
// filter one item
|
||||
{
|
||||
found := false
|
||||
set, err := value.Filter(func(*DalSchemaAlteration) (bool, error) {
|
||||
if !found {
|
||||
found = true
|
||||
return found, nil
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
req.NoError(err)
|
||||
req.Len(set, 1)
|
||||
}
|
||||
|
||||
// filter error
|
||||
{
|
||||
_, err := value.Filter(func(*DalSchemaAlteration) (bool, error) {
|
||||
return false, fmt.Errorf("filter error")
|
||||
})
|
||||
req.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDalSchemaAlterationSetIDs(t *testing.T) {
|
||||
var (
|
||||
value = make(DalSchemaAlterationSet, 3)
|
||||
req = require.New(t)
|
||||
)
|
||||
|
||||
// construct objects
|
||||
value[0] = new(DalSchemaAlteration)
|
||||
value[1] = new(DalSchemaAlteration)
|
||||
value[2] = new(DalSchemaAlteration)
|
||||
// set ids
|
||||
value[0].ID = 1
|
||||
value[1].ID = 2
|
||||
value[2].ID = 3
|
||||
|
||||
// Find existing
|
||||
{
|
||||
val := value.FindByID(2)
|
||||
req.Equal(uint64(2), val.ID)
|
||||
}
|
||||
|
||||
// Find non-existing
|
||||
{
|
||||
val := value.FindByID(4)
|
||||
req.Nil(val)
|
||||
}
|
||||
|
||||
// List IDs from set
|
||||
{
|
||||
val := value.IDs()
|
||||
req.Equal(len(val), len(value))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDalSensitivityLevelSetWalk(t *testing.T) {
|
||||
var (
|
||||
value = make(DalSensitivityLevelSet, 3)
|
||||
|
||||
@@ -10,6 +10,7 @@ types:
|
||||
labelResourceType: user
|
||||
DalConnection:
|
||||
DalSensitivityLevel:
|
||||
DalSchemaAlteration:
|
||||
Application:
|
||||
labelResourceType: application
|
||||
Role:
|
||||
|
||||
Reference in New Issue
Block a user