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 /routers/web/org | |
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 'routers/web/org')
-rw-r--r-- | routers/web/org/home.go | 4 | ||||
-rw-r--r-- | routers/web/org/org.go | 4 | ||||
-rw-r--r-- | routers/web/org/setting.go | 14 | ||||
-rw-r--r-- | routers/web/org/teams.go | 6 |
4 files changed, 15 insertions, 13 deletions
diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 89bd12a18f..0752fa12cb 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -30,7 +30,7 @@ func Home(ctx *context.Context) { org := ctx.Org.Organization - if !models.HasOrgOrUserVisible(org, ctx.User) { + if !models.HasOrgOrUserVisible(org.AsUser(), ctx.User) { ctx.NotFound("HasOrgOrUserVisible", nil) return } @@ -140,7 +140,7 @@ func Home(ctx *context.Context) { ctx.Data["Total"] = count ctx.Data["MembersTotal"] = membersCount ctx.Data["Members"] = members - ctx.Data["Teams"] = org.Teams + ctx.Data["Teams"] = ctx.Org.Teams ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull diff --git a/routers/web/org/org.go b/routers/web/org/org.go index beba3daca4..6722f8d104 100644 --- a/routers/web/org/org.go +++ b/routers/web/org/org.go @@ -49,7 +49,7 @@ func CreatePost(ctx *context.Context) { return } - org := &models.User{ + org := &models.Organization{ Name: form.OrgName, IsActive: true, Type: models.UserTypeOrganization, @@ -75,5 +75,5 @@ func CreatePost(ctx *context.Context) { } log.Trace("Organization created: %s", org.Name) - ctx.Redirect(org.DashboardLink()) + ctx.Redirect(org.AsUser().DashboardLink()) } diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index f27cb40838..f05dbd8bc1 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -68,7 +68,7 @@ func SettingsPost(ctx *context.Context) { ctx.Data["OrgName"] = true ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSettingsOptions, &form) return - } else if err = models.ChangeUserName(org, form.Name); err != nil { + } else if err = models.ChangeUserName(org.AsUser(), form.Name); err != nil { if err == models.ErrUserNameIllegal { ctx.Data["OrgName"] = true ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form) @@ -100,18 +100,20 @@ func SettingsPost(ctx *context.Context) { visibilityChanged := form.Visibility != org.Visibility org.Visibility = form.Visibility - if err := models.UpdateUser(org); err != nil { + if err := models.UpdateUser(org.AsUser()); err != nil { ctx.ServerError("UpdateUser", err) return } // update forks visibility if visibilityChanged { - if err := org.GetRepositories(db.ListOptions{Page: 1, PageSize: org.NumRepos}); err != nil { + repos, _, err := models.GetUserRepositories(&models.SearchRepoOptions{ + Actor: org.AsUser(), Private: true, ListOptions: db.ListOptions{Page: 1, PageSize: org.NumRepos}}) + if err != nil { ctx.ServerError("GetRepositories", err) return } - for _, repo := range org.Repos { + for _, repo := range repos { repo.OwnerName = org.Name if err := models.UpdateRepository(repo, true); err != nil { ctx.ServerError("UpdateRepository", err) @@ -134,7 +136,7 @@ func SettingsPost(ctx *context.Context) { func SettingsAvatar(ctx *context.Context) { form := web.GetForm(ctx).(*forms.AvatarForm) form.Source = forms.AvatarLocal - if err := userSetting.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil { + if err := userSetting.UpdateAvatarSetting(ctx, form, ctx.Org.Organization.AsUser()); err != nil { ctx.Flash.Error(err.Error()) } else { ctx.Flash.Success(ctx.Tr("org.settings.update_avatar_success")) @@ -145,7 +147,7 @@ func SettingsAvatar(ctx *context.Context) { // SettingsDeleteAvatar response for delete avatar on settings page func SettingsDeleteAvatar(ctx *context.Context) { - if err := ctx.Org.Organization.DeleteAvatar(); err != nil { + if err := ctx.Org.Organization.AsUser().DeleteAvatar(); err != nil { ctx.Flash.Error(err.Error()) } diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 28ffac4dd3..ac6a42904a 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -38,13 +38,13 @@ func Teams(ctx *context.Context) { ctx.Data["Title"] = org.FullName ctx.Data["PageIsOrgTeams"] = true - for _, t := range org.Teams { + for _, t := range ctx.Org.Teams { if err := t.GetMembers(&models.SearchMembersOptions{}); err != nil { ctx.ServerError("GetMembers", err) return } } - ctx.Data["Teams"] = org.Teams + ctx.Data["Teams"] = ctx.Org.Teams ctx.HTML(http.StatusOK, tplTeams) } @@ -158,7 +158,7 @@ func TeamsAction(ctx *context.Context) { case "team": ctx.Redirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName)) case "home": - ctx.Redirect(ctx.Org.Organization.HomeLink()) + ctx.Redirect(ctx.Org.Organization.AsUser().HomeLink()) default: ctx.Redirect(ctx.Org.OrgLink + "/teams") } |