From 427457946bc11243db800424170c2f2bff867213 Mon Sep 17 00:00:00 2001 From: numen Date: Thu, 28 May 2026 21:25:41 +0200 Subject: [PATCH] feat(api): return created time in /org/{org} endpoint (#12633) closes #4126 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12633 Reviewed-by: Gusted --- modules/structs/org.go | 23 +++++++++++++---------- services/convert/convert.go | 1 + templates/swagger/v1_json.tmpl | 5 +++++ tests/integration/api_org_test.go | 1 + tests/integration/api_team_test.go | 13 ++++++++++++- tests/integration/api_user_orgs_test.go | 12 +++++++++++- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/modules/structs/org.go b/modules/structs/org.go index 451153b620..a0b050326b 100644 --- a/modules/structs/org.go +++ b/modules/structs/org.go @@ -3,18 +3,21 @@ package structs +import "time" + // Organization represents an organization type Organization struct { - ID int64 `json:"id"` - Name string `json:"name"` - FullName string `json:"full_name"` - Email string `json:"email"` - AvatarURL string `json:"avatar_url"` - Description string `json:"description"` - Website string `json:"website"` - Location string `json:"location"` - Visibility string `json:"visibility"` - RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"` + ID int64 `json:"id"` + Name string `json:"name"` + FullName string `json:"full_name"` + Email string `json:"email"` + AvatarURL string `json:"avatar_url"` + Description string `json:"description"` + Website string `json:"website"` + Location string `json:"location"` + Visibility string `json:"visibility"` + RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"` + Created time.Time `json:"created"` // deprecated UserName string `json:"username"` } diff --git a/services/convert/convert.go b/services/convert/convert.go index 49949ac0e0..78c45cfbf4 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -348,6 +348,7 @@ func ToOrganization(ctx context.Context, org *organization.Organization) *api.Or Location: org.Location, Visibility: org.Visibility.String(), RepoAdminChangeTeamAccess: org.RepoAdminChangeTeamAccess, + Created: org.CreatedUnix.AsTime(), } } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 3b04fd4146..47d280cbde 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -28189,6 +28189,11 @@ "type": "string", "x-go-name": "AvatarURL" }, + "created": { + "type": "string", + "format": "date-time", + "x-go-name": "Created" + }, "description": { "type": "string", "x-go-name": "Description" diff --git a/tests/integration/api_org_test.go b/tests/integration/api_org_test.go index d20387747b..98532f6659 100644 --- a/tests/integration/api_org_test.go +++ b/tests/integration/api_org_test.go @@ -49,6 +49,7 @@ func TestAPIOrgCreate(t *testing.T) { assert.Equal(t, org.Website, apiOrg.Website) assert.Equal(t, org.Location, apiOrg.Location) assert.Equal(t, org.Visibility, apiOrg.Visibility) + assert.False(t, apiOrg.Created.IsZero()) unittest.AssertExistsAndLoadBean(t, &user_model.User{ Name: org.UserName, diff --git a/tests/integration/api_team_test.go b/tests/integration/api_team_test.go index 5332f6ba83..5055aae35d 100644 --- a/tests/integration/api_team_test.go +++ b/tests/integration/api_team_test.go @@ -43,7 +43,18 @@ func TestAPITeam(t *testing.T) { DecodeJSON(t, resp, &apiTeam) assert.Equal(t, team.ID, apiTeam.ID) assert.Equal(t, team.Name, apiTeam.Name) - assert.Equal(t, convert.ToOrganization(db.DefaultContext, org), apiTeam.Organization) + + toOrg := convert.ToOrganization(db.DefaultContext, org) + assert.Equal(t, toOrg.ID, apiTeam.Organization.ID) + assert.Equal(t, toOrg.AvatarURL, apiTeam.Organization.AvatarURL) + assert.Equal(t, toOrg.Name, apiTeam.Organization.Name) + assert.Equal(t, toOrg.FullName, apiTeam.Organization.FullName) + assert.Equal(t, toOrg.Description, apiTeam.Organization.Description) + assert.Equal(t, toOrg.Website, apiTeam.Organization.Website) + assert.Equal(t, toOrg.Location, apiTeam.Organization.Location) + assert.Equal(t, toOrg.Visibility, apiTeam.Organization.Visibility) + assert.Equal(t, toOrg.RepoAdminChangeTeamAccess, apiTeam.Organization.RepoAdminChangeTeamAccess) + assert.Equal(t, toOrg.Created.Local(), apiTeam.Organization.Created.Local()) // non team member user will not access the teams details teamUser2 := unittest.AssertExistsAndLoadBean(t, &organization.TeamUser{ID: 3}) diff --git a/tests/integration/api_user_orgs_test.go b/tests/integration/api_user_orgs_test.go index ca3fc7df34..4409b44c2a 100644 --- a/tests/integration/api_user_orgs_test.go +++ b/tests/integration/api_user_orgs_test.go @@ -26,7 +26,9 @@ func TestUserOrgs(t *testing.T) { unrelatedUsername := "user5" orgs := getUserOrgs(t, adminUsername, normalUsername) - + for _, org := range orgs { + org.Created = org.Created.Local() + } org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "org3"}) org17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "org17"}) @@ -42,6 +44,7 @@ func TestUserOrgs(t *testing.T) { Website: "", Location: "", Visibility: "public", + Created: org17.CreatedUnix.AsTime().Local(), }, { ID: 3, @@ -54,6 +57,7 @@ func TestUserOrgs(t *testing.T) { Website: "", Location: "", Visibility: "public", + Created: org3.CreatedUnix.AsTime().Local(), }, }, orgs) @@ -100,6 +104,10 @@ func TestMyOrgs(t *testing.T) { resp := MakeRequest(t, req, http.StatusOK) var orgs []*api.Organization DecodeJSON(t, resp, &orgs) + for _, org := range orgs { + org.Created = org.Created.Local() + } + org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "org3"}) org17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "org17"}) @@ -115,6 +123,7 @@ func TestMyOrgs(t *testing.T) { Website: "", Location: "", Visibility: "public", + Created: org17.CreatedUnix.AsTime().Local(), }, { ID: 3, @@ -127,6 +136,7 @@ func TestMyOrgs(t *testing.T) { Website: "", Location: "", Visibility: "public", + Created: org3.CreatedUnix.AsTime().Local(), }, }, orgs) }