Skip to content

Commit 4274579

Browse files
numenGusted
authored andcommitted
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>
1 parent e35880e commit 4274579

6 files changed

Lines changed: 43 additions & 12 deletions

File tree

modules/structs/org.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33

44
package structs
55

6+
import "time"
7+
68
// Organization represents an organization
79
type Organization struct {
8-
ID int64 `json:"id"`
9-
Name string `json:"name"`
10-
FullName string `json:"full_name"`
11-
Email string `json:"email"`
12-
AvatarURL string `json:"avatar_url"`
13-
Description string `json:"description"`
14-
Website string `json:"website"`
15-
Location string `json:"location"`
16-
Visibility string `json:"visibility"`
17-
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
10+
ID int64 `json:"id"`
11+
Name string `json:"name"`
12+
FullName string `json:"full_name"`
13+
Email string `json:"email"`
14+
AvatarURL string `json:"avatar_url"`
15+
Description string `json:"description"`
16+
Website string `json:"website"`
17+
Location string `json:"location"`
18+
Visibility string `json:"visibility"`
19+
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
20+
Created time.Time `json:"created"`
1821
// deprecated
1922
UserName string `json:"username"`
2023
}

services/convert/convert.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ func ToOrganization(ctx context.Context, org *organization.Organization) *api.Or
348348
Location: org.Location,
349349
Visibility: org.Visibility.String(),
350350
RepoAdminChangeTeamAccess: org.RepoAdminChangeTeamAccess,
351+
Created: org.CreatedUnix.AsTime(),
351352
}
352353
}
353354

templates/swagger/v1_json.tmpl

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/api_org_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func TestAPIOrgCreate(t *testing.T) {
4949
assert.Equal(t, org.Website, apiOrg.Website)
5050
assert.Equal(t, org.Location, apiOrg.Location)
5151
assert.Equal(t, org.Visibility, apiOrg.Visibility)
52+
assert.False(t, apiOrg.Created.IsZero())
5253

5354
unittest.AssertExistsAndLoadBean(t, &user_model.User{
5455
Name: org.UserName,

tests/integration/api_team_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ func TestAPITeam(t *testing.T) {
4343
DecodeJSON(t, resp, &apiTeam)
4444
assert.Equal(t, team.ID, apiTeam.ID)
4545
assert.Equal(t, team.Name, apiTeam.Name)
46-
assert.Equal(t, convert.ToOrganization(db.DefaultContext, org), apiTeam.Organization)
46+
47+
toOrg := convert.ToOrganization(db.DefaultContext, org)
48+
assert.Equal(t, toOrg.ID, apiTeam.Organization.ID)
49+
assert.Equal(t, toOrg.AvatarURL, apiTeam.Organization.AvatarURL)
50+
assert.Equal(t, toOrg.Name, apiTeam.Organization.Name)
51+
assert.Equal(t, toOrg.FullName, apiTeam.Organization.FullName)
52+
assert.Equal(t, toOrg.Description, apiTeam.Organization.Description)
53+
assert.Equal(t, toOrg.Website, apiTeam.Organization.Website)
54+
assert.Equal(t, toOrg.Location, apiTeam.Organization.Location)
55+
assert.Equal(t, toOrg.Visibility, apiTeam.Organization.Visibility)
56+
assert.Equal(t, toOrg.RepoAdminChangeTeamAccess, apiTeam.Organization.RepoAdminChangeTeamAccess)
57+
assert.Equal(t, toOrg.Created.Local(), apiTeam.Organization.Created.Local())
4758

4859
// non team member user will not access the teams details
4960
teamUser2 := unittest.AssertExistsAndLoadBean(t, &organization.TeamUser{ID: 3})

tests/integration/api_user_orgs_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ func TestUserOrgs(t *testing.T) {
2626
unrelatedUsername := "user5"
2727

2828
orgs := getUserOrgs(t, adminUsername, normalUsername)
29-
29+
for _, org := range orgs {
30+
org.Created = org.Created.Local()
31+
}
3032
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "org3"})
3133
org17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "org17"})
3234

@@ -42,6 +44,7 @@ func TestUserOrgs(t *testing.T) {
4244
Website: "",
4345
Location: "",
4446
Visibility: "public",
47+
Created: org17.CreatedUnix.AsTime().Local(),
4548
},
4649
{
4750
ID: 3,
@@ -54,6 +57,7 @@ func TestUserOrgs(t *testing.T) {
5457
Website: "",
5558
Location: "",
5659
Visibility: "public",
60+
Created: org3.CreatedUnix.AsTime().Local(),
5761
},
5862
}, orgs)
5963

@@ -100,6 +104,10 @@ func TestMyOrgs(t *testing.T) {
100104
resp := MakeRequest(t, req, http.StatusOK)
101105
var orgs []*api.Organization
102106
DecodeJSON(t, resp, &orgs)
107+
for _, org := range orgs {
108+
org.Created = org.Created.Local()
109+
}
110+
103111
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "org3"})
104112
org17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "org17"})
105113

@@ -115,6 +123,7 @@ func TestMyOrgs(t *testing.T) {
115123
Website: "",
116124
Location: "",
117125
Visibility: "public",
126+
Created: org17.CreatedUnix.AsTime().Local(),
118127
},
119128
{
120129
ID: 3,
@@ -127,6 +136,7 @@ func TestMyOrgs(t *testing.T) {
127136
Website: "",
128137
Location: "",
129138
Visibility: "public",
139+
Created: org3.CreatedUnix.AsTime().Local(),
130140
},
131141
}, orgs)
132142
}

0 commit comments

Comments
 (0)