diff --git a/internal/common/eventmanager.go b/internal/common/eventmanager.go index ce15e68f..5d1e9718 100644 --- a/internal/common/eventmanager.go +++ b/internal/common/eventmanager.go @@ -782,6 +782,13 @@ func (*EventParams) getStringReplacement(val string, jsonEscaped bool) string { } func (p *EventParams) getStringReplacements(addObjectData, jsonEscaped bool) []string { + dateTimeString := p.Timestamp.UTC().Format(dateTimeMillisFormat) + year := dateTimeString[0:4] + month := dateTimeString[5:7] + day := dateTimeString[8:10] + hour := dateTimeString[11:13] + minute := dateTimeString[14:16] + replacements := []string{ "{{Name}}", p.getStringReplacement(p.Name, jsonEscaped), "{{Event}}", p.Event, @@ -800,7 +807,12 @@ func (p *EventParams) getStringReplacements(addObjectData, jsonEscaped bool) []s "{{Role}}", p.getStringReplacement(p.Role, jsonEscaped), "{{Email}}", p.getStringReplacement(p.Email, jsonEscaped), "{{Timestamp}}", strconv.FormatInt(p.Timestamp.UnixNano(), 10), - "{{DateTime}}", p.Timestamp.UTC().Format(dateTimeMillisFormat), + "{{DateTime}}", dateTimeString, + "{{Year}}", year, + "{{Month}}", month, + "{{Day}}", day, + "{{Hour}}", hour, + "{{Minute}}", minute, "{{StatusString}}", p.getStatusString(), "{{UID}}", p.getStringReplacement(p.UID, jsonEscaped), "{{Ext}}", p.getStringReplacement(p.Extension, jsonEscaped), diff --git a/internal/common/eventmanager_test.go b/internal/common/eventmanager_test.go index 72261bfe..2d73b6bb 100644 --- a/internal/common/eventmanager_test.go +++ b/internal/common/eventmanager_test.go @@ -809,6 +809,8 @@ func TestDateTimePlaceholder(t *testing.T) { r := strings.NewReplacer(replacements...) res := r.Replace("{{DateTime}}") assert.Equal(t, dateTime.UTC().Format(dateTimeMillisFormat), res) + res = r.Replace("{{Year}}-{{Month}}-{{Day}}T{{Hour}}:{{Minute}}") + assert.Equal(t, dateTime.UTC().Format(dateTimeMillisFormat)[:16], res) } func TestEventRuleActions(t *testing.T) { diff --git a/static/locales/en/translation.json b/static/locales/en/translation.json index f4984525..31a68cae 100644 --- a/static/locales/en/translation.json +++ b/static/locales/en/translation.json @@ -1045,6 +1045,11 @@ "role": "User or admin role", "timestamp": "Event timestamp as nanoseconds since epoch", "datetime": "Event timestamp formatted as YYYY-MM-DDTHH:MM:SS.ZZZ", + "year": "Event year formatted as four digits", + "month": "Event month formatted as two digits", + "day": "Event day formatted as two digits", + "hour": "Event hour formatted as two digits", + "minute": "Event minute formatted as two digits", "email": "For filesystem events, this is the email associated with the user performing the action. For the provider events, this is the email associated with the affected user or admin. Blank in all other cases", "object_data": "Provider object data serialized as JSON with sensitive fields removed", "object_data_string": "Provider object data as JSON escaped string with sensitive fields removed", diff --git a/static/locales/it/translation.json b/static/locales/it/translation.json index 6515af38..5dd81dd4 100644 --- a/static/locales/it/translation.json +++ b/static/locales/it/translation.json @@ -1045,6 +1045,11 @@ "role": "Ruolo dell'utente o dell'amministratore", "timestamp": "Timestamp dell'evento in nanosecondi dall'epoch time", "datetime": "Timestamp dell'evento formattato come YYYY-MM-DDTHH:MM:SS.ZZZ", + "year": "Anno dell'evento formattato a quattro cifre", + "month": "Mese dell'evento formattato a due cifre", + "day": "Giorno dell'evento formattato a due cifre", + "hour": "Ora dell'evento formattata a due cifre", + "minute": "Minuto dell'evento formattato a due cifre", "email": "Per gli eventi del file system, questa รจ l'e-mail associata all'utente che esegue l'azione. Per gli eventi del provider, si tratta dell'e-mail associata all'utente o all'amministratore interessato. Vuoto in tutti gli altri casi", "object_data": "Dati dell'oggetto provider serializzati come JSON con campi sensibili rimossi", "object_data_string": "Dati dell'oggetto provider serializzati come stringa JSON escaped con campi sensibili rimossi", diff --git a/templates/webadmin/eventaction.html b/templates/webadmin/eventaction.html index aaf7b9ce..10bd04c6 100644 --- a/templates/webadmin/eventaction.html +++ b/templates/webadmin/eventaction.html @@ -945,6 +945,21 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
{{`{{DateTime}}`}} => Timestamp formatted as YYYY-MM-DDTHH:MM:SS.ZZZ.
++ {{`{{Year}}`}} => Event year formatted as four digits. +
++ {{`{{Month}}`}} => Event month formatted as two digits. +
++ {{`{{Day}}`}} => Event day formatted as two digits. +
++ {{`{{Hour}}`}} => Event hour formatted as two digits. +
++ {{`{{Minute}}`}} => Event minute formatted as two digits. +
{{`{{Email}}`}} => For filesystem events, this is the email associated with the user performing the action. For the provider events, this is the email associated with the affected user or admin. Blank in all other cases.