diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-19 19:41:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 19:41:40 +0800 |
commit | 7a0347315995b25bcb2dca4786504fb699b5f004 (patch) | |
tree | 803dfd39286216fd0521ad16539ffd9fc5f87fc0 /modules/context | |
parent | a09b40de8d1dae7107437cfba42cee201fcd6d42 (diff) | |
download | gitea-7a0347315995b25bcb2dca4786504fb699b5f004.tar.gz gitea-7a0347315995b25bcb2dca4786504fb699b5f004.zip |
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>
Diffstat (limited to 'modules/context')
-rw-r--r-- | modules/context/api_org.go | 2 | ||||
-rw-r--r-- | modules/context/org.go | 22 |
2 files changed, 10 insertions, 14 deletions
diff --git a/modules/context/api_org.go b/modules/context/api_org.go index 3a2c8c559d..6d86fa6ed2 100644 --- a/modules/context/api_org.go +++ b/modules/context/api_org.go @@ -10,6 +10,6 @@ import ( // APIOrganization contains organization and team type APIOrganization struct { - Organization *models.User + Organization *models.Organization Team *models.Team } diff --git a/modules/context/org.go b/modules/context/org.go index d7257361fd..54cc3a9d8c 100644 --- a/modules/context/org.go +++ b/modules/context/org.go @@ -18,11 +18,12 @@ type Organization struct { IsMember bool IsTeamMember bool // Is member of team. IsTeamAdmin bool // In owner team or team that has admin permission level. - Organization *models.User + Organization *models.Organization OrgLink string CanCreateOrgRepo bool - Team *models.Team + Team *models.Team + Teams []*models.Team } // HandleOrgAssignment handles organization assignment @@ -49,7 +50,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { orgName := ctx.Params(":org") var err error - ctx.Org.Organization, err = models.GetUserByName(orgName) + ctx.Org.Organization, err = models.GetOrgByName(orgName) if err != nil { if models.IsErrUserNotExist(err) { redirectUserID, err := user_model.LookupUserRedirect(orgName) @@ -68,12 +69,6 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { org := ctx.Org.Organization ctx.Data["Org"] = org - // Force redirection when username is actually a user. - if !org.IsOrganization() { - ctx.Redirect(org.HomeLink()) - return - } - // Admin has super access. if ctx.IsSigned && ctx.User.IsAdmin { ctx.Org.IsOwner = true @@ -118,18 +113,19 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { ctx.Data["IsOrganizationMember"] = ctx.Org.IsMember ctx.Data["CanCreateOrgRepo"] = ctx.Org.CanCreateOrgRepo - ctx.Org.OrgLink = org.OrganisationLink() + ctx.Org.OrgLink = org.AsUser().OrganisationLink() ctx.Data["OrgLink"] = ctx.Org.OrgLink // Team. if ctx.Org.IsMember { if ctx.Org.IsOwner { - if err := org.LoadTeams(); err != nil { + ctx.Org.Teams, err = org.LoadTeams() + if err != nil { ctx.ServerError("LoadTeams", err) return } } else { - org.Teams, err = org.GetUserTeams(ctx.User.ID) + ctx.Org.Teams, err = org.GetUserTeams(ctx.User.ID) if err != nil { ctx.ServerError("GetUserTeams", err) return @@ -140,7 +136,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { teamName := ctx.Params(":team") if len(teamName) > 0 { teamExists := false - for _, team := range org.Teams { + for _, team := range ctx.Org.Teams { if team.LowerName == strings.ToLower(teamName) { teamExists = true ctx.Org.Team = team |