Skip to content

Commit a513675

Browse files
committed
last-login: Add abstracted way to update custom fields
1 parent 1f87c24 commit a513675

3 files changed

Lines changed: 51 additions & 10 deletions

File tree

data/settings.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ last_login {
26002600
plugin: 'last-login',
26012601
values: setting_types.STRING,
26022602
text: `
2603-
The key that is updated in the dictionary with the last login information.`
2603+
The key that is updated in the dictionary with the last login timestamp.`
26042604
},
26052605

26062606
last_login_precision: {
@@ -2611,6 +2611,18 @@ The key that is updated in the dictionary with the last login information.`
26112611
text: `Precision for last login timestamp.`
26122612
},
26132613

2614+
last_login_dict_fields: {
2615+
default: '',
2616+
added: {
2617+
settings_last_login_dict_fields_added: false
2618+
},
2619+
plugin: 'last-login',
2620+
values: setting_types.STRLIST,
2621+
text: `
2622+
List of additional key/value pairs to be updated in the
2623+
dictionary. Both keys and values support variable expansion.`
2624+
},
2625+
26142626
/* lazy-expunge plugin */
26152627

26162628
lazy_expunge_mailbox: {

data/updates.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export const updates = {
156156
settings_imapc_ssl_verify_removed: '2.4.0',
157157
settings_inet_listener_type_added: '2.4.0',
158158
settings_lazy_expunge_only_last_instance_changed: '2.4.3',
159+
settings_last_login_dict_fields_added: '2.4.X',
159160
settings_login_socket_path_added: '2.4.0',
160161
settings_lmtp_user_concurrency_limit_changed: '2.4.1',
161162
settings_mail_access_groups_changed: '2.4.3',

docs/core/plugins/last_login.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ to include `%{service}`.
6060

6161
### MySQL Example
6262

63-
This includes the service and remote IP address as well.
63+
This includes the service and remote IP address as well. Using
64+
`last_login_dict_fields` ensures that both the timestamp and the IP address are
65+
updated if a login record for that user/service already exists.
6466

6567
::: code-group
6668

@@ -69,7 +71,10 @@ last_login {
6971
dict proxy {
7072
name = sql
7173
}
72-
key = last-login/%{service}/%{user}/%{remote_ip}
74+
key = last-login/%{service}/%{user}/access
75+
last_login_dict_fields {
76+
ip = %{remote_ip}
77+
}
7378
precision = ms
7479
}
7580
@@ -82,7 +87,7 @@ dict_server {
8287
password = pass
8388
}
8489
85-
dict_map shared/last-login/$service/$user/$remote_ip {
90+
dict_map shared/last-login/$service/$user/access {
8691
sql_table = last_login
8792
value_field last_access {
8893
type = uint
@@ -94,8 +99,18 @@ dict_server {
9499
key_field service {
95100
value = $service
96101
}
97-
key_field last_ip {
98-
value = $remote_ip
102+
}
103+
104+
dict_map shared/last-login/$service/$user/ip {
105+
sql_table = last_login
106+
value_field last_ip {
107+
}
108+
109+
key_field userid {
110+
value = $user
111+
}
112+
key_field service {
113+
value = $service
99114
}
100115
}
101116
}
@@ -125,7 +140,10 @@ last_login {
125140
name = cassandra
126141
socket_path = dict-async
127142
}
128-
key = last-login/%{service}/%{user}/%{remote_ip}
143+
key = last-login/%{service}/%{user}/access
144+
last_login_dict_fields {
145+
ip = %{remote_ip}
146+
}
129147
precision = ms
130148
}
131149
@@ -140,7 +158,7 @@ dict_server {
140158
password = pass
141159
}
142160
143-
dict_map shared/last-login/$service/$user/$remote_ip {
161+
dict_map shared/last-login/$service/$user/access {
144162
sql_table = last_login
145163
value_field last_access {
146164
type = uint
@@ -152,8 +170,18 @@ dict_server {
152170
key_field service {
153171
value = $service
154172
}
155-
key_field last_ip {
156-
value = $remote_ip
173+
}
174+
175+
dict_map shared/last-login/$service/$user/ip {
176+
sql_table = last_login
177+
value_field last_ip {
178+
}
179+
180+
key_field userid {
181+
value = $user
182+
}
183+
key_field service {
184+
value = $service
157185
}
158186
}
159187
}

0 commit comments

Comments
 (0)