1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Use a standalone struct name for Organization (#17632)

* Use a standalone struct name for Organization

* recover unnecessary change

* make the code readable

* Fix template failure

* Fix template failure

* Move HasMemberWithUserID to org

* Fix test

* Remove unnecessary user type check

* Fix test

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Lunny Xiao
2021-11-19 19:41:40 +08:00
committed by GitHub
parent a09b40de8d
commit 7a03473159
43 changed files with 335 additions and 259 deletions

View File

@@ -59,7 +59,7 @@ func ListHooks(ctx *context.APIContext) {
hooks := make([]*api.Hook, len(orgHooks))
for i, hook := range orgHooks {
hooks[i] = convert.ToHook(ctx.Org.Organization.HomeLink(), hook)
hooks[i] = convert.ToHook(ctx.Org.Organization.AsUser().HomeLink(), hook)
}
ctx.SetTotalCountHeader(count)
@@ -95,7 +95,7 @@ func GetHook(ctx *context.APIContext) {
if err != nil {
return
}
ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), hook))
ctx.JSON(http.StatusOK, convert.ToHook(org.AsUser().HomeLink(), hook))
}
// CreateHook create a hook for an organization

View File

@@ -56,7 +56,7 @@ func ListLabels(ctx *context.APIContext) {
}
ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, convert.ToLabelList(labels, nil, ctx.Org.Organization))
ctx.JSON(http.StatusOK, convert.ToLabelList(labels, nil, ctx.Org.Organization.AsUser()))
}
// CreateLabel create a label for a repository
@@ -104,7 +104,7 @@ func CreateLabel(ctx *context.APIContext) {
return
}
ctx.JSON(http.StatusCreated, convert.ToLabel(label, nil, ctx.Org.Organization))
ctx.JSON(http.StatusCreated, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser()))
}
// GetLabel get label by organization and label id
@@ -149,7 +149,7 @@ func GetLabel(ctx *context.APIContext) {
return
}
ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization))
ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser()))
}
// EditLabel modify a label for an Organization
@@ -214,7 +214,7 @@ func EditLabel(ctx *context.APIContext) {
return
}
ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization))
ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser()))
}
// DeleteLabel delete a label for an organization

View File

@@ -31,7 +31,7 @@ func listUserOrgs(ctx *context.APIContext, u *models.User) {
}
maxResults := len(orgs)
orgs, _ = util.PaginateSlice(orgs, listOptions.Page, listOptions.PageSize).([]*models.User)
orgs, _ = util.PaginateSlice(orgs, listOptions.Page, listOptions.PageSize).([]*models.Organization)
apiOrgs := make([]*api.Organization, len(orgs))
for i := range orgs {
@@ -141,7 +141,8 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
return
}
authorizeLevel, err := o.GetOrgUserMaxAuthorizeLevel(u.ID)
org := models.OrgFromUser(o)
authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(u.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetOrgUserAuthorizeLevel", err)
return
@@ -160,7 +161,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
op.IsOwner = true
}
op.CanCreateRepository, err = o.CanCreateOrgRepo(u.ID)
op.CanCreateRepository, err = org.CanCreateOrgRepo(u.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
return
@@ -212,7 +213,7 @@ func GetAll(ctx *context.APIContext) {
}
orgs := make([]*api.Organization, len(publicOrgs))
for i := range publicOrgs {
orgs[i] = convert.ToOrganization(publicOrgs[i])
orgs[i] = convert.ToOrganization(models.OrgFromUser(publicOrgs[i]))
}
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
@@ -252,7 +253,7 @@ func Create(ctx *context.APIContext) {
visibility = api.VisibilityModes[form.Visibility]
}
org := &models.User{
org := &models.Organization{
Name: form.UserName,
FullName: form.FullName,
Description: form.Description,
@@ -295,7 +296,7 @@ func Get(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/Organization"
if !models.HasOrgOrUserVisible(ctx.Org.Organization, ctx.User) {
if !models.HasOrgOrUserVisible(ctx.Org.Organization.AsUser(), ctx.User) {
ctx.NotFound("HasOrgOrUserVisible", nil)
return
}
@@ -337,7 +338,7 @@ func Edit(ctx *context.APIContext) {
if form.RepoAdminChangeTeamAccess != nil {
org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
}
if err := models.UpdateUserCols(org,
if err := models.UpdateUserCols(org.AsUser(),
"full_name", "description", "website", "location",
"visibility", "repo_admin_change_team_access",
); err != nil {

View File

@@ -102,7 +102,7 @@ func ListUserTeams(ctx *context.APIContext) {
for i := range teams {
apiOrg, ok := cache[teams[i].OrgID]
if !ok {
org, err := models.GetUserByID(teams[i].OrgID)
org, err := models.GetOrgByID(teams[i].OrgID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
return