feat(api): return created time in /org/{org} endpoint (#12633)

closes #4126

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12633
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
numen
2026-05-28 21:25:41 +02:00
committed by Gusted
parent e35880e7ac
commit 427457946b
6 changed files with 43 additions and 12 deletions
+13 -10
View File
@@ -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"`
}
+1
View File
@@ -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(),
}
}
+5
View File
@@ -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"
+1
View File
@@ -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,
+12 -1
View File
@@ -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})
+11 -1
View File
@@ -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)
}