snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
129
server/system/rest/dal_schema_alteration.go
Normal file
129
server/system/rest/dal_schema_alteration.go
Normal file
@@ -0,0 +1,129 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/api"
|
||||
"github.com/cortezaproject/corteza/server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza/server/pkg/id"
|
||||
"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)
|
||||
Apply(context.Context, ...uint64) error
|
||||
Dismiss(context.Context, ...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: id.Uints(r.BatchID...),
|
||||
Kind: r.Kind,
|
||||
Resource: r.Resource,
|
||||
ResourceType: r.ResourceType,
|
||||
|
||||
Deleted: filter.State(r.Deleted),
|
||||
Dismissed: filter.State(r.Dismissed),
|
||||
Completed: filter.State(r.Completed),
|
||||
}
|
||||
)
|
||||
|
||||
if f.Deleted == 0 {
|
||||
f.Deleted = filter.StateExcluded
|
||||
}
|
||||
if f.Dismissed == 0 {
|
||||
f.Dismissed = 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) Apply(ctx context.Context, r *request.DalSchemaAlterationApply) (interface{}, error) {
|
||||
return api.OK(), ctrl.svc.Apply(ctx, r.AlterationID...)
|
||||
}
|
||||
|
||||
func (ctrl DalSchemaAlteration) Dismiss(ctx context.Context, r *request.DalSchemaAlterationDismiss) (interface{}, error) {
|
||||
return api.OK(), ctrl.svc.Dismiss(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
|
||||
}
|
||||
Reference in New Issue
Block a user