Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Actions Board View Rule #2249

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
353edeb
feat(actions): Actions system infra.
michaelkleinhenz Aug 17, 2018
6ea5c68
fix(tests): Fixed the tests.
michaelkleinhenz Aug 17, 2018
be9dae7
fix(doc): Fixed documentation.
michaelkleinhenz Aug 17, 2018
529be05
Merge remote-tracking branch 'upstream/master' into actions_infra
michaelkleinhenz Aug 17, 2018
008f7ff
Merge branch 'master' into actions_infra
michaelkleinhenz Aug 17, 2018
72ad9ce
Merge branch 'master' into actions_infra
michaelkleinhenz Aug 17, 2018
ab89650
fix(doc): Added doc.
michaelkleinhenz Aug 17, 2018
b7fa5c0
fix(code): Moved Change.
michaelkleinhenz Aug 17, 2018
5589d68
fix(code): Refactoring Change.Set.
michaelkleinhenz Aug 17, 2018
f625367
fix(formatting): Format fixed.
michaelkleinhenz Aug 17, 2018
00305cf
fix(staterule): Added state rule.
michaelkleinhenz Aug 17, 2018
88fdfe9
fix(actions): Enabled state rule.
michaelkleinhenz Aug 17, 2018
a60efd3
Merge remote-tracking branch 'upstream/master' into actions_staterule
michaelkleinhenz Aug 20, 2018
532ca2f
Fixed formatting.
michaelkleinhenz Aug 20, 2018
fa75f51
Fix documentation.
michaelkleinhenz Aug 20, 2018
13d3f53
Merge branch 'master' into actions_staterule
michaelkleinhenz Aug 20, 2018
9aab756
Fixed WIT.
michaelkleinhenz Aug 20, 2018
94ca51e
Fixed golden files.
michaelkleinhenz Aug 20, 2018
0edeacc
Merge remote-tracking branch 'upstream/master' into actions_staterule
michaelkleinhenz Aug 24, 2018
e832f8b
Fixed PR comments.
michaelkleinhenz Aug 24, 2018
13640c8
Merge branch 'master' into actions_staterule
michaelkleinhenz Aug 24, 2018
1ce8bd8
Merge remote-tracking branch 'upstream/master' into actions_staterule
michaelkleinhenz Aug 27, 2018
5b4d19c
Fixed group loading.
michaelkleinhenz Aug 27, 2018
4764322
Used id.Slice.
michaelkleinhenz Aug 27, 2018
feecf1c
Fixed error reporting.
michaelkleinhenz Aug 27, 2018
4b6acc6
Added test for contains. Fixes memory leak.
michaelkleinhenz Aug 27, 2018
35e6034
Added test for removeElement.
michaelkleinhenz Aug 27, 2018
d867145
Added removeElement() test.
michaelkleinhenz Aug 27, 2018
dab1b62
Merge remote-tracking branch 'upstream/master' into actions_staterule
michaelkleinhenz Aug 27, 2018
f758549
Fixed slice creation.
michaelkleinhenz Aug 27, 2018
649ef2a
Removed debug code.
michaelkleinhenz Aug 27, 2018
58f5187
Fixed equals.
michaelkleinhenz Aug 27, 2018
973fe2d
Fixed isDirty structural inconsistency in onStateChange().
michaelkleinhenz Aug 28, 2018
69d1af4
Fixed err check.
michaelkleinhenz Aug 28, 2018
9a8d624
Fixed leftover bug.
michaelkleinhenz Aug 28, 2018
5001aa2
Changed return type on fuseChanges.
michaelkleinhenz Aug 28, 2018
7dafce4
Fixed tests, removed action instances.
michaelkleinhenz Aug 28, 2018
595316f
Merge branch 'master' into actions_staterule
michaelkleinhenz Aug 29, 2018
6f4d7fb
Fixed empty return bug.
Aug 31, 2018
3cb93a2
Removed redundant code.
Aug 31, 2018
f83ff16
Updated OnChange() signature to not work with cbr.
Aug 31, 2018
9f4de7d
Removed pointer args.
Aug 31, 2018
5ff5380
Merge remote-tracking branch 'upstream/master' into actions_staterule
michaelkleinhenz Sep 6, 2018
89c8cb4
Fixed some minor issues.
michaelkleinhenz Sep 6, 2018
e71b346
Merge remote-tracking branch 'upstream/master' into actions_staterule
kwk Sep 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 4 additions & 36 deletions actions/actions.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
package actions

