aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorSybren2023-02-16 17:32:01 +0100
committerGitHub2023-02-16 10:32:01 -0600
commitaa45777c926adba2bbe9e269960476acf55abb33 (patch)
treebcf28d4a45eb80c9598b827b6c7bc284416b0790 /modules
parenta0b9767df8720578910d49437db37dc34821bd0b (diff)
Allow custom "created" timestamps in user creation API (#22549)
Allow back-dating user creation via the `adminCreateUser` API operation. `CreateUserOption` now has an optional field `created_at`, which can contain a datetime-formatted string. If this field is present, the user's `created_unix` database field will be updated to its value. This is important for Blender's migration of users from Phabricator to Gitea. There are many users, and the creation timestamp of their account can give us some indication as to how long someone's been part of the community. The back-dating is done in a separate query that just updates the user's `created_unix` field. This was the easiest and cleanest way I could find, as in the initial `INSERT` query the field always is set to "now".
Diffstat (limited to 'modules')
-rw-r--r--modules/structs/admin_user.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/modules/structs/admin_user.go b/modules/structs/admin_user.go
index 0739653ee..4d679c81d 100644
--- a/modules/structs/admin_user.go
+++ b/modules/structs/admin_user.go
@@ -4,6 +4,8 @@
package structs
+import "time"
+
// CreateUserOption create user options
type CreateUserOption struct {
SourceID int64 `json:"source_id"`
@@ -20,6 +22,11 @@ type CreateUserOption struct {
SendNotify bool `json:"send_notify"`
Restricted *bool `json:"restricted"`
Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
+
+ // For explicitly setting the user creation timestamp. Useful when users are
+ // migrated from other systems. When omitted, the user's creation timestamp
+ // will be set to "now".
+ Created *time.Time `json:"created_at"`
}
// EditUserOption edit user options