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:
+13
-10
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Generated
+5
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user