diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/context/api_org.go | 2 | ||||
-rw-r--r-- | modules/context/org.go | 22 | ||||
-rw-r--r-- | modules/convert/convert.go | 4 | ||||
-rw-r--r-- | modules/repository/create_test.go | 7 | ||||
-rw-r--r-- | modules/repository/repo.go | 2 |
5 files changed, 16 insertions, 21 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 diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 80d5ffff05..4229e6cc7d 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -277,10 +277,10 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey { } // ToOrganization convert models.User to api.Organization -func ToOrganization(org *models.User) *api.Organization { +func ToOrganization(org *models.Organization) *api.Organization { return &api.Organization{ ID: org.ID, - AvatarURL: org.AvatarLink(), + AvatarURL: org.AsUser().AvatarLink(), UserName: org.Name, FullName: org.FullName, Description: org.Description, diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go index 55fc515588..12fc7afeeb 100644 --- a/modules/repository/create_test.go +++ b/modules/repository/create_test.go @@ -36,7 +36,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) { assert.NoError(t, err, "GetUserByID") // Create org. - org := &models.User{ + org := &models.Organization{ Name: "All_repo", IsActive: true, Type: models.UserTypeOrganization, @@ -52,7 +52,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) { // Create repos. repoIds := make([]int64, 0) for i := 0; i < 3; i++ { - r, err := CreateRepository(user, org, models.CreateRepoOptions{Name: fmt.Sprintf("repo-%d", i)}) + r, err := CreateRepository(user, org.AsUser(), models.CreateRepoOptions{Name: fmt.Sprintf("repo-%d", i)}) assert.NoError(t, err, "CreateRepository %d", i) if r != nil { repoIds = append(repoIds, r.ID) @@ -114,8 +114,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) { } // Create repo and check teams repositories. - org.Teams = nil // Reset teams to allow their reloading. - r, err := CreateRepository(user, org, models.CreateRepoOptions{Name: "repo-last"}) + r, err := CreateRepository(user, org.AsUser(), models.CreateRepoOptions{Name: "repo-last"}) assert.NoError(t, err, "CreateRepository last") if r != nil { repoIds = append(repoIds, r.ID) diff --git a/modules/repository/repo.go b/modules/repository/repo.go index 871ba617ad..5eec5a7314 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -50,7 +50,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *models.User, repo *models. repoPath := models.RepoPath(u.Name, opts.RepoName) if u.IsOrganization() { - t, err := u.GetOwnerTeam() + t, err := models.OrgFromUser(u).GetOwnerTeam() if err != nil { return nil, err } |