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
|
||||
|
@@ -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,
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user