/*
The actions system is a key component for process automation in WIT. It provides
a way of executing user-configurable, dynamic process steps depending on user
settings, schema settings and events in the WIT.

The idea here is to provide a simple, yet powerful "publish-subscribe" system that
can connect any "event" in the system to any "action" with a clear decoupling
of events and actions with the goal of making the associations later dynamic and
configurable by the user ("user connects this event to this action"). Think
of a "IFTTT for WIT" (https://en.wikipedia.org/wiki/IFTTT).

Actions are generic and atomic execution steps that do exactly one task and
are configurable. The actions system around the actions provide a key-based
execution of the actions.

Some examples for an application of this system would be:
- closing all children of a parent WI that is being closed (the user connects the
"close" attribute change event of a WI to an action that closes all WIs of
a matching query).
- sending out notifications for mentions on markdown (the system executes an
action "send notification" for every mention found in markdown values).
- moving all WIs from one iteration to the next in the time sequence when
the original iteration is closed.

For all these automations, the actions system provides a re-usable, flexible
and later user configurable way of doing that without creating lots of
custom code and/or custom process implementations that are hardcoded in the
WIT.
*/

import (
"context"

Expand Down Expand Up @@ -65,21 +35,19 @@ func ExecuteActionsByChangeset(ctx context.Context, db application.DB, userID uu
actionConfig := actionConfigs[actionKey]
switch actionKey {
case rules.ActionKeyNil:
newContext, actionChanges, err = executeAction(rules.ActionNil{}, actionConfig, newContext, contextChanges, &actionChanges)
newContext, actionChanges, err = executeAction(rules.ActionNil{}, actionConfig, newContext, contextChanges, actionChanges)
case rules.ActionKeyFieldSet:
newContext, actionChanges, err = executeAction(rules.ActionFieldSet{
Db: db,
Ctx: ctx,
UserID: &userID,
}, actionConfig, newContext, contextChanges, &actionChanges)
/* commented out for now until this rule is added
}, actionConfig, newContext, contextChanges, actionChanges)
case rules.ActionKeyStateToMetastate:
newContext, actionChanges, err = executeAction(rules.ActionStateToMetaState{
Db: db,
Ctx: ctx,
UserID: &userID,
}, actionConfig, newContext, contextChanges, &actionChanges)
*/
}, actionConfig, newContext, contextChanges, actionChanges)
default:
return nil, nil, errs.New("action key " + actionKey + " is unknown")
}
Expand All @@ -93,7 +61,7 @@ func ExecuteActionsByChangeset(ctx context.Context, db application.DB, userID uu
// executeAction executes the action given. The actionChanges contain the changes made by
// prior action executions. The execution is expected to add/update their changes on this
// change set.
func executeAction(act rules.Action, configuration string, newContext change.Detector, contextChanges change.Set, actionChanges *change.Set) (change.Detector, change.Set, error) {
func executeAction(act rules.Action, configuration string, newContext change.Detector, contextChanges change.Set, actionChanges change.Set) (change.Detector, change.Set, error) {
if act == nil {
return nil, nil, errs.New("rule can not be nil")
}
Expand Down
2 changes: 1 addition & 1 deletion actions/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Package actions system is a key component for process automation in WIT. It prov
way of executing user-configurable, dynamic process steps depending on user
settings, schema settings and events in the WIT.

The idea here is to provide a simple, yet powerful "signal-slot" system that
The idea here is to provide a simple, yet powerful "publish-subscribe" system that
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have almost the same comment without relating to a package or something in actions/actions.go. Please remove the latter one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelkleinhenz great. But please try to use one commit per comment so it is easy to follow as a reviewer.

can connect any "event" in the system to any "action" with a clear decoupling of
events and actions with the goal of making the associations later dynamic and
configurable by the user ("user connects this event to this action"). Think
Expand Down
2 changes: 1 addition & 1 deletion actions/rules/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ type Action interface {
// updated attributes. It returns the new context. Note that this
// needs the new (after change) context and the old value(s) as
// part of the changeset.
OnChange(newContext change.Detector, contextChanges change.Set, configuration string, actionChanges *change.Set) (change.Detector, change.Set, error)
OnChange(newContext change.Detector, contextChanges change.Set, configuration string, actionChanges change.Set) (change.Detector, change.Set, error)
}
6 changes: 3 additions & 3 deletions actions/rules/action_field_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (act ActionFieldSet) storeWorkItem(wi *workitem.WorkItem) (*workitem.WorkIt
}

// OnChange executes the action rule.
func (act ActionFieldSet) OnChange(newContext change.Detector, contextChanges change.Set, configuration string, actionChanges *change.Set) (change.Detector, change.Set, error) {
func (act ActionFieldSet) OnChange(newContext change.Detector, contextChanges change.Set, configuration string, actionChanges change.Set) (change.Detector, change.Set, error) {
// check if the newContext is a WorkItem, fail otherwise.
wiContext, ok := newContext.(workitem.WorkItem)
if !ok {
Expand All @@ -76,7 +76,7 @@ func (act ActionFieldSet) OnChange(newContext change.Detector, contextChanges ch
if !ok {
return nil, nil, errs.New("unknown field name: " + k)
}
*actionChanges = append(*actionChanges, change.Change{
actionChanges = append(actionChanges, change.Change{
AttributeName: k,
NewValue: v,
OldValue: wiContext.Fields[k],
Expand All @@ -100,5 +100,5 @@ func (act ActionFieldSet) OnChange(newContext change.Detector, contextChanges ch
return nil, nil, errs.New("field attribute unknown: " + k)
}
}
return *actionResultContext, *actionChanges, nil
return *actionResultContext, actionChanges, nil
}
10 changes: 5 additions & 5 deletions actions/rules/action_field_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *ActionFieldSetSuite) TestActionExecution() {
}
var convertChanges change.Set
// Not using constants here intentionally.
afterActionWI, convertChanges, err := action.OnChange(newVersion, contextChanges, "{ \"system.state\": \"resolved\" }", &convertChanges)
afterActionWI, convertChanges, err := action.OnChange(newVersion, contextChanges, "{ \"system.state\": \"resolved\" }", convertChanges)
require.NoError(t, err)
require.Len(t, convertChanges, 1)
require.Equal(t, workitem.SystemState, convertChanges[0].AttributeName)
Expand All @@ -79,15 +79,15 @@ func (s *ActionFieldSetSuite) TestActionExecution() {
}
var convertChanges change.Set
// Not using constants here intentionally.
afterActionWI, convertChanges, err := action.OnChange(newVersion, contextChanges, "{ \"system.state\": \"resolved\" }", &convertChanges)
afterActionWI, convertChanges, err := action.OnChange(newVersion, contextChanges, "{ \"system.state\": \"resolved\" }", convertChanges)
require.NoError(t, err)
require.Len(t, convertChanges, 1)
require.Equal(t, workitem.SystemState, convertChanges[0].AttributeName)
require.Equal(t, workitem.SystemStateOpen, convertChanges[0].OldValue)
require.Equal(t, workitem.SystemStateResolved, convertChanges[0].NewValue)
require.Equal(t, workitem.SystemStateResolved, afterActionWI.(workitem.WorkItem).Fields[workitem.SystemState])
// doing another change, the convertChange needs to stack.
afterActionWI, convertChanges, err = action.OnChange(afterActionWI, change.Set{}, "{ \"system.state\": \"new\" }", &convertChanges)
afterActionWI, convertChanges, err = action.OnChange(afterActionWI, change.Set{}, "{ \"system.state\": \"new\" }", convertChanges)
require.NoError(t, err)
require.Len(t, convertChanges, 2)
require.Equal(t, workitem.SystemState, convertChanges[0].AttributeName)
Expand All @@ -112,7 +112,7 @@ func (s *ActionFieldSetSuite) TestActionExecution() {
UserID: &fxt.Identities[0].ID,
}
var convertChanges change.Set
_, _, err = action.OnChange(newVersion, contextChanges, "{ \"system.notavailable\": \"updatedState\" }", &convertChanges)
_, _, err = action.OnChange(newVersion, contextChanges, "{ \"system.notavailable\": \"updatedState\" }", convertChanges)
require.NotNil(t, err)
})

Expand All @@ -129,7 +129,7 @@ func (s *ActionFieldSetSuite) TestActionExecution() {
UserID: &fxt.Identities[0].ID,
}
var convertChanges change.Set
_, convertChanges, err = action.OnChange(newVersion, contextChanges, "someNonJSON", &convertChanges)
_, convertChanges, err = action.OnChange(newVersion, contextChanges, "someNonJSON", convertChanges)
require.NotNil(t, err)
})
}
2 changes: 1 addition & 1 deletion actions/rules/action_nil.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ type ActionNil struct {
var _ Action = ActionNil{}

// OnChange executes the action rule.
func (act ActionNil) OnChange(newContext change.Detector, contextChanges change.Set, configuration string, actionChanges *change.Set) (change.Detector, change.Set, error) {
func (act ActionNil) OnChange(newContext change.Detector, contextChanges change.Set, configuration string, actionChanges change.Set) (change.Detector, change.Set, error) {
return newContext, nil, nil
}
Loading