From 263ddeaaf79505c8df182ad036c94277716b272a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20B=C3=A9trancourt?= Date: Tue, 2 May 2023 16:43:38 +0200 Subject: [PATCH] feat(task): allow to get watchers (#439) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #188 Signed-off-by: Thomas Bétrancourt --- models/task/task.go | 8 +++++++- models/tasktemplate/validate.go | 17 +++++++++-------- utask.go | 3 +++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/models/task/task.go b/models/task/task.go index 2e3e25e0..3d668266 100644 --- a/models/task/task.go +++ b/models/task/task.go @@ -666,12 +666,18 @@ func (t *Task) ExportTaskInfos(values *values.Values) { m["task_id"] = t.PublicID m["created"] = t.Created m["requester_username"] = t.RequesterUsername - if t.RequesterGroups != nil && len(t.RequesterGroups) > 0 { + if len(t.RequesterGroups) > 0 { m["requester_groups"] = strings.Join(t.RequesterGroups, utask.GroupsSeparator) } if t.ResolverUsername != nil { m["resolver_username"] = t.ResolverUsername } + if len(t.WatcherUsernames) > 0 { + m["watcher_usernames"] = strings.Join(t.WatcherUsernames, utask.UsernamesSeparator) + } + if len(t.WatcherGroups) > 0 { + m["watcher_groups"] = strings.Join(t.WatcherGroups, utask.GroupsSeparator) + } m["last_activity"] = t.LastActivity m["region"] = utask.FRegion if t.Resolution != nil { diff --git a/models/tasktemplate/validate.go b/models/tasktemplate/validate.go index 067ed79c..55a4593e 100644 --- a/models/tasktemplate/validate.go +++ b/models/tasktemplate/validate.go @@ -31,7 +31,7 @@ func validTemplate(template string, inputs, resolverInputs []string, steps map[s } stepNames := stepNames(steps) - taskInfoKeys := []string{"resolver_username", "created", "requester_username", "requester_groups", "task_id", "region", "resolution_id"} + taskInfoKeys := []string{"resolver_username", "created", "requester_username", "requester_groups", "task_id", "region", "resolution_id", "watcher_usernames", "watcher_groups"} for _, m := range matches { parts := strings.Split(m[1], ".") if len(parts) >= 3 { @@ -138,13 +138,14 @@ func stepNames(stepMap map[string]*step.Step) []string { // tryVariablePath tries to match a chain of variables with the given properties. // For example: -// given properties = map[foo:[bar] bar:[bar] qux:[foo] utaskRootKey:[qux]] -// and parts = [qux foo bar bar bar] -// "qux.foo.bar.bar.bar" is valid since "qux" makes "foo", "foo" makes "bar" -// and "bar" makes "bar". -// "qux.foo.bar.foo" is not valid since we cannot make "foo" from "bar". -// "foo.bar.bar" is not valid either since we start looping on parts using -// utaskRootKey map, which contains root properties of the json schema. +// +// given properties = map[foo:[bar] bar:[bar] qux:[foo] utaskRootKey:[qux]] +// and parts = [qux foo bar bar bar] +// "qux.foo.bar.bar.bar" is valid since "qux" makes "foo", "foo" makes "bar" +// and "bar" makes "bar". +// "qux.foo.bar.foo" is not valid since we cannot make "foo" from "bar". +// "foo.bar.bar" is not valid either since we start looping on parts using +// utaskRootKey map, which contains root properties of the json schema. func tryVariablePath(properties map[string][]string, parts []string) error { // start with root properties lastKey := jsonschema.RootKey diff --git a/utask.go b/utask.go index 09682ba1..f296312a 100644 --- a/utask.go +++ b/utask.go @@ -101,6 +101,9 @@ const ( // NotificationStrategyFailureOnly corresponds to the mode where notifications will only be sent if the state is BLOCKED NotificationStrategyFailureOnly = "failure_only" + // UsernamesSeparator corresponds to the separator used to break a string into a list of usernames and vice versa. + UsernamesSeparator = "," + // GroupsSeparator corresponds to the separator used to break a string into a list of groups and vice versa. GroupsSeparator = ","