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:
@@ -10,6 +10,6 @@ import (
|
||||
|
||||
// APIOrganization contains organization and team
|
||||
type APIOrganization struct {
|
||||
Organization *models.User
|
||||
Organization *models.Organization
|
||||
Team *models.Team
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user