From 33b11d7b64d3ad96df5e81b12f47fb78dd36b95b Mon Sep 17 00:00:00 2001 From: "tobias.petersen" Date: Tue, 29 Apr 2025 18:23:21 +0200 Subject: [PATCH 1/6] feat: return 'updated_at' (last used) for PublicKeys in the API --- modules/structs/user_key.go | 1 + services/convert/convert.go | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/structs/user_key.go b/modules/structs/user_key.go index 08eed59a89c88..4414e5adf3872 100644 --- a/modules/structs/user_key.go +++ b/modules/structs/user_key.go @@ -16,6 +16,7 @@ type PublicKey struct { Fingerprint string `json:"fingerprint,omitempty"` // swagger:strfmt date-time Created time.Time `json:"created_at,omitempty"` + Updated time.Time `json:"updated_at,omitempty"` Owner *User `json:"user,omitempty"` ReadOnly bool `json:"read_only,omitempty"` KeyType string `json:"key_type,omitempty"` diff --git a/services/convert/convert.go b/services/convert/convert.go index 9d2afdea308b9..93b72e223a11a 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -307,6 +307,7 @@ func ToPublicKey(apiLink string, key *asymkey_model.PublicKey) *api.PublicKey { Title: key.Name, Fingerprint: key.Fingerprint, Created: key.CreatedUnix.AsTime(), + Updated: key.UpdatedUnix.AsTime(), } } From a86dedb5e14304ac354935a667dda52cb1e735b9 Mon Sep 17 00:00:00 2001 From: "tobias.petersen" Date: Tue, 29 Apr 2025 18:25:38 +0200 Subject: [PATCH 2/6] feat: return 'created_at' & 'updated_at' (last used) for AccessTokens in the API --- modules/structs/user_app.go | 12 +++++++----- routers/api/v1/user/app.go | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/structs/user_app.go b/modules/structs/user_app.go index 8401252bd6591..715edde686f71 100644 --- a/modules/structs/user_app.go +++ b/modules/structs/user_app.go @@ -11,11 +11,13 @@ import ( // AccessToken represents an API access token. // swagger:response AccessToken type AccessToken struct { - ID int64 `json:"id"` - Name string `json:"name"` - Token string `json:"sha1"` - TokenLastEight string `json:"token_last_eight"` - Scopes []string `json:"scopes"` + ID int64 `json:"id"` + Name string `json:"name"` + Token string `json:"sha1"` + TokenLastEight string `json:"token_last_eight"` + Scopes []string `json:"scopes"` + Created time.Time `json:"created_at"` + Updated time.Time `json:"updated_at"` } // AccessTokenList represents a list of API access token. diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go index 4ca06ca923886..720101016197a 100644 --- a/routers/api/v1/user/app.go +++ b/routers/api/v1/user/app.go @@ -62,6 +62,8 @@ func ListAccessTokens(ctx *context.APIContext) { Name: tokens[i].Name, TokenLastEight: tokens[i].TokenLastEight, Scopes: tokens[i].Scope.StringSlice(), + Created: tokens[i].CreatedUnix.AsTime(), + Updated: tokens[i].UpdatedUnix.AsTime(), } } From 77e1f9fc632fcb27671e6f11e7c31f46ac88876a Mon Sep 17 00:00:00 2001 From: "tobias.petersen" Date: Wed, 30 Apr 2025 10:54:56 +0200 Subject: [PATCH 3/6] fix: add fields 'created_at' and 'updated_at' for AccessToken in swagger template --- templates/swagger/v1_json.tmpl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 8758b5c0a1505..ef9b512e1a607 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -20001,6 +20001,16 @@ "token_last_eight": { "type": "string", "x-go-name": "TokenLastEight" + }, + "created_at": { + "type": "string", + "format": "date-time", + "x-go-name": "Created" + }, + "updated_at": { + "type": "string", + "format": "date-time", + "x-go-name": "Updated" } }, "x-go-package": "code.gitea.io/gitea/modules/structs" From 80fa02a5ec7764ce40c6af324241435ea8641203 Mon Sep 17 00:00:00 2001 From: "tobias.petersen" Date: Wed, 30 Apr 2025 10:58:15 +0200 Subject: [PATCH 4/6] fix: add field 'updated_at' for PublicKey in swagger template --- templates/swagger/v1_json.tmpl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index ef9b512e1a607..806a50d5872d4 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -25495,6 +25495,11 @@ "type": "string", "x-go-name": "Title" }, + "updated_at": { + "type": "string", + "format": "date-time", + "x-go-name": "Updated" + }, "url": { "type": "string", "x-go-name": "URL" From c0a72f896de352106626e1b417538509f44443bd Mon Sep 17 00:00:00 2001 From: "tobias.petersen" Date: Wed, 30 Apr 2025 11:05:50 +0200 Subject: [PATCH 5/6] fix: wrong order of properties in swagger template --- templates/swagger/v1_json.tmpl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 806a50d5872d4..4a84fae95b20f 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -19978,6 +19978,11 @@ "type": "object", "title": "AccessToken represents an API access token.", "properties": { + "created_at": { + "type": "string", + "format": "date-time", + "x-go-name": "Created" + }, "id": { "type": "integer", "format": "int64", @@ -20002,11 +20007,6 @@ "type": "string", "x-go-name": "TokenLastEight" }, - "created_at": { - "type": "string", - "format": "date-time", - "x-go-name": "Created" - }, "updated_at": { "type": "string", "format": "date-time", From 41fa647c3e1d8e6a91c1d23ba8fa78d631b5aea0 Mon Sep 17 00:00:00 2001 From: "tobias.petersen" Date: Thu, 1 May 2025 15:39:22 +0200 Subject: [PATCH 6/6] fix: rename API field 'updated_at' to 'last_used_at' for PublicKey and AccessToken --- modules/structs/user_app.go | 2 +- modules/structs/user_key.go | 2 +- templates/swagger/v1_json.tmpl | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/structs/user_app.go b/modules/structs/user_app.go index 715edde686f71..15811ceb66aae 100644 --- a/modules/structs/user_app.go +++ b/modules/structs/user_app.go @@ -17,7 +17,7 @@ type AccessToken struct { TokenLastEight string `json:"token_last_eight"` Scopes []string `json:"scopes"` Created time.Time `json:"created_at"` - Updated time.Time `json:"updated_at"` + Updated time.Time `json:"last_used_at"` } // AccessTokenList represents a list of API access token. diff --git a/modules/structs/user_key.go b/modules/structs/user_key.go index 4414e5adf3872..c4c41207e1c68 100644 --- a/modules/structs/user_key.go +++ b/modules/structs/user_key.go @@ -16,7 +16,7 @@ type PublicKey struct { Fingerprint string `json:"fingerprint,omitempty"` // swagger:strfmt date-time Created time.Time `json:"created_at,omitempty"` - Updated time.Time `json:"updated_at,omitempty"` + Updated time.Time `json:"last_used_at,omitempty"` Owner *User `json:"user,omitempty"` ReadOnly bool `json:"read_only,omitempty"` KeyType string `json:"key_type,omitempty"` diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 4a84fae95b20f..223a2e84103f6 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -19988,6 +19988,11 @@ "format": "int64", "x-go-name": "ID" }, + "last_used_at": { + "type": "string", + "format": "date-time", + "x-go-name": "Updated" + }, "name": { "type": "string", "x-go-name": "Name" @@ -20006,11 +20011,6 @@ "token_last_eight": { "type": "string", "x-go-name": "TokenLastEight" - }, - "updated_at": { - "type": "string", - "format": "date-time", - "x-go-name": "Updated" } }, "x-go-package": "code.gitea.io/gitea/modules/structs" @@ -25487,6 +25487,11 @@ "type": "string", "x-go-name": "KeyType" }, + "last_used_at": { + "type": "string", + "format": "date-time", + "x-go-name": "Updated" + }, "read_only": { "type": "boolean", "x-go-name": "ReadOnly" @@ -25495,11 +25500,6 @@ "type": "string", "x-go-name": "Title" }, - "updated_at": { - "type": "string", - "format": "date-time", - "x-go-name": "Updated" - }, "url": { "type": "string", "x-go-name": "URL"