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:
25
server/system/service/event/application.go
Normal file
25
server/system/service/event/application.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res applicationBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return applicationMatch(res.application, c)
|
||||
}
|
||||
|
||||
// Handles application matchers
|
||||
func applicationMatch(r *types.Application, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
// not supported yet
|
||||
//case "application", "application.handle":
|
||||
// return c.Match(r.Handle)
|
||||
case "application.name":
|
||||
return c.Match(r.Name)
|
||||
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
22
server/system/service/event/application_test.go
Normal file
22
server/system/service/event/application_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestApplicationMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &applicationBase{
|
||||
application: &types.Application{Name: "someApp"},
|
||||
}
|
||||
|
||||
cApp = eventbus.MustMakeConstraint("application.name", "eq", "someApp")
|
||||
)
|
||||
|
||||
a.True(res.Match(cApp))
|
||||
}
|
||||
8
server/system/service/event/auth.go
Normal file
8
server/system/service/event/auth.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package event
|
||||
|
||||
import "github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res authBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return userMatch(res.user, c)
|
||||
}
|
||||
24
server/system/service/event/auth_client.go
Normal file
24
server/system/service/event/auth_client.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
var _ = eventbus.ConstraintMaker
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res authClientBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return authClientMatch(res.authClient, c)
|
||||
}
|
||||
|
||||
// Handles application matchers
|
||||
func authClientMatch(r *types.AuthClient, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
// not supported yet
|
||||
case "auth-client", "auth-client.handle":
|
||||
return c.Match(r.Handle)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
22
server/system/service/event/auth_test.go
Normal file
22
server/system/service/event/auth_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAuthMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &authBase{
|
||||
user: &types.User{Handle: "user"},
|
||||
}
|
||||
|
||||
cUsr = eventbus.MustMakeConstraint("user", "eq", "user")
|
||||
)
|
||||
|
||||
a.True(res.Match(cUsr))
|
||||
}
|
||||
19
server/system/service/event/data_privacy_request.go
Normal file
19
server/system/service/event/data_privacy_request.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 dataPrivacyRequestBase) 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
|
||||
}
|
||||
5346
server/system/service/event/events.gen.go
generated
Normal file
5346
server/system/service/event/events.gen.go
generated
Normal file
File diff suppressed because it is too large
Load Diff
158
server/system/service/event/events.yaml
Normal file
158
server/system/service/event/events.yaml
Normal file
@@ -0,0 +1,158 @@
|
||||
system:
|
||||
on: ['manual', 'interval', 'timestamp']
|
||||
|
||||
system:sink:
|
||||
on: ['request']
|
||||
props:
|
||||
- name: 'response'
|
||||
type: '*types.SinkResponse'
|
||||
- name: 'request'
|
||||
type: '*types.SinkRequest'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: request.host
|
||||
- name: request.remote-address
|
||||
- name: request.method
|
||||
- name: request.path
|
||||
- name: request.username
|
||||
- name: request.password
|
||||
- name: request.content-type
|
||||
- name: request.get.*
|
||||
- name: request.post.*
|
||||
- name: request.header.*
|
||||
|
||||
system:mail:
|
||||
on: ['manual', 'receive', 'send']
|
||||
props:
|
||||
- name: 'message'
|
||||
type: '*types.MailMessage'
|
||||
constraints:
|
||||
- name: message.header.subject
|
||||
- name: message.header.from
|
||||
- name: message.header.to
|
||||
- name: message.header.reply-to
|
||||
- name: message.header.cc
|
||||
- name: message.header.bcc
|
||||
|
||||
system:auth:
|
||||
ba: ['login', 'signup']
|
||||
props:
|
||||
- name: 'user'
|
||||
type: '*types.User'
|
||||
- name: 'provider'
|
||||
type: '*types.AuthProvider'
|
||||
constraints:
|
||||
- name: user.handle
|
||||
- name: user.email
|
||||
|
||||
system:auth-client:
|
||||
on: ['manual']
|
||||
ba: ['create', 'update', 'delete']
|
||||
props:
|
||||
- name: 'authClient'
|
||||
type: '*types.AuthClient'
|
||||
- name: 'oldAuthClient'
|
||||
type: '*types.AuthClient'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: auth-client.handle
|
||||
|
||||
|
||||
system:user:
|
||||
on: ['manual']
|
||||
ba: ['create', 'update', 'delete', 'suspend']
|
||||
props:
|
||||
- name: 'user'
|
||||
type: '*types.User'
|
||||
- name: 'oldUser'
|
||||
type: '*types.User'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: user.handle
|
||||
- name: user.email
|
||||
|
||||
system:role:
|
||||
on: ['manual']
|
||||
ba: ['create', 'update', 'delete']
|
||||
props:
|
||||
- name: 'role'
|
||||
type: '*types.Role'
|
||||
- name: 'oldRole'
|
||||
type: '*types.Role'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: role.handle
|
||||
- name: role.name
|
||||
|
||||
system:role:member:
|
||||
ba: ['add', 'remove']
|
||||
props:
|
||||
- name: 'user'
|
||||
type: '*types.User'
|
||||
- name: 'role'
|
||||
type: '*types.Role'
|
||||
constraints:
|
||||
- name: role.handle
|
||||
- name: role.name
|
||||
- name: user.handle
|
||||
- name: user.email
|
||||
|
||||
|
||||
system:user-group:
|
||||
on: ['manual']
|
||||
ba: ['create', 'update', 'delete', 'memberAdd', 'memberRemove']
|
||||
props:
|
||||
- name: 'userGroup'
|
||||
type: '*types.UserGroup'
|
||||
- name: 'oldUserGroup'
|
||||
type: '*types.UserGroup'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: userGroup.handle
|
||||
- name: userGroup.name
|
||||
|
||||
system:application:
|
||||
on: ['manual']
|
||||
ba: ['create', 'update', 'delete']
|
||||
props:
|
||||
- name: 'application'
|
||||
type: '*types.Application'
|
||||
- name: 'oldApplication'
|
||||
type: '*types.Application'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: application.name
|
||||
|
||||
|
||||
system:queue:
|
||||
on: ['message']
|
||||
props:
|
||||
- name: 'payload'
|
||||
type: '*types.QueueMessage'
|
||||
constraints:
|
||||
- name: payload.queue
|
||||
|
||||
system:data-privacy-request:
|
||||
on: ['manual']
|
||||
ba: ['create', 'update', 'delete']
|
||||
props:
|
||||
- name: 'dataPrivacyRequest'
|
||||
type: '*types.DataPrivacyRequest'
|
||||
- name: 'oldDataPrivacyRequest'
|
||||
type: '*types.DataPrivacyRequest'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: role.name
|
||||
|
||||
system:reminder:
|
||||
on: ['manual']
|
||||
ba: ['create','update','delete','dismiss','snooze']
|
||||
props:
|
||||
- name: 'reminder'
|
||||
type: '*types.Reminder'
|
||||
- name: 'oldReminder'
|
||||
type: '*types.Reminder'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: reminder.resource
|
||||
- name: reminder.assigned-to
|
||||
48
server/system/service/event/mail.go
Normal file
48
server/system/service/event/mail.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"net/mail"
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res mailBase) 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 mailMatch(res.message, c)
|
||||
}
|
||||
|
||||
// Handles role matchers
|
||||
func mailMatch(r *types.MailMessage, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "message.header.subject", "mail.header.subject":
|
||||
return c.Match(r.Subject)
|
||||
case "message.header.from", "mail.header.from":
|
||||
return mailMatchAnyAddress(c, r.Header.From...)
|
||||
case "message.header.to", "mail.header.to":
|
||||
return mailMatchAnyAddress(c, r.Header.To...)
|
||||
case "message.header.reply-to", "mail.header.replyTo":
|
||||
return mailMatchAnyAddress(c, r.Header.ReplyTo...)
|
||||
case "message.header.cc", "mail.header.cc":
|
||||
return mailMatchAnyAddress(c, r.Header.CC...)
|
||||
case "message.header.bcc", "mail.header.bcc":
|
||||
return mailMatchAnyAddress(c, r.Header.BCC...)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func mailMatchAnyAddress(c eventbus.ConstraintMatcher, aa ...*mail.Address) bool {
|
||||
for _, a := range aa {
|
||||
if c.Match(a.Address) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
22
server/system/service/event/queue.go
Normal file
22
server/system/service/event/queue.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
var _ = eventbus.ConstraintMaker
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res queueBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return queueMatch(res.payload, c)
|
||||
}
|
||||
|
||||
func queueMatch(r *types.QueueMessage, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "payload.queue":
|
||||
return c.Match(r.Queue)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
23
server/system/service/event/reminder.go
Normal file
23
server/system/service/event/reminder.go
Normal file
@@ -0,0 +1,23 @@
|
||||
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 reminderBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
// Prevent recursion: don't trigger workflows for workflow-created reminders
|
||||
if res.reminder != nil && res.reminder.Resource == "workflow-reminder" {
|
||||
return false
|
||||
}
|
||||
// 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
|
||||
}
|
||||
23
server/system/service/event/role.go
Normal file
23
server/system/service/event/role.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res roleBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return roleMatch(res.role, c)
|
||||
}
|
||||
|
||||
// Handles role matchers
|
||||
func roleMatch(r *types.Role, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "role", "role.handle":
|
||||
return c.Match(r.Handle)
|
||||
case "role.name":
|
||||
return c.Match(r.Name)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
13
server/system/service/event/role_member.go
Normal file
13
server/system/service/event/role_member.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res roleMemberBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return eventbus.MatchFirst(
|
||||
func() bool { return userMatch(res.user, c) },
|
||||
func() bool { return roleMatch(res.role, c) },
|
||||
)
|
||||
}
|
||||
25
server/system/service/event/role_member_test.go
Normal file
25
server/system/service/event/role_member_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRoleMemberMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &roleMemberBase{
|
||||
role: &types.Role{Handle: "admin"},
|
||||
user: &types.User{Handle: "user"},
|
||||
}
|
||||
|
||||
cRol = eventbus.MustMakeConstraint("role", "eq", "admin")
|
||||
cUsr = eventbus.MustMakeConstraint("user", "eq", "user")
|
||||
)
|
||||
|
||||
a.True(res.Match(cRol))
|
||||
a.True(res.Match(cUsr))
|
||||
}
|
||||
22
server/system/service/event/role_test.go
Normal file
22
server/system/service/event/role_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRoleMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &roleBase{
|
||||
role: &types.Role{Handle: "admin"},
|
||||
}
|
||||
|
||||
cRol = eventbus.MustMakeConstraint("role", "eq", "admin")
|
||||
)
|
||||
|
||||
a.True(res.Match(cRol))
|
||||
}
|
||||
60
server/system/service/event/sink.go
Normal file
60
server/system/service/event/sink.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
sinkMatchRequestGet = "request.get."
|
||||
sinkMatchRequestPost = "request.post."
|
||||
sinkMatchRequestHeader = "request.header."
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res sinkBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return sinkMatch(res.request, c)
|
||||
}
|
||||
|
||||
// Handles sink's URL matchers
|
||||
func sinkMatch(r *types.SinkRequest, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "request.host":
|
||||
return c.Match(r.Host)
|
||||
case "request.remoteAddress", "request.remote-address":
|
||||
return c.Match(r.RemoteAddr)
|
||||
case "request.method":
|
||||
return c.Match(r.Method)
|
||||
case "request.path":
|
||||
// match path, right side of "/sink"
|
||||
return c.Match(r.Path)
|
||||
case "request.username":
|
||||
return c.Match(r.Username)
|
||||
case "request.password":
|
||||
return c.Match(r.Password)
|
||||
case "request.content-type":
|
||||
return c.Match(r.Header.Get("content-type"))
|
||||
}
|
||||
|
||||
// Dynamically check matcher name if it contains request.(get|post|header).*
|
||||
// and use value for matcher:
|
||||
//
|
||||
// to match "&foo=bar" in URL string use .where('request.get.foo', 'bar')
|
||||
//
|
||||
// It only matches first value (get, post and header can have multiple values)
|
||||
|
||||
if strings.HasPrefix(c.Name(), sinkMatchRequestGet) {
|
||||
return c.Match(r.Query.Get(c.Name()[len(sinkMatchRequestGet):]))
|
||||
}
|
||||
|
||||
if strings.HasPrefix(c.Name(), sinkMatchRequestPost) {
|
||||
return c.Match(r.PostForm.Get(c.Name()[len(sinkMatchRequestPost):]))
|
||||
}
|
||||
|
||||
if strings.HasPrefix(c.Name(), sinkMatchRequestHeader) {
|
||||
return c.Match(r.Header.Get(c.Name()[len(sinkMatchRequestHeader):]))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
22
server/system/service/event/system.go
Normal file
22
server/system/service/event/system.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 systemOnInterval) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return scheduler.OnInterval(c.Values()...)
|
||||
}
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res systemOnTimestamp) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return scheduler.OnTimestamp(c.Values()...)
|
||||
}
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res systemBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
// No constraints are supported for system.
|
||||
return false
|
||||
}
|
||||
39
server/system/service/event/system_test.go
Normal file
39
server/system/service/event/system_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 TestSystemOnIntervalMatching(t *testing.T) {
|
||||
var (
|
||||
res = &systemOnInterval{}
|
||||
cInt = eventbus.MustMakeConstraint("", "", "* * * * *")
|
||||
)
|
||||
|
||||
// Just make sure it runs
|
||||
// not bothering with precise test setup (scheduler's tests cover all that
|
||||
res.Match(cInt)
|
||||
}
|
||||
|
||||
func TestSystemOnTimestampMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &systemOnInterval{}
|
||||
|
||||
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 TestSystemMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &systemBase{}
|
||||
)
|
||||
|
||||
a.False(res.Match(eventbus.MustMakeConstraint("foo", "", "bar")))
|
||||
}
|
||||
23
server/system/service/event/user.go
Normal file
23
server/system/service/event/user.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res userBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
return userMatch(res.user, c)
|
||||
}
|
||||
|
||||
// Handles user matchers
|
||||
func userMatch(r *types.User, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "user", "user.handle":
|
||||
return r != nil && c.Match(r.Handle)
|
||||
case "user.email":
|
||||
return r != nil && c.Match(r.Email)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
19
server/system/service/event/user_group.go
Normal file
19
server/system/service/event/user_group.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 userGroupBase) 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
|
||||
}
|
||||
22
server/system/service/event/user_test.go
Normal file
22
server/system/service/event/user_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUserMatching(t *testing.T) {
|
||||
var (
|
||||
a = assert.New(t)
|
||||
res = &userBase{
|
||||
user: &types.User{Email: "user@example.tld"},
|
||||
}
|
||||
|
||||
cUsr = eventbus.MustMakeConstraint("user.email", "eq", "user@example.tld")
|
||||
)
|
||||
|
||||
a.True(res.Match(cUsr))
|
||||
}
|
||||
Reference in New Issue
Block a user