Add name field for org api (#21270)
related #21205 The field `UserName` is not really usefull for an organization. This adds a second `Name` field. The [GitHub API](https://docs.github.com/en/rest/orgs/orgs#get-an-organization) uses `name` too. `UserName` should be deprecated then.
This commit is contained in:
parent
1dfa28ffa5
commit
b7309b8ccb
|
@ -296,6 +296,7 @@ func ToOrganization(org *organization.Organization) *api.Organization {
|
||||||
return &api.Organization{
|
return &api.Organization{
|
||||||
ID: org.ID,
|
ID: org.ID,
|
||||||
AvatarURL: org.AsUser().AvatarLink(),
|
AvatarURL: org.AsUser().AvatarLink(),
|
||||||
|
Name: org.Name,
|
||||||
UserName: org.Name,
|
UserName: org.Name,
|
||||||
FullName: org.FullName,
|
FullName: org.FullName,
|
||||||
Description: org.Description,
|
Description: org.Description,
|
||||||
|
|
|
@ -7,7 +7,7 @@ package structs
|
||||||
// Organization represents an organization
|
// Organization represents an organization
|
||||||
type Organization struct {
|
type Organization struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
UserName string `json:"username"`
|
Name string `json:"name"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
@ -15,6 +15,8 @@ type Organization struct {
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
Visibility string `json:"visibility"`
|
Visibility string `json:"visibility"`
|
||||||
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
|
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
|
||||||
|
// deprecated
|
||||||
|
UserName string `json:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrganizationPermissions list different users permissions on an organization
|
// OrganizationPermissions list different users permissions on an organization
|
||||||
|
|
|
@ -17326,11 +17326,16 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "Location"
|
"x-go-name": "Location"
|
||||||
},
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "Name"
|
||||||
|
},
|
||||||
"repo_admin_change_team_access": {
|
"repo_admin_change_team_access": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "RepoAdminChangeTeamAccess"
|
"x-go-name": "RepoAdminChangeTeamAccess"
|
||||||
},
|
},
|
||||||
"username": {
|
"username": {
|
||||||
|
"description": "deprecated",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "UserName"
|
"x-go-name": "UserName"
|
||||||
},
|
},
|
||||||
|
|
|
@ -37,7 +37,7 @@ func TestAPIAdminOrgCreate(t *testing.T) {
|
||||||
var apiOrg api.Organization
|
var apiOrg api.Organization
|
||||||
DecodeJSON(t, resp, &apiOrg)
|
DecodeJSON(t, resp, &apiOrg)
|
||||||
|
|
||||||
assert.Equal(t, org.UserName, apiOrg.UserName)
|
assert.Equal(t, org.UserName, apiOrg.Name)
|
||||||
assert.Equal(t, org.FullName, apiOrg.FullName)
|
assert.Equal(t, org.FullName, apiOrg.FullName)
|
||||||
assert.Equal(t, org.Description, apiOrg.Description)
|
assert.Equal(t, org.Description, apiOrg.Description)
|
||||||
assert.Equal(t, org.Website, apiOrg.Website)
|
assert.Equal(t, org.Website, apiOrg.Website)
|
||||||
|
|
|
@ -38,7 +38,7 @@ func TestAPIOrgCreate(t *testing.T) {
|
||||||
var apiOrg api.Organization
|
var apiOrg api.Organization
|
||||||
DecodeJSON(t, resp, &apiOrg)
|
DecodeJSON(t, resp, &apiOrg)
|
||||||
|
|
||||||
assert.Equal(t, org.UserName, apiOrg.UserName)
|
assert.Equal(t, org.UserName, apiOrg.Name)
|
||||||
assert.Equal(t, org.FullName, apiOrg.FullName)
|
assert.Equal(t, org.FullName, apiOrg.FullName)
|
||||||
assert.Equal(t, org.Description, apiOrg.Description)
|
assert.Equal(t, org.Description, apiOrg.Description)
|
||||||
assert.Equal(t, org.Website, apiOrg.Website)
|
assert.Equal(t, org.Website, apiOrg.Website)
|
||||||
|
@ -54,7 +54,7 @@ func TestAPIOrgCreate(t *testing.T) {
|
||||||
req = NewRequestf(t, "GET", "/api/v1/orgs/%s?token=%s", org.UserName, token)
|
req = NewRequestf(t, "GET", "/api/v1/orgs/%s?token=%s", org.UserName, token)
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
DecodeJSON(t, resp, &apiOrg)
|
DecodeJSON(t, resp, &apiOrg)
|
||||||
assert.EqualValues(t, org.UserName, apiOrg.UserName)
|
assert.EqualValues(t, org.UserName, apiOrg.Name)
|
||||||
|
|
||||||
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/repos?token=%s", org.UserName, token)
|
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/repos?token=%s", org.UserName, token)
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
@ -94,7 +94,7 @@ func TestAPIOrgEdit(t *testing.T) {
|
||||||
var apiOrg api.Organization
|
var apiOrg api.Organization
|
||||||
DecodeJSON(t, resp, &apiOrg)
|
DecodeJSON(t, resp, &apiOrg)
|
||||||
|
|
||||||
assert.Equal(t, "user3", apiOrg.UserName)
|
assert.Equal(t, "user3", apiOrg.Name)
|
||||||
assert.Equal(t, org.FullName, apiOrg.FullName)
|
assert.Equal(t, org.FullName, apiOrg.FullName)
|
||||||
assert.Equal(t, org.Description, apiOrg.Description)
|
assert.Equal(t, org.Description, apiOrg.Description)
|
||||||
assert.Equal(t, org.Website, apiOrg.Website)
|
assert.Equal(t, org.Website, apiOrg.Website)
|
||||||
|
|
|
@ -32,6 +32,7 @@ func TestUserOrgs(t *testing.T) {
|
||||||
assert.Equal(t, []*api.Organization{
|
assert.Equal(t, []*api.Organization{
|
||||||
{
|
{
|
||||||
ID: 17,
|
ID: 17,
|
||||||
|
Name: user17.Name,
|
||||||
UserName: user17.Name,
|
UserName: user17.Name,
|
||||||
FullName: user17.FullName,
|
FullName: user17.FullName,
|
||||||
AvatarURL: user17.AvatarLink(),
|
AvatarURL: user17.AvatarLink(),
|
||||||
|
@ -42,6 +43,7 @@ func TestUserOrgs(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
|
Name: user3.Name,
|
||||||
UserName: user3.Name,
|
UserName: user3.Name,
|
||||||
FullName: user3.FullName,
|
FullName: user3.FullName,
|
||||||
AvatarURL: user3.AvatarLink(),
|
AvatarURL: user3.AvatarLink(),
|
||||||
|
@ -99,6 +101,7 @@ func TestMyOrgs(t *testing.T) {
|
||||||
assert.Equal(t, []*api.Organization{
|
assert.Equal(t, []*api.Organization{
|
||||||
{
|
{
|
||||||
ID: 17,
|
ID: 17,
|
||||||
|
Name: user17.Name,
|
||||||
UserName: user17.Name,
|
UserName: user17.Name,
|
||||||
FullName: user17.FullName,
|
FullName: user17.FullName,
|
||||||
AvatarURL: user17.AvatarLink(),
|
AvatarURL: user17.AvatarLink(),
|
||||||
|
@ -109,6 +112,7 @@ func TestMyOrgs(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
|
Name: user3.Name,
|
||||||
UserName: user3.Name,
|
UserName: user3.Name,
|
||||||
FullName: user3.FullName,
|
FullName: user3.FullName,
|
||||||
AvatarURL: user3.AvatarLink(),
|
AvatarURL: user3.AvatarLink(),
|
||||||
|
|
Loading…
Reference in New Issue