浏览代码

EventManager: add more datetime placeholders

Signed-off-by: Nicola Murino <[email protected]>
Nicola Murino 9 月之前
父节点
当前提交
f56a93495d

+ 13 - 1
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),

+ 2 - 0
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) {

+ 5 - 0
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",

+ 5 - 0
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",

+ 15 - 0
templates/webadmin/eventaction.html

@@ -945,6 +945,21 @@ explicit grant from the SFTPGo Team ([email protected]).
                 <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>