From 709a3a946a05c9089412be8589e69964ea8a1b9d Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Sun, 31 May 2020 10:38:27 +0200 Subject: [PATCH] Improve auditlog meta handling (support for omitting empty values) --- codegen/v2/actionlog/actions.gen.go.tpl | 13 +- compose/service/access_control_actions.gen.go | 19 +-- compose/service/attachment_actions.gen.go | 65 +++++----- compose/service/chart_actions.gen.go | 51 ++++---- compose/service/module_actions.gen.go | 57 ++++----- compose/service/namespace_actions.gen.go | 43 +++---- compose/service/page_actions.gen.go | 65 +++++----- compose/service/record_actions.gen.go | 67 +++++------ pkg/actionlog/types.go | 111 +++++++++++++++++- pkg/actionlog/types_test.go | 62 ++++++++++ system/service/access_control_actions.gen.go | 19 +-- system/service/application_actions.gen.go | 31 ++--- system/service/attachment_actions.gen.go | 39 +++--- system/service/auth_actions.gen.go | 39 +++--- system/service/reminder_actions.gen.go | 57 ++++----- system/service/role_actions.gen.go | 65 +++++----- system/service/sink_actions.gen.go | 31 ++--- system/service/statistics_actions.gen.go | 11 +- system/service/user_actions.gen.go | 69 +++++------ 19 files changed, 550 insertions(+), 364 deletions(-) create mode 100644 pkg/actionlog/types_test.go diff --git a/codegen/v2/actionlog/actions.gen.go.tpl b/codegen/v2/actionlog/actions.gen.go.tpl index 3219b095a..07a258a09 100644 --- a/codegen/v2/actionlog/actions.gen.go.tpl +++ b/codegen/v2/actionlog/actions.gen.go.tpl @@ -62,6 +62,11 @@ type ( {{ end }} ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -87,19 +92,15 @@ func (p *{{ $.Service }}ActionProps) {{ camelCase "set" $prop.Name }}({{ $prop.N func (p {{ $.Service }}ActionProps) serialize() actionlog.Meta { var ( m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } ) - // avoiding declared but not used - _ = str - {{ range $prop := $.Props }} {{- if $prop.Builtin }} - m["{{ $prop.Name }}"] = str(p.{{ $prop.Name }}) + m.Set("{{ $prop.Name }}", p.{{ $prop.Name }}, true) {{- else }} if p.{{ $prop.Name }} != nil { {{- range $f := $prop.Fields }} - m["{{ $prop.Name }}.{{ $f }}"] = str(p.{{ $prop.Name }}.{{ camelCase " " $f }}) + m.Set("{{ $prop.Name }}.{{ $f }}", p.{{ $prop.Name }}.{{ camelCase " " $f }}, true) {{- end }} } {{- end }} diff --git a/compose/service/access_control_actions.gen.go b/compose/service/access_control_actions.gen.go index 065691c77..8c0205ba2 100644 --- a/compose/service/access_control_actions.gen.go +++ b/compose/service/access_control_actions.gen.go @@ -47,6 +47,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -67,18 +72,14 @@ func (p *accessControlActionProps) setRule(rule *permissions.Rule) *accessContro // func (p accessControlActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.rule != nil { - m["rule.operation"] = str(p.rule.Operation) - m["rule.roleID"] = str(p.rule.RoleID) - m["rule.access"] = str(p.rule.Access) - m["rule.resource"] = str(p.rule.Resource) + m.Set("rule.operation", p.rule.Operation, true) + m.Set("rule.roleID", p.rule.RoleID, true) + m.Set("rule.access", p.rule.Access, true) + m.Set("rule.resource", p.rule.Resource, true) } return m diff --git a/compose/service/attachment_actions.gen.go b/compose/service/attachment_actions.gen.go index 9131f7a08..e42346e6e 100644 --- a/compose/service/attachment_actions.gen.go +++ b/compose/service/attachment_actions.gen.go @@ -56,6 +56,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -175,51 +180,47 @@ func (p *attachmentActionProps) setModule(module *types.Module) *attachmentActio // func (p attachmentActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - - m["size"] = str(p.size) - m["name"] = str(p.name) - m["mimetype"] = str(p.mimetype) - m["url"] = str(p.url) + m.Set("size", p.size, true) + m.Set("name", p.name, true) + m.Set("mimetype", p.mimetype, true) + m.Set("url", p.url, true) if p.attachment != nil { - m["attachment.name"] = str(p.attachment.Name) - m["attachment.kind"] = str(p.attachment.Kind) - m["attachment.url"] = str(p.attachment.Url) - m["attachment.previewUrl"] = str(p.attachment.PreviewUrl) - m["attachment.meta"] = str(p.attachment.Meta) - m["attachment.ownerID"] = str(p.attachment.OwnerID) - m["attachment.ID"] = str(p.attachment.ID) - m["attachment.namespaceID"] = str(p.attachment.NamespaceID) + m.Set("attachment.name", p.attachment.Name, true) + m.Set("attachment.kind", p.attachment.Kind, true) + m.Set("attachment.url", p.attachment.Url, true) + m.Set("attachment.previewUrl", p.attachment.PreviewUrl, true) + m.Set("attachment.meta", p.attachment.Meta, true) + m.Set("attachment.ownerID", p.attachment.OwnerID, true) + m.Set("attachment.ID", p.attachment.ID, true) + m.Set("attachment.namespaceID", p.attachment.NamespaceID, true) } if p.filter != nil { - m["filter.filter"] = str(p.filter.Filter) - m["filter.kind"] = str(p.filter.Kind) - m["filter.sort"] = str(p.filter.Sort) + m.Set("filter.filter", p.filter.Filter, true) + m.Set("filter.kind", p.filter.Kind, true) + m.Set("filter.sort", p.filter.Sort, true) } if p.namespace != nil { - m["namespace.name"] = str(p.namespace.Name) - m["namespace.slug"] = str(p.namespace.Slug) - m["namespace.ID"] = str(p.namespace.ID) + m.Set("namespace.name", p.namespace.Name, true) + m.Set("namespace.slug", p.namespace.Slug, true) + m.Set("namespace.ID", p.namespace.ID, true) } if p.record != nil { - m["record.ID"] = str(p.record.ID) - m["record.moduleID"] = str(p.record.ModuleID) - m["record.namespaceID"] = str(p.record.NamespaceID) + m.Set("record.ID", p.record.ID, true) + m.Set("record.moduleID", p.record.ModuleID, true) + m.Set("record.namespaceID", p.record.NamespaceID, true) } if p.page != nil { - m["page.handle"] = str(p.page.Handle) - m["page.title"] = str(p.page.Title) - m["page.ID"] = str(p.page.ID) + m.Set("page.handle", p.page.Handle, true) + m.Set("page.title", p.page.Title, true) + m.Set("page.ID", p.page.ID, true) } if p.module != nil { - m["module.handle"] = str(p.module.Handle) - m["module.name"] = str(p.module.Name) - m["module.ID"] = str(p.module.ID) + m.Set("module.handle", p.module.Handle, true) + m.Set("module.name", p.module.Name, true) + m.Set("module.ID", p.module.ID, true) } return m diff --git a/compose/service/chart_actions.gen.go b/compose/service/chart_actions.gen.go index 72ace0540..99d93538d 100644 --- a/compose/service/chart_actions.gen.go +++ b/compose/service/chart_actions.gen.go @@ -50,6 +50,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -103,40 +108,36 @@ func (p *chartActionProps) setNamespace(namespace *types.Namespace) *chartAction // func (p chartActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.chart != nil { - m["chart.name"] = str(p.chart.Name) - m["chart.handle"] = str(p.chart.Handle) - m["chart.ID"] = str(p.chart.ID) - m["chart.namespaceID"] = str(p.chart.NamespaceID) + m.Set("chart.name", p.chart.Name, true) + m.Set("chart.handle", p.chart.Handle, true) + m.Set("chart.ID", p.chart.ID, true) + m.Set("chart.namespaceID", p.chart.NamespaceID, true) } if p.changed != nil { - m["changed.name"] = str(p.changed.Name) - m["changed.handle"] = str(p.changed.Handle) - m["changed.ID"] = str(p.changed.ID) - m["changed.namespaceID"] = str(p.changed.NamespaceID) - m["changed.config"] = str(p.changed.Config) + m.Set("changed.name", p.changed.Name, true) + m.Set("changed.handle", p.changed.Handle, true) + m.Set("changed.ID", p.changed.ID, true) + m.Set("changed.namespaceID", p.changed.NamespaceID, true) + m.Set("changed.config", p.changed.Config, true) } if p.filter != nil { - m["filter.query"] = str(p.filter.Query) - m["filter.handle"] = str(p.filter.Handle) - m["filter.namespaceID"] = str(p.filter.NamespaceID) - m["filter.sort"] = str(p.filter.Sort) - m["filter.limit"] = str(p.filter.Limit) - m["filter.offset"] = str(p.filter.Offset) - m["filter.page"] = str(p.filter.Page) - m["filter.perPage"] = str(p.filter.PerPage) + m.Set("filter.query", p.filter.Query, true) + m.Set("filter.handle", p.filter.Handle, true) + m.Set("filter.namespaceID", p.filter.NamespaceID, true) + m.Set("filter.sort", p.filter.Sort, true) + m.Set("filter.limit", p.filter.Limit, true) + m.Set("filter.offset", p.filter.Offset, true) + m.Set("filter.page", p.filter.Page, true) + m.Set("filter.perPage", p.filter.PerPage, true) } if p.namespace != nil { - m["namespace.name"] = str(p.namespace.Name) - m["namespace.slug"] = str(p.namespace.Slug) - m["namespace.ID"] = str(p.namespace.ID) + m.Set("namespace.name", p.namespace.Name, true) + m.Set("namespace.slug", p.namespace.Slug, true) + m.Set("namespace.ID", p.namespace.ID, true) } return m diff --git a/compose/service/module_actions.gen.go b/compose/service/module_actions.gen.go index b24fa78ae..a3abf188b 100644 --- a/compose/service/module_actions.gen.go +++ b/compose/service/module_actions.gen.go @@ -50,6 +50,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -103,43 +108,39 @@ func (p *moduleActionProps) setNamespace(namespace *types.Namespace) *moduleActi // func (p moduleActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.module != nil { - m["module.name"] = str(p.module.Name) - m["module.handle"] = str(p.module.Handle) - m["module.ID"] = str(p.module.ID) - m["module.namespaceID"] = str(p.module.NamespaceID) + m.Set("module.name", p.module.Name, true) + m.Set("module.handle", p.module.Handle, true) + m.Set("module.ID", p.module.ID, true) + m.Set("module.namespaceID", p.module.NamespaceID, true) } if p.changed != nil { - m["changed.name"] = str(p.changed.Name) - m["changed.handle"] = str(p.changed.Handle) - m["changed.ID"] = str(p.changed.ID) - m["changed.namespaceID"] = str(p.changed.NamespaceID) - m["changed.meta"] = str(p.changed.Meta) - m["changed.fields"] = str(p.changed.Fields) + m.Set("changed.name", p.changed.Name, true) + m.Set("changed.handle", p.changed.Handle, true) + m.Set("changed.ID", p.changed.ID, true) + m.Set("changed.namespaceID", p.changed.NamespaceID, true) + m.Set("changed.meta", p.changed.Meta, true) + m.Set("changed.fields", p.changed.Fields, true) } if p.filter != nil { - m["filter.query"] = str(p.filter.Query) - m["filter.name"] = str(p.filter.Name) - m["filter.handle"] = str(p.filter.Handle) - m["filter.name"] = str(p.filter.Name) - m["filter.namespaceID"] = str(p.filter.NamespaceID) - m["filter.sort"] = str(p.filter.Sort) - m["filter.limit"] = str(p.filter.Limit) - m["filter.offset"] = str(p.filter.Offset) - m["filter.page"] = str(p.filter.Page) - m["filter.perPage"] = str(p.filter.PerPage) + m.Set("filter.query", p.filter.Query, true) + m.Set("filter.name", p.filter.Name, true) + m.Set("filter.handle", p.filter.Handle, true) + m.Set("filter.name", p.filter.Name, true) + m.Set("filter.namespaceID", p.filter.NamespaceID, true) + m.Set("filter.sort", p.filter.Sort, true) + m.Set("filter.limit", p.filter.Limit, true) + m.Set("filter.offset", p.filter.Offset, true) + m.Set("filter.page", p.filter.Page, true) + m.Set("filter.perPage", p.filter.PerPage, true) } if p.namespace != nil { - m["namespace.name"] = str(p.namespace.Name) - m["namespace.slug"] = str(p.namespace.Slug) - m["namespace.ID"] = str(p.namespace.ID) + m.Set("namespace.name", p.namespace.Name, true) + m.Set("namespace.slug", p.namespace.Slug, true) + m.Set("namespace.ID", p.namespace.ID, true) } return m diff --git a/compose/service/namespace_actions.gen.go b/compose/service/namespace_actions.gen.go index ef8b29502..6362fc168 100644 --- a/compose/service/namespace_actions.gen.go +++ b/compose/service/namespace_actions.gen.go @@ -49,6 +49,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -91,34 +96,30 @@ func (p *namespaceActionProps) setFilter(filter *types.NamespaceFilter) *namespa // func (p namespaceActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.namespace != nil { - m["namespace.name"] = str(p.namespace.Name) - m["namespace.slug"] = str(p.namespace.Slug) - m["namespace.ID"] = str(p.namespace.ID) - m["namespace.enabled"] = str(p.namespace.Enabled) + m.Set("namespace.name", p.namespace.Name, true) + m.Set("namespace.slug", p.namespace.Slug, true) + m.Set("namespace.ID", p.namespace.ID, true) + m.Set("namespace.enabled", p.namespace.Enabled, true) } if p.changed != nil { - m["changed.name"] = str(p.changed.Name) - m["changed.slug"] = str(p.changed.Slug) - m["changed.ID"] = str(p.changed.ID) - m["changed.meta"] = str(p.changed.Meta) - m["changed.enabled"] = str(p.changed.Enabled) + m.Set("changed.name", p.changed.Name, true) + m.Set("changed.slug", p.changed.Slug, true) + m.Set("changed.ID", p.changed.ID, true) + m.Set("changed.meta", p.changed.Meta, true) + m.Set("changed.enabled", p.changed.Enabled, true) } if p.filter != nil { - m["filter.query"] = str(p.filter.Query) - m["filter.slug"] = str(p.filter.Slug) - m["filter.sort"] = str(p.filter.Sort) - m["filter.limit"] = str(p.filter.Limit) - m["filter.offset"] = str(p.filter.Offset) - m["filter.page"] = str(p.filter.Page) - m["filter.perPage"] = str(p.filter.PerPage) + m.Set("filter.query", p.filter.Query, true) + m.Set("filter.slug", p.filter.Slug, true) + m.Set("filter.sort", p.filter.Sort, true) + m.Set("filter.limit", p.filter.Limit, true) + m.Set("filter.offset", p.filter.Offset, true) + m.Set("filter.page", p.filter.Page, true) + m.Set("filter.perPage", p.filter.PerPage, true) } return m diff --git a/compose/service/page_actions.gen.go b/compose/service/page_actions.gen.go index a80cb6e30..8cc3dcf30 100644 --- a/compose/service/page_actions.gen.go +++ b/compose/service/page_actions.gen.go @@ -50,6 +50,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -103,47 +108,43 @@ func (p *pageActionProps) setNamespace(namespace *types.Namespace) *pageActionPr // func (p pageActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.page != nil { - m["page.title"] = str(p.page.Title) - m["page.handle"] = str(p.page.Handle) - m["page.ID"] = str(p.page.ID) - m["page.namespaceID"] = str(p.page.NamespaceID) - m["page.moduleID"] = str(p.page.ModuleID) + m.Set("page.title", p.page.Title, true) + m.Set("page.handle", p.page.Handle, true) + m.Set("page.ID", p.page.ID, true) + m.Set("page.namespaceID", p.page.NamespaceID, true) + m.Set("page.moduleID", p.page.ModuleID, true) } if p.changed != nil { - m["changed.title"] = str(p.changed.Title) - m["changed.handle"] = str(p.changed.Handle) - m["changed.ID"] = str(p.changed.ID) - m["changed.namespaceID"] = str(p.changed.NamespaceID) - m["changed.description"] = str(p.changed.Description) - m["changed.moduleID"] = str(p.changed.ModuleID) - m["changed.blocks"] = str(p.changed.Blocks) - m["changed.visible"] = str(p.changed.Visible) - m["changed.weight"] = str(p.changed.Weight) + m.Set("changed.title", p.changed.Title, true) + m.Set("changed.handle", p.changed.Handle, true) + m.Set("changed.ID", p.changed.ID, true) + m.Set("changed.namespaceID", p.changed.NamespaceID, true) + m.Set("changed.description", p.changed.Description, true) + m.Set("changed.moduleID", p.changed.ModuleID, true) + m.Set("changed.blocks", p.changed.Blocks, true) + m.Set("changed.visible", p.changed.Visible, true) + m.Set("changed.weight", p.changed.Weight, true) } if p.filter != nil { - m["filter.query"] = str(p.filter.Query) - m["filter.handle"] = str(p.filter.Handle) - m["filter.root"] = str(p.filter.Root) - m["filter.namespaceID"] = str(p.filter.NamespaceID) - m["filter.parentID"] = str(p.filter.ParentID) - m["filter.sort"] = str(p.filter.Sort) - m["filter.limit"] = str(p.filter.Limit) - m["filter.offset"] = str(p.filter.Offset) - m["filter.page"] = str(p.filter.Page) - m["filter.perPage"] = str(p.filter.PerPage) + m.Set("filter.query", p.filter.Query, true) + m.Set("filter.handle", p.filter.Handle, true) + m.Set("filter.root", p.filter.Root, true) + m.Set("filter.namespaceID", p.filter.NamespaceID, true) + m.Set("filter.parentID", p.filter.ParentID, true) + m.Set("filter.sort", p.filter.Sort, true) + m.Set("filter.limit", p.filter.Limit, true) + m.Set("filter.offset", p.filter.Offset, true) + m.Set("filter.page", p.filter.Page, true) + m.Set("filter.perPage", p.filter.PerPage, true) } if p.namespace != nil { - m["namespace.name"] = str(p.namespace.Name) - m["namespace.slug"] = str(p.namespace.Slug) - m["namespace.ID"] = str(p.namespace.ID) + m.Set("namespace.name", p.namespace.Name, true) + m.Set("namespace.slug", p.namespace.Slug, true) + m.Set("namespace.ID", p.namespace.ID, true) } return m diff --git a/compose/service/record_actions.gen.go b/compose/service/record_actions.gen.go index 9df78c3f7..521a09e7a 100644 --- a/compose/service/record_actions.gen.go +++ b/compose/service/record_actions.gen.go @@ -55,6 +55,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -163,52 +168,48 @@ func (p *recordActionProps) setValueErrors(valueErrors *types.RecordValueErrorSe // func (p recordActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.record != nil { - m["record.ID"] = str(p.record.ID) - m["record.moduleID"] = str(p.record.ModuleID) - m["record.namespaceID"] = str(p.record.NamespaceID) - m["record.ownedBy"] = str(p.record.OwnedBy) + m.Set("record.ID", p.record.ID, true) + m.Set("record.moduleID", p.record.ModuleID, true) + m.Set("record.namespaceID", p.record.NamespaceID, true) + m.Set("record.ownedBy", p.record.OwnedBy, true) } if p.changed != nil { - m["changed.ID"] = str(p.changed.ID) - m["changed.moduleID"] = str(p.changed.ModuleID) - m["changed.namespaceID"] = str(p.changed.NamespaceID) - m["changed.ownedBy"] = str(p.changed.OwnedBy) + m.Set("changed.ID", p.changed.ID, true) + m.Set("changed.moduleID", p.changed.ModuleID, true) + m.Set("changed.namespaceID", p.changed.NamespaceID, true) + m.Set("changed.ownedBy", p.changed.OwnedBy, true) } if p.filter != nil { - m["filter.query"] = str(p.filter.Query) - m["filter.namespaceID"] = str(p.filter.NamespaceID) - m["filter.moduleID"] = str(p.filter.ModuleID) - m["filter.deleted"] = str(p.filter.Deleted) - m["filter.sort"] = str(p.filter.Sort) - m["filter.limit"] = str(p.filter.Limit) - m["filter.offset"] = str(p.filter.Offset) - m["filter.page"] = str(p.filter.Page) - m["filter.perPage"] = str(p.filter.PerPage) + m.Set("filter.query", p.filter.Query, true) + m.Set("filter.namespaceID", p.filter.NamespaceID, true) + m.Set("filter.moduleID", p.filter.ModuleID, true) + m.Set("filter.deleted", p.filter.Deleted, true) + m.Set("filter.sort", p.filter.Sort, true) + m.Set("filter.limit", p.filter.Limit, true) + m.Set("filter.offset", p.filter.Offset, true) + m.Set("filter.page", p.filter.Page, true) + m.Set("filter.perPage", p.filter.PerPage, true) } if p.namespace != nil { - m["namespace.name"] = str(p.namespace.Name) - m["namespace.slug"] = str(p.namespace.Slug) - m["namespace.ID"] = str(p.namespace.ID) + m.Set("namespace.name", p.namespace.Name, true) + m.Set("namespace.slug", p.namespace.Slug, true) + m.Set("namespace.ID", p.namespace.ID, true) } if p.module != nil { - m["module.name"] = str(p.module.Name) - m["module.handle"] = str(p.module.Handle) - m["module.ID"] = str(p.module.ID) - m["module.namespaceID"] = str(p.module.NamespaceID) + m.Set("module.name", p.module.Name, true) + m.Set("module.handle", p.module.Handle, true) + m.Set("module.ID", p.module.ID, true) + m.Set("module.namespaceID", p.module.NamespaceID, true) } - m["bulkOperation"] = str(p.bulkOperation) - m["field"] = str(p.field) - m["value"] = str(p.value) + m.Set("bulkOperation", p.bulkOperation, true) + m.Set("field", p.field, true) + m.Set("value", p.value, true) if p.valueErrors != nil { - m["valueErrors.set"] = str(p.valueErrors.Set) + m.Set("valueErrors.set", p.valueErrors.Set, true) } return m diff --git a/pkg/actionlog/types.go b/pkg/actionlog/types.go index c9ab20f5d..b979d134e 100644 --- a/pkg/actionlog/types.go +++ b/pkg/actionlog/types.go @@ -1,14 +1,15 @@ package actionlog import ( - "github.com/cortezaproject/corteza-server/pkg/rh" "time" + + "github.com/cortezaproject/corteza-server/pkg/rh" ) type ( // Any additional data // that can be packed with the raised audit event - Meta map[string]string + Meta map[string]interface{} // Severity determinants event severity level Severity uint8 @@ -63,6 +64,10 @@ type ( // Standard paging fields & helpers rh.PageFilter } + + loggableMetaValue interface { + ActionLogMetaValue() (interface{}, bool) + } ) const ( @@ -79,3 +84,105 @@ const ( ) func (a *Action) LoggableAction() *Action { return a } + +// Set value as key to meta, or skip it if value is empty (and omitempty is set) +func (m Meta) Set(key string, in interface{}, omitempty bool) { + // if value has fn() ActionLogMetaValue that can + // reformat value and (maybe) omit empty values, call that first + if lmv, is := in.(loggableMetaValue); is { + if v, empty := lmv.ActionLogMetaValue(); !omitempty || !empty { + m[key] = v + } + + return + } + + if !omitempty { + // Nothing special, + // assign value and quit + m[key] = in + return + } + + // for the rest, we need to determine what kind of + + if str, is := in.(string); is { + if !omitempty || len(str) > 0 { + m[key] = str + } + + return + } + + if bb, is := in.([]byte); is { + if !omitempty || len(bb) > 0 { + m[key] = bb + } + + return + } + + if b, is := in.(bool); is { + m[key] = b + return + } + + // cast to (int|uint|float)64 + num := func(n interface{}) interface{} { + switch n := n.(type) { + case int: + return int64(n) + case int8: + return int64(n) + case int16: + return int64(n) + case int32: + return int64(n) + case int64: + return n + case uint: + return uint64(n) + case uintptr: + return uint64(n) + case uint8: + return uint64(n) + case uint16: + return uint64(n) + case uint32: + return uint64(n) + case uint64: + return n + case float32: + return float64(n) + case float64: + return n + } + return n + }(in) + + switch num := num.(type) { + case nil: + case uint64: + if !omitempty || num > 0 { + m[key] = in + } + return + + case int64: + if !omitempty || num > 0 { + m[key] = in + } + return + + case float64: + if !omitempty || num > 0 { + m[key] = in + } + + return + } + + // for the rest (slices, etc..) + // just set the value + m[key] = in +} diff --git a/pkg/actionlog/types_test.go b/pkg/actionlog/types_test.go new file mode 100644 index 000000000..4ec1052d8 --- /dev/null +++ b/pkg/actionlog/types_test.go @@ -0,0 +1,62 @@ +package actionlog + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +type ( + metaFoo struct{ val string } + metaBar struct{ val string } +) + +func (f metaFoo) ActionLogMetaValue() (interface{}, bool) { + return strings.ToUpper(f.val), len(f.val) == 0 +} + +func TestMeta_Set(t *testing.T) { + tests := []struct { + name string + val interface{} + omitempty bool + out Meta + }{ + {"string value, omit", "str", true, Meta{"t": "str"}}, + {"string value, keep", "str", false, Meta{"t": "str"}}, + {"string empty, omit", "", true, Meta{}}, + {"string empty, keep", "", false, Meta{"t": ""}}, + + {"byte value, omit", []byte{'b', 'y', 't', 'e'}, true, Meta{"t": []byte{'b', 'y', 't', 'e'}}}, + {"byte value, keep", []byte{'b', 'y', 't', 'e'}, false, Meta{"t": []byte{'b', 'y', 't', 'e'}}}, + {"byte empty, omit", []byte{}, true, Meta{}}, + {"byte empty, keep", []byte{}, false, Meta{"t": []byte{}}}, + + {"bool true", true, false, Meta{"t": true}}, + {"bool false", false, false, Meta{"t": false}}, + + {"int value, omit", 1, true, Meta{"t": 1}}, + {"int value, keep", 1, false, Meta{"t": 1}}, + {"int empty, omit", 0, true, Meta{}}, + {"int empty, keep", 0, false, Meta{"t": 0}}, + + {"slice", []int{0, 1}, false, Meta{"t": []int{0, 1}}}, + + {"meta foo", metaFoo{"value"}, false, Meta{"t": "VALUE"}}, + {"meta foo, omit", metaFoo{""}, true, Meta{}}, + // @todo raw + {"meta bar", metaBar{"value"}, false, Meta{"t": metaBar{"value"}}}, + {"meta bar", metaBar{}, true, Meta{"t": metaBar{""}}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + a := assert.New(t) + m := make(Meta) + m.Set("t", tt.val, tt.omitempty) + if !a.Equal(tt.out, m) { + t.Fail() + } + }) + } +} diff --git a/system/service/access_control_actions.gen.go b/system/service/access_control_actions.gen.go index bcd79a647..3495d4c5a 100644 --- a/system/service/access_control_actions.gen.go +++ b/system/service/access_control_actions.gen.go @@ -47,6 +47,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -67,18 +72,14 @@ func (p *accessControlActionProps) setRule(rule *permissions.Rule) *accessContro // func (p accessControlActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.rule != nil { - m["rule.operation"] = str(p.rule.Operation) - m["rule.roleID"] = str(p.rule.RoleID) - m["rule.access"] = str(p.rule.Access) - m["rule.resource"] = str(p.rule.Resource) + m.Set("rule.operation", p.rule.Operation, true) + m.Set("rule.roleID", p.rule.RoleID, true) + m.Set("rule.access", p.rule.Access, true) + m.Set("rule.resource", p.rule.Resource, true) } return m diff --git a/system/service/application_actions.gen.go b/system/service/application_actions.gen.go index 78047f761..218ce09f1 100644 --- a/system/service/application_actions.gen.go +++ b/system/service/application_actions.gen.go @@ -50,6 +50,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -103,30 +108,26 @@ func (p *applicationActionProps) setFilter(filter *types.ApplicationFilter) *app // func (p applicationActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.application != nil { - m["application.name"] = str(p.application.Name) - m["application.ID"] = str(p.application.ID) + m.Set("application.name", p.application.Name, true) + m.Set("application.ID", p.application.ID, true) } if p.new != nil { - m["new.name"] = str(p.new.Name) - m["new.ID"] = str(p.new.ID) + m.Set("new.name", p.new.Name, true) + m.Set("new.ID", p.new.ID, true) } if p.update != nil { - m["update.name"] = str(p.update.Name) - m["update.ID"] = str(p.update.ID) + m.Set("update.name", p.update.Name, true) + m.Set("update.ID", p.update.ID, true) } if p.filter != nil { - m["filter.query"] = str(p.filter.Query) - m["filter.name"] = str(p.filter.Name) - m["filter.deleted"] = str(p.filter.Deleted) - m["filter.sort"] = str(p.filter.Sort) + m.Set("filter.query", p.filter.Query, true) + m.Set("filter.name", p.filter.Name, true) + m.Set("filter.deleted", p.filter.Deleted, true) + m.Set("filter.sort", p.filter.Sort, true) } return m diff --git a/system/service/attachment_actions.gen.go b/system/service/attachment_actions.gen.go index 0863050b1..fcd5fe424 100644 --- a/system/service/attachment_actions.gen.go +++ b/system/service/attachment_actions.gen.go @@ -52,6 +52,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -127,30 +132,26 @@ func (p *attachmentActionProps) setFilter(filter *types.AttachmentFilter) *attac // func (p attachmentActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - - m["size"] = str(p.size) - m["name"] = str(p.name) - m["mimetype"] = str(p.mimetype) - m["url"] = str(p.url) + m.Set("size", p.size, true) + m.Set("name", p.name, true) + m.Set("mimetype", p.mimetype, true) + m.Set("url", p.url, true) if p.attachment != nil { - m["attachment.name"] = str(p.attachment.Name) - m["attachment.kind"] = str(p.attachment.Kind) - m["attachment.url"] = str(p.attachment.Url) - m["attachment.previewUrl"] = str(p.attachment.PreviewUrl) - m["attachment.meta"] = str(p.attachment.Meta) - m["attachment.ownerID"] = str(p.attachment.OwnerID) - m["attachment.ID"] = str(p.attachment.ID) + m.Set("attachment.name", p.attachment.Name, true) + m.Set("attachment.kind", p.attachment.Kind, true) + m.Set("attachment.url", p.attachment.Url, true) + m.Set("attachment.previewUrl", p.attachment.PreviewUrl, true) + m.Set("attachment.meta", p.attachment.Meta, true) + m.Set("attachment.ownerID", p.attachment.OwnerID, true) + m.Set("attachment.ID", p.attachment.ID, true) } if p.filter != nil { - m["filter.filter"] = str(p.filter.Filter) - m["filter.kind"] = str(p.filter.Kind) - m["filter.sort"] = str(p.filter.Sort) + m.Set("filter.filter", p.filter.Filter, true) + m.Set("filter.kind", p.filter.Kind, true) + m.Set("filter.sort", p.filter.Sort, true) } return m diff --git a/system/service/auth_actions.gen.go b/system/service/auth_actions.gen.go index 996cf1f30..a9831c63b 100644 --- a/system/service/auth_actions.gen.go +++ b/system/service/auth_actions.gen.go @@ -51,6 +51,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -115,32 +120,28 @@ func (p *authActionProps) setUser(user *types.User) *authActionProps { // func (p authActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - - m["email"] = str(p.email) - m["provider"] = str(p.provider) + m.Set("email", p.email, true) + m.Set("provider", p.provider, true) if p.credentials != nil { - m["credentials.kind"] = str(p.credentials.Kind) - m["credentials.label"] = str(p.credentials.Label) - m["credentials.ID"] = str(p.credentials.ID) + m.Set("credentials.kind", p.credentials.Kind, true) + m.Set("credentials.label", p.credentials.Label, true) + m.Set("credentials.ID", p.credentials.ID, true) } if p.role != nil { - m["role.handle"] = str(p.role.Handle) - m["role.name"] = str(p.role.Name) - m["role.ID"] = str(p.role.ID) + m.Set("role.handle", p.role.Handle, true) + m.Set("role.name", p.role.Name, true) + m.Set("role.ID", p.role.ID, true) } if p.user != nil { - m["user.handle"] = str(p.user.Handle) - m["user.name"] = str(p.user.Name) - m["user.ID"] = str(p.user.ID) - m["user.email"] = str(p.user.Email) - m["user.suspendedAt"] = str(p.user.SuspendedAt) - m["user.deletedAt"] = str(p.user.DeletedAt) + m.Set("user.handle", p.user.Handle, true) + m.Set("user.name", p.user.Name, true) + m.Set("user.ID", p.user.ID, true) + m.Set("user.email", p.user.Email, true) + m.Set("user.suspendedAt", p.user.SuspendedAt, true) + m.Set("user.deletedAt", p.user.DeletedAt, true) } return m diff --git a/system/service/reminder_actions.gen.go b/system/service/reminder_actions.gen.go index 06881b08c..01d2fe22e 100644 --- a/system/service/reminder_actions.gen.go +++ b/system/service/reminder_actions.gen.go @@ -50,6 +50,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -103,43 +108,39 @@ func (p *reminderActionProps) setFilter(filter *types.ReminderFilter) *reminderA // func (p reminderActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.reminder != nil { - m["reminder.resource"] = str(p.reminder.Resource) - m["reminder.ID"] = str(p.reminder.ID) - m["reminder.assignedTo"] = str(p.reminder.AssignedTo) - m["reminder.assignedBy"] = str(p.reminder.AssignedBy) - m["reminder.remindAt"] = str(p.reminder.RemindAt) + m.Set("reminder.resource", p.reminder.Resource, true) + m.Set("reminder.ID", p.reminder.ID, true) + m.Set("reminder.assignedTo", p.reminder.AssignedTo, true) + m.Set("reminder.assignedBy", p.reminder.AssignedBy, true) + m.Set("reminder.remindAt", p.reminder.RemindAt, true) } if p.new != nil { - m["new.resource"] = str(p.new.Resource) - m["new.ID"] = str(p.new.ID) - m["new.assignedTo"] = str(p.new.AssignedTo) - m["new.assignedBy"] = str(p.new.AssignedBy) - m["new.remindAt"] = str(p.new.RemindAt) + m.Set("new.resource", p.new.Resource, true) + m.Set("new.ID", p.new.ID, true) + m.Set("new.assignedTo", p.new.AssignedTo, true) + m.Set("new.assignedBy", p.new.AssignedBy, true) + m.Set("new.remindAt", p.new.RemindAt, true) } if p.updated != nil { - m["updated.resource"] = str(p.updated.Resource) - m["updated.ID"] = str(p.updated.ID) - m["updated.assignedTo"] = str(p.updated.AssignedTo) - m["updated.assignedBy"] = str(p.updated.AssignedBy) - m["updated.remindAt"] = str(p.updated.RemindAt) + m.Set("updated.resource", p.updated.Resource, true) + m.Set("updated.ID", p.updated.ID, true) + m.Set("updated.assignedTo", p.updated.AssignedTo, true) + m.Set("updated.assignedBy", p.updated.AssignedBy, true) + m.Set("updated.remindAt", p.updated.RemindAt, true) } if p.filter != nil { - m["filter.resource"] = str(p.filter.Resource) - m["filter.reminderID"] = str(p.filter.ReminderID) - m["filter.assignedTo"] = str(p.filter.AssignedTo) - m["filter.scheduledFrom"] = str(p.filter.ScheduledFrom) - m["filter.scheduledUntil"] = str(p.filter.ScheduledUntil) - m["filter.excludeDismissed"] = str(p.filter.ExcludeDismissed) - m["filter.scheduledOnly"] = str(p.filter.ScheduledOnly) - m["filter.sort"] = str(p.filter.Sort) + m.Set("filter.resource", p.filter.Resource, true) + m.Set("filter.reminderID", p.filter.ReminderID, true) + m.Set("filter.assignedTo", p.filter.AssignedTo, true) + m.Set("filter.scheduledFrom", p.filter.ScheduledFrom, true) + m.Set("filter.scheduledUntil", p.filter.ScheduledUntil, true) + m.Set("filter.excludeDismissed", p.filter.ExcludeDismissed, true) + m.Set("filter.scheduledOnly", p.filter.ScheduledOnly, true) + m.Set("filter.sort", p.filter.Sort, true) } return m diff --git a/system/service/role_actions.gen.go b/system/service/role_actions.gen.go index 13092e986..4e7314ad9 100644 --- a/system/service/role_actions.gen.go +++ b/system/service/role_actions.gen.go @@ -53,6 +53,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -139,53 +144,49 @@ func (p *roleActionProps) setFilter(filter *types.RoleFilter) *roleActionProps { // func (p roleActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.member != nil { - m["member.handle"] = str(p.member.Handle) - m["member.email"] = str(p.member.Email) - m["member.name"] = str(p.member.Name) - m["member.ID"] = str(p.member.ID) + m.Set("member.handle", p.member.Handle, true) + m.Set("member.email", p.member.Email, true) + m.Set("member.name", p.member.Name, true) + m.Set("member.ID", p.member.ID, true) } if p.role != nil { - m["role.handle"] = str(p.role.Handle) - m["role.name"] = str(p.role.Name) - m["role.ID"] = str(p.role.ID) + m.Set("role.handle", p.role.Handle, true) + m.Set("role.name", p.role.Name, true) + m.Set("role.ID", p.role.ID, true) } if p.new != nil { - m["new.handle"] = str(p.new.Handle) - m["new.name"] = str(p.new.Name) - m["new.ID"] = str(p.new.ID) + m.Set("new.handle", p.new.Handle, true) + m.Set("new.name", p.new.Name, true) + m.Set("new.ID", p.new.ID, true) } if p.update != nil { - m["update.handle"] = str(p.update.Handle) - m["update.name"] = str(p.update.Name) - m["update.ID"] = str(p.update.ID) + m.Set("update.handle", p.update.Handle, true) + m.Set("update.name", p.update.Name, true) + m.Set("update.ID", p.update.ID, true) } if p.existing != nil { - m["existing.handle"] = str(p.existing.Handle) - m["existing.name"] = str(p.existing.Name) - m["existing.ID"] = str(p.existing.ID) + m.Set("existing.handle", p.existing.Handle, true) + m.Set("existing.name", p.existing.Name, true) + m.Set("existing.ID", p.existing.ID, true) } if p.target != nil { - m["target.handle"] = str(p.target.Handle) - m["target.name"] = str(p.target.Name) - m["target.ID"] = str(p.target.ID) + m.Set("target.handle", p.target.Handle, true) + m.Set("target.name", p.target.Name, true) + m.Set("target.ID", p.target.ID, true) } if p.filter != nil { - m["filter.query"] = str(p.filter.Query) - m["filter.roleID"] = str(p.filter.RoleID) - m["filter.memberID"] = str(p.filter.MemberID) - m["filter.handle"] = str(p.filter.Handle) - m["filter.name"] = str(p.filter.Name) - m["filter.deleted"] = str(p.filter.Deleted) - m["filter.archived"] = str(p.filter.Archived) - m["filter.sort"] = str(p.filter.Sort) + m.Set("filter.query", p.filter.Query, true) + m.Set("filter.roleID", p.filter.RoleID, true) + m.Set("filter.memberID", p.filter.MemberID, true) + m.Set("filter.handle", p.filter.Handle, true) + m.Set("filter.name", p.filter.Name, true) + m.Set("filter.deleted", p.filter.Deleted, true) + m.Set("filter.archived", p.filter.Archived, true) + m.Set("filter.sort", p.filter.Sort, true) } return m diff --git a/system/service/sink_actions.gen.go b/system/service/sink_actions.gen.go index 2d228f0dc..296bb1370 100644 --- a/system/service/sink_actions.gen.go +++ b/system/service/sink_actions.gen.go @@ -54,6 +54,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -118,24 +123,20 @@ func (p *sinkActionProps) setMailHeader(mailHeader *types.MailMessageHeader) *si // func (p sinkActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - - m["url"] = str(p.url) - m["responseStatus"] = str(p.responseStatus) - m["contentType"] = str(p.contentType) - m["sinkParams"] = str(p.sinkParams) + m.Set("url", p.url, true) + m.Set("responseStatus", p.responseStatus, true) + m.Set("contentType", p.contentType, true) + m.Set("sinkParams", p.sinkParams, true) if p.mailHeader != nil { - m["mailHeader.to"] = str(p.mailHeader.To) - m["mailHeader.CC"] = str(p.mailHeader.CC) - m["mailHeader.BCC"] = str(p.mailHeader.BCC) - m["mailHeader.from"] = str(p.mailHeader.From) - m["mailHeader.replyTo"] = str(p.mailHeader.ReplyTo) - m["mailHeader.raw"] = str(p.mailHeader.Raw) + m.Set("mailHeader.to", p.mailHeader.To, true) + m.Set("mailHeader.CC", p.mailHeader.CC, true) + m.Set("mailHeader.BCC", p.mailHeader.BCC, true) + m.Set("mailHeader.from", p.mailHeader.From, true) + m.Set("mailHeader.replyTo", p.mailHeader.ReplyTo, true) + m.Set("mailHeader.raw", p.mailHeader.Raw, true) } return m diff --git a/system/service/statistics_actions.gen.go b/system/service/statistics_actions.gen.go index 44de24c97..58075db3d 100644 --- a/system/service/statistics_actions.gen.go +++ b/system/service/statistics_actions.gen.go @@ -45,6 +45,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -55,13 +60,9 @@ type ( // func (p statisticsActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - return m } diff --git a/system/service/user_actions.gen.go b/system/service/user_actions.gen.go index 008ba7c99..138206ace 100644 --- a/system/service/user_actions.gen.go +++ b/system/service/user_actions.gen.go @@ -51,6 +51,11 @@ type ( } ) +var ( + // just a placeholder to cover template cases w/o fmt package use + _ = fmt.Println +) + // ********************************************************************************************************************* // ********************************************************************************************************************* // Props methods @@ -115,51 +120,47 @@ func (p *userActionProps) setFilter(filter *types.UserFilter) *userActionProps { // func (p userActionProps) serialize() actionlog.Meta { var ( - m = make(actionlog.Meta) - str = func(i interface{}) string { return fmt.Sprintf("%v", i) } + m = make(actionlog.Meta) ) - // avoiding declared but not used - _ = str - if p.user != nil { - m["user.handle"] = str(p.user.Handle) - m["user.email"] = str(p.user.Email) - m["user.name"] = str(p.user.Name) - m["user.username"] = str(p.user.Username) - m["user.ID"] = str(p.user.ID) + m.Set("user.handle", p.user.Handle, true) + m.Set("user.email", p.user.Email, true) + m.Set("user.name", p.user.Name, true) + m.Set("user.username", p.user.Username, true) + m.Set("user.ID", p.user.ID, true) } if p.new != nil { - m["new.handle"] = str(p.new.Handle) - m["new.email"] = str(p.new.Email) - m["new.name"] = str(p.new.Name) - m["new.username"] = str(p.new.Username) - m["new.ID"] = str(p.new.ID) + m.Set("new.handle", p.new.Handle, true) + m.Set("new.email", p.new.Email, true) + m.Set("new.name", p.new.Name, true) + m.Set("new.username", p.new.Username, true) + m.Set("new.ID", p.new.ID, true) } if p.update != nil { - m["update.handle"] = str(p.update.Handle) - m["update.email"] = str(p.update.Email) - m["update.name"] = str(p.update.Name) - m["update.username"] = str(p.update.Username) - m["update.ID"] = str(p.update.ID) + m.Set("update.handle", p.update.Handle, true) + m.Set("update.email", p.update.Email, true) + m.Set("update.name", p.update.Name, true) + m.Set("update.username", p.update.Username, true) + m.Set("update.ID", p.update.ID, true) } if p.existing != nil { - m["existing.handle"] = str(p.existing.Handle) - m["existing.email"] = str(p.existing.Email) - m["existing.name"] = str(p.existing.Name) - m["existing.username"] = str(p.existing.Username) - m["existing.ID"] = str(p.existing.ID) + m.Set("existing.handle", p.existing.Handle, true) + m.Set("existing.email", p.existing.Email, true) + m.Set("existing.name", p.existing.Name, true) + m.Set("existing.username", p.existing.Username, true) + m.Set("existing.ID", p.existing.ID, true) } if p.filter != nil { - m["filter.query"] = str(p.filter.Query) - m["filter.userID"] = str(p.filter.UserID) - m["filter.roleID"] = str(p.filter.RoleID) - m["filter.handle"] = str(p.filter.Handle) - m["filter.email"] = str(p.filter.Email) - m["filter.username"] = str(p.filter.Username) - m["filter.deleted"] = str(p.filter.Deleted) - m["filter.suspended"] = str(p.filter.Suspended) - m["filter.sort"] = str(p.filter.Sort) + m.Set("filter.query", p.filter.Query, true) + m.Set("filter.userID", p.filter.UserID, true) + m.Set("filter.roleID", p.filter.RoleID, true) + m.Set("filter.handle", p.filter.Handle, true) + m.Set("filter.email", p.filter.Email, true) + m.Set("filter.username", p.filter.Username, true) + m.Set("filter.deleted", p.filter.Deleted, true) + m.Set("filter.suspended", p.filter.Suspended, true) + m.Set("filter.sort", p.filter.Sort, true) } return m