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:
22
server/compose/service/event/compose.go
Normal file
22
server/compose/service/event/compose.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/pkg/scheduler"
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res composeOnInterval) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return scheduler.OnInterval(c.Values()...)
|
||||
}
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res composeOnTimestamp) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return scheduler.OnTimestamp(c.Values()...)
|
||||
}
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res composeBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
// We do not support any matchers, so if there is a constraint, fail.
|
||||
return false
|
||||
}
|
||||
39
server/compose/service/event/compose_test.go
Normal file
39
server/compose/service/event/compose_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestComposeOnIntervalMatching(t *testing.T) {
|
||||
var (
|
||||
res = &composeOnInterval{}
|
||||
cInt = eventbus.MustMakeConstraint("", "", "* * * * *")
|
||||
)
|
||||
|
||||
// Just make sure it runs
|
||||
// not bothering with precise test setup (scheduler's tests cover all that
|
||||
res.Match(cInt)
|
||||
}
|
||||
|
||||
func TestComposeOnTimestampMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &composeOnInterval{}
|
||||
|
||||
cTStamp = eventbus.MustMakeConstraint("", "", "2000-01-01T00:00:00Z") // Y2k!
|
||||
)
|
||||
|
||||
a.False(res.Match(cTStamp), "Year 2000?! How did we get here? Anyhow, happy New year!")
|
||||
}
|
||||
|
||||
func TestComposeMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &composeBase{}
|
||||
)
|
||||
|
||||
a.False(res.Match(eventbus.MustMakeConstraint("foo", "", "bar")))
|
||||
}
|
||||
3396
server/compose/service/event/events.gen.go
generated
Normal file
3396
server/compose/service/event/events.gen.go
generated
Normal file
File diff suppressed because it is too large
Load Diff
106
server/compose/service/event/events.yaml
Normal file
106
server/compose/service/event/events.yaml
Normal file
@@ -0,0 +1,106 @@
|
||||
compose:
|
||||
on: ['manual', 'interval', 'timestamp']
|
||||
|
||||
compose:namespace:
|
||||
on: ['manual']
|
||||
ba: ['create', 'update', 'delete']
|
||||
props:
|
||||
- name: 'namespace'
|
||||
type: '*types.Namespace'
|
||||
- name: 'oldNamespace'
|
||||
type: '*types.Namespace'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: namespace.handle
|
||||
- name: namespace.name
|
||||
|
||||
compose:page:
|
||||
on: ['manual']
|
||||
ba: ['create', 'update', 'delete']
|
||||
props:
|
||||
- name: 'page'
|
||||
type: '*types.Page'
|
||||
- name: 'oldPage'
|
||||
type: '*types.Page'
|
||||
immutable: true
|
||||
- name: 'namespace'
|
||||
type: '*types.Namespace'
|
||||
immutable: true
|
||||
- name: 'selected'
|
||||
type: '[]interface{}'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: namespace.handle
|
||||
- name: namespace.name
|
||||
- name: page.handle
|
||||
- name: page.name
|
||||
|
||||
compose:page-layout:
|
||||
on: ['manual']
|
||||
ba: ['create', 'update', 'delete']
|
||||
props:
|
||||
- name: 'pageLayout'
|
||||
type: '*types.PageLayout'
|
||||
- name: 'oldPageLayout'
|
||||
type: '*types.PageLayout'
|
||||
immutable: true
|
||||
- name: 'namespace'
|
||||
type: '*types.Namespace'
|
||||
immutable: true
|
||||
- name: 'selected'
|
||||
type: '[]interface{}'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: namespace.handle
|
||||
- name: namespace.name
|
||||
- name: pageLayout.handle
|
||||
- name: pageLayout.name
|
||||
|
||||
compose:module:
|
||||
on: ['manual']
|
||||
ba: ['create', 'update', 'delete']
|
||||
props:
|
||||
- name: 'module'
|
||||
type: '*types.Module'
|
||||
- name: 'oldModule'
|
||||
type: '*types.Module'
|
||||
immutable: true
|
||||
- name: 'namespace'
|
||||
type: '*types.Namespace'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: namespace.handle
|
||||
- name: namespace.name
|
||||
- name: module.handle
|
||||
- name: module.name
|
||||
|
||||
compose:record:
|
||||
on: ['manual', 'iteration']
|
||||
ba: ['create', 'update', 'delete', 'undelete', 'organize']
|
||||
props:
|
||||
- name: 'record'
|
||||
type: '*types.Record'
|
||||
- name: 'oldRecord'
|
||||
type: '*types.Record'
|
||||
immutable: true
|
||||
- name: 'module'
|
||||
type: '*types.Module'
|
||||
immutable: true
|
||||
- name: 'namespace'
|
||||
type: '*types.Namespace'
|
||||
immutable: true
|
||||
- name: 'recordValueErrors'
|
||||
type: '*types.RecordValueErrorSet'
|
||||
- name: 'selected'
|
||||
type: '[]interface{}'
|
||||
immutable: true
|
||||
|
||||
constraints:
|
||||
- name: namespace.handle
|
||||
- name: namespace.name
|
||||
- name: module.handle
|
||||
- name: module.name
|
||||
- name: record.created-at
|
||||
- name: record.updated-at
|
||||
- name: record.deleted-at
|
||||
- name: record.values.*
|
||||
26
server/compose/service/event/module.go
Normal file
26
server/compose/service/event/module.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res moduleBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return eventbus.MatchFirst(
|
||||
func() bool { return moduleMatch(res.module, c) },
|
||||
func() bool { return namespaceMatch(res.namespace, c) },
|
||||
)
|
||||
}
|
||||
|
||||
// Handles module matchers
|
||||
func moduleMatch(r *types.Module, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "module", "module.handle":
|
||||
return c.Match(r.Handle)
|
||||
case "module.name":
|
||||
return c.Match(r.Name)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
25
server/compose/service/event/module_test.go
Normal file
25
server/compose/service/event/module_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestModuleMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &moduleBase{
|
||||
module: &types.Module{Handle: "mh1"},
|
||||
namespace: &types.Namespace{Slug: "slg1"},
|
||||
}
|
||||
|
||||
cMod = eventbus.MustMakeConstraint("module", "eq", "mh1")
|
||||
cNms = eventbus.MustMakeConstraint("namespace", "eq", "slg1")
|
||||
)
|
||||
|
||||
a.True(res.Match(cMod))
|
||||
a.True(res.Match(cNms))
|
||||
}
|
||||
23
server/compose/service/event/namespace.go
Normal file
23
server/compose/service/event/namespace.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res namespaceBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return namespaceMatch(res.namespace, c)
|
||||
}
|
||||
|
||||
// Handles namespace matchers
|
||||
func namespaceMatch(r *types.Namespace, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "namespace", "namespace.slug", "namespace.handle":
|
||||
return c.Match(r.Slug)
|
||||
case "namespace.name":
|
||||
return c.Match(r.Name)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
22
server/compose/service/event/namespace_test.go
Normal file
22
server/compose/service/event/namespace_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNamespaceMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &namespaceBase{
|
||||
namespace: &types.Namespace{Slug: "slg1"},
|
||||
}
|
||||
|
||||
cNms = eventbus.MustMakeConstraint("namespace", "eq", "slg1")
|
||||
)
|
||||
|
||||
a.True(res.Match(cNms))
|
||||
}
|
||||
26
server/compose/service/event/page.go
Normal file
26
server/compose/service/event/page.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res pageBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return eventbus.MatchFirst(
|
||||
func() bool { return pageMatch(res.page, c) },
|
||||
func() bool { return namespaceMatch(res.namespace, c) },
|
||||
)
|
||||
}
|
||||
|
||||
// Handles namespace matchers
|
||||
func pageMatch(r *types.Page, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "page", "page.handle":
|
||||
return c.Match(r.Handle)
|
||||
case "page.title":
|
||||
return c.Match(r.Title)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
19
server/compose/service/event/page_layout.go
Normal file
19
server/compose/service/event/page_layout.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
)
|
||||
|
||||
var _ = eventbus.ConstraintMaker
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res pageLayoutBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
// By default we match no mather what kind of constraints we receive
|
||||
//
|
||||
// Function will be called multiple times - once for every trigger constraint
|
||||
// All should match (return true):
|
||||
// constraint#1 AND constraint#2 AND constraint#3 ...
|
||||
//
|
||||
// When there are multiple values, Match() can decide how to treat them (OR, AND...)
|
||||
return true
|
||||
}
|
||||
25
server/compose/service/event/page_test.go
Normal file
25
server/compose/service/event/page_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPageMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &pageBase{
|
||||
page: &types.Page{Handle: "ph1"},
|
||||
namespace: &types.Namespace{Slug: "slg1"},
|
||||
}
|
||||
|
||||
cPge = eventbus.MustMakeConstraint("page", "eq", "ph1")
|
||||
cNms = eventbus.MustMakeConstraint("namespace", "eq", "slg1")
|
||||
)
|
||||
|
||||
a.True(res.Match(cPge))
|
||||
a.True(res.Match(cNms))
|
||||
}
|
||||
43
server/compose/service/event/record.go
Normal file
43
server/compose/service/event/record.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
recordMatchValues = "record.values."
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res recordBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return eventbus.MatchFirst(
|
||||
func() bool { return recordMatch(res.record, c) },
|
||||
func() bool { return moduleMatch(res.module, c) },
|
||||
func() bool { return namespaceMatch(res.namespace, c) },
|
||||
)
|
||||
}
|
||||
|
||||
func recordMatch(r *types.Record, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "record.updatedAt", "record.updated-at":
|
||||
return c.Match(r.UpdatedAt.Format(time.RFC3339))
|
||||
case "record.createdAt", "record.created-at":
|
||||
return c.Match(r.CreatedAt.Format(time.RFC3339))
|
||||
case "record.deletedAt", "record.deleted-at":
|
||||
return c.Match(r.DeletedAt.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
if strings.HasPrefix(c.Name(), recordMatchValues) {
|
||||
fieldName := c.Name()[len(recordMatchValues):]
|
||||
for _, v := range r.Values.FilterByName(fieldName) {
|
||||
if c.Match(v.Value) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
58
server/compose/service/event/record_test.go
Normal file
58
server/compose/service/event/record_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRecordMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &recordBase{
|
||||
module: &types.Module{Handle: "mh1"},
|
||||
namespace: &types.Namespace{Slug: "slg1"},
|
||||
}
|
||||
|
||||
cMod = eventbus.MustMakeConstraint("module", "eq", "mh1")
|
||||
cNms = eventbus.MustMakeConstraint("namespace", "eq", "slg1")
|
||||
)
|
||||
|
||||
a.True(res.Match(cMod))
|
||||
a.True(res.Match(cNms))
|
||||
}
|
||||
|
||||
func TestRecordMatchValues(t *testing.T) {
|
||||
var (
|
||||
rec = &types.Record{
|
||||
Values: types.RecordValueSet{
|
||||
&types.RecordValue{Name: "fld1", Value: "val1"},
|
||||
&types.RecordValue{Name: "fld2", Value: "val2"},
|
||||
},
|
||||
}
|
||||
|
||||
res = &recordBase{record: rec}
|
||||
|
||||
cases = []struct {
|
||||
match bool
|
||||
name string
|
||||
op string
|
||||
v string
|
||||
}{
|
||||
{true, "fld1", "eq", "val1"},
|
||||
{false, "fld2", "eq", "val1"},
|
||||
{false, "fld1", "!=", "val1"},
|
||||
}
|
||||
)
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(
|
||||
fmt.Sprintf("(%s %s %s) == %v", c.name, c.op, c.v, c.match),
|
||||
func(t *testing.T) {
|
||||
assert.Equal(t, c.match, res.Match(eventbus.MustMakeConstraint("record.values."+c.name, c.op, c.v)))
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user