EventManager: add more datetime placeholders

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2025-01-16 18:14:43 +01:00
parent 24215dc734
commit ef2f3e51ea
5 changed files with 40 additions and 0 deletions

View File

@@ -789,6 +789,12 @@ func (p *EventParams) getStringReplacements(addObjectData, jsonEscaped bool) []s
} else {
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,
@@ -809,6 +815,11 @@ func (p *EventParams) getStringReplacements(addObjectData, jsonEscaped bool) []s
"{{Email}}", p.getStringReplacement(p.Email, jsonEscaped),
"{{Timestamp}}", strconv.FormatInt(p.Timestamp.UnixNano(), 10),
"{{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),

View File

@@ -812,12 +812,16 @@ 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)
Config.TZ = "local"
replacements = params.getStringReplacements(false, false)
r = strings.NewReplacer(replacements...)
res = r.Replace("{{DateTime}}")
assert.Equal(t, dateTime.Local().Format(dateTimeMillisFormat), res)
res = r.Replace("{{Year}}-{{Month}}-{{Day}}T{{Hour}}:{{Minute}}")
assert.Equal(t, dateTime.Local().Format(dateTimeMillisFormat)[:16], res)
Config.TZ = oldTZ
}

View File

@@ -1078,6 +1078,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",

View File

@@ -1078,6 +1078,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",

View File

@@ -960,6 +960,21 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
<p>
<span class="shortcut">{{`{{DateTime}}`}}</span> => <span data-i18n="actions.placeholders_modal.datetime">Timestamp formatted as YYYY-MM-DDTHH:MM:SS.ZZZ.</span>
</p>
<p>
<span class="shortcut">{{`{{Year}}`}}</span> => <span data-i18n="actions.placeholders_modal.year">Event year formatted as four digits.</span>
</p>
<p>
<span class="shortcut">{{`{{Month}}`}}</span> => <span data-i18n="actions.placeholders_modal.month">Event month formatted as two digits.</span>
</p>
<p>
<span class="shortcut">{{`{{Day}}`}}</span> => <span data-i18n="actions.placeholders_modal.day">Event day formatted as two digits.</span>
</p>
<p>
<span class="shortcut">{{`{{Hour}}`}}</span> => <span data-i18n="actions.placeholders_modal.hour">Event hour formatted as two digits.</span>
</p>
<p>
<span class="shortcut">{{`{{Minute}}`}}</span> => <span data-i18n="actions.placeholders_modal.minute">Event minute formatted as two digits.</span>
</p>
<p>
<span class="shortcut">{{`{{Email}}`}}</span> => <span data-i18n="actions.placeholders_modal.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.</span>
</p>