summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-19 19:41:40 +0800
committerGitHub <noreply@github.com>2021-11-19 19:41:40 +0800
commit7a0347315995b25bcb2dca4786504fb699b5f004 (patch)
tree803dfd39286216fd0521ad16539ffd9fc5f87fc0 /routers
parenta09b40de8d1dae7107437cfba42cee201fcd6d42 (diff)
downloadgitea-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')
-rw-r--r--routers/api/v1/admin/org.go4
-rw-r--r--routers/api/v1/org/hook.go4
-rw-r--r--routers/api/v1/org/label.go8
-rw-r--r--routers/api/v1/org/org.go15
-rw-r--r--routers/api/v1/org/team.go2
-rw-r--r--routers/api/v1/repo/fork.go2
-rw-r--r--routers/api/v1/repo/migrate.go2
-rw-r--r--routers/api/v1/repo/repo.go6
-rw-r--r--routers/api/v1/repo/transfer.go4
-rw-r--r--routers/api/v1/user/repo.go2
-rw-r--r--routers/api/v1/utils/hook.go4
-rw-r--r--routers/web/org/home.go4
-rw-r--r--routers/web/org/org.go4
-rw-r--r--routers/web/org/setting.go14
-rw-r--r--routers/web/org/teams.go6
-rw-r--r--routers/web/repo/issue.go13
-rw-r--r--routers/web/repo/issue_label.go2
-rw-r--r--routers/web/repo/pull.go2
-rw-r--r--routers/web/repo/repo.go2
-rw-r--r--routers/web/repo/setting.go4
-rw-r--r--routers/web/repo/setting_protected_branch.go2
-rw-r--r--routers/web/repo/tag.go2
-rw-r--r--routers/web/user/home.go12
-rw-r--r--routers/web/user/oauth.go6
24 files changed, 66 insertions, 60 deletions
diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go
index 5da87fa7df..2633865d2c 100644
--- a/routers/api/v1/admin/org.go
+++ b/routers/api/v1/admin/org.go
@@ -54,7 +54,7 @@ func CreateOrg(ctx *context.APIContext) {
visibility = api.VisibilityModes[form.Visibility]
}
- org := &models.User{
+ org := &models.Organization{
Name: form.UserName,
FullName: form.FullName,
Description: form.Description,
@@ -117,7 +117,7 @@ func GetAllOrgs(ctx *context.APIContext) {
}
orgs := make([]*api.Organization, len(users))
for i := range users {
- orgs[i] = convert.ToOrganization(users[i])
+ orgs[i] = convert.ToOrganization(models.OrgFromUser(users[i]))
}
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
diff --git a/routers/api/v1/org/hook.go b/routers/api/v1/org/hook.go
index 6c81616170..b9d1fa2f67 100644
--- a/routers/api/v1/org/hook.go
+++ b/routers/api/v1/org/hook.go
@@ -59,7 +59,7 @@ func ListHooks(ctx *context.APIContext) {
hooks := make([]*api.Hook, len(orgHooks))
for i, hook := range orgHooks {
- hooks[i] = convert.ToHook(ctx.Org.Organization.HomeLink(), hook)
+ hooks[i] = convert.ToHook(ctx.Org.Organization.AsUser().HomeLink(), hook)
}
ctx.SetTotalCountHeader(count)
@@ -95,7 +95,7 @@ func GetHook(ctx *context.APIContext) {
if err != nil {
return
}
- ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), hook))
+ ctx.JSON(http.StatusOK, convert.ToHook(org.AsUser().HomeLink(), hook))
}
// CreateHook create a hook for an organization
diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go
index b375284189..7d4c12d364 100644
--- a/routers/api/v1/org/label.go
+++ b/routers/api/v1/org/label.go
@@ -56,7 +56,7 @@ func ListLabels(ctx *context.APIContext) {
}
ctx.SetTotalCountHeader(count)
- ctx.JSON(http.StatusOK, convert.ToLabelList(labels, nil, ctx.Org.Organization))
+ ctx.JSON(http.StatusOK, convert.ToLabelList(labels, nil, ctx.Org.Organization.AsUser()))
}
// CreateLabel create a label for a repository
@@ -104,7 +104,7 @@ func CreateLabel(ctx *context.APIContext) {
return
}
- ctx.JSON(http.StatusCreated, convert.ToLabel(label, nil, ctx.Org.Organization))
+ ctx.JSON(http.StatusCreated, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser()))
}
// GetLabel get label by organization and label id
@@ -149,7 +149,7 @@ func GetLabel(ctx *context.APIContext) {
return
}
- ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization))
+ ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser()))
}
// EditLabel modify a label for an Organization
@@ -214,7 +214,7 @@ func EditLabel(ctx *context.APIContext) {
return
}
- ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization))
+ ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser()))
}
// DeleteLabel delete a label for an organization
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go
index e82e8552e0..bbf127f891 100644
--- a/routers/api/v1/org/org.go
+++ b/routers/api/v1/org/org.go
@@ -31,7 +31,7 @@ func listUserOrgs(ctx *context.APIContext, u *models.User) {
}
maxResults := len(orgs)
- orgs, _ = util.PaginateSlice(orgs, listOptions.Page, listOptions.PageSize).([]*models.User)
+ orgs, _ = util.PaginateSlice(orgs, listOptions.Page, listOptions.PageSize).([]*models.Organization)
apiOrgs := make([]*api.Organization, len(orgs))
for i := range orgs {
@@ -141,7 +141,8 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
return
}
- authorizeLevel, err := o.GetOrgUserMaxAuthorizeLevel(u.ID)
+ org := models.OrgFromUser(o)
+ authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(u.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetOrgUserAuthorizeLevel", err)
return
@@ -160,7 +161,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
op.IsOwner = true
}
- op.CanCreateRepository, err = o.CanCreateOrgRepo(u.ID)
+ op.CanCreateRepository, err = org.CanCreateOrgRepo(u.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
return
@@ -212,7 +213,7 @@ func GetAll(ctx *context.APIContext) {
}
orgs := make([]*api.Organization, len(publicOrgs))
for i := range publicOrgs {
- orgs[i] = convert.ToOrganization(publicOrgs[i])
+ orgs[i] = convert.ToOrganization(models.OrgFromUser(publicOrgs[i]))
}
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
@@ -252,7 +253,7 @@ func Create(ctx *context.APIContext) {
visibility = api.VisibilityModes[form.Visibility]
}
- org := &models.User{
+ org := &models.Organization{
Name: form.UserName,
FullName: form.FullName,
Description: form.Description,
@@ -295,7 +296,7 @@ func Get(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/Organization"
- if !models.HasOrgOrUserVisible(ctx.Org.Organization, ctx.User) {
+ if !models.HasOrgOrUserVisible(ctx.Org.Organization.AsUser(), ctx.User) {
ctx.NotFound("HasOrgOrUserVisible", nil)
return
}
@@ -337,7 +338,7 @@ func Edit(ctx *context.APIContext) {
if form.RepoAdminChangeTeamAccess != nil {
org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
}
- if err := models.UpdateUserCols(org,
+ if err := models.UpdateUserCols(org.AsUser(),
"full_name", "description", "website", "location",
"visibility", "repo_admin_change_team_access",
); err != nil {
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
index 0dc1b68aee..e78e487895 100644
--- a/routers/api/v1/org/team.go
+++ b/routers/api/v1/org/team.go
@@ -102,7 +102,7 @@ func ListUserTeams(ctx *context.APIContext) {
for i := range teams {
apiOrg, ok := cache[teams[i].OrgID]
if !ok {
- org, err := models.GetUserByID(teams[i].OrgID)
+ org, err := models.GetOrgByID(teams[i].OrgID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
return
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index b3504faad9..45d3c815a7 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -120,7 +120,7 @@ func CreateFork(ctx *context.APIContext) {
ctx.Error(http.StatusForbidden, "isMemberNot", fmt.Sprintf("User is no Member of Organisation '%s'", org.Name))
return
}
- forker = org
+ forker = org.AsUser()
}
fork, err := repo_service.ForkRepository(ctx.User, forker, models.ForkRepoOptions{
diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go
index 00390dfb5f..1880a88367 100644
--- a/routers/api/v1/repo/migrate.go
+++ b/routers/api/v1/repo/migrate.go
@@ -86,7 +86,7 @@ func Migrate(ctx *context.APIContext) {
if repoOwner.IsOrganization() {
// Check ownership of organization.
- isOwner, err := repoOwner.IsOwnedBy(ctx.User.ID)
+ isOwner, err := models.OrgFromUser(repoOwner).IsOwnedBy(ctx.User.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsOwnedBy", err)
return
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 22f9da614d..872ce22871 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -393,7 +393,7 @@ func Generate(ctx *context.APIContext) {
}
if !ctx.User.IsAdmin {
- canCreate, err := ctxUser.CanCreateOrgRepo(ctx.User.ID)
+ canCreate, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.User.ID)
if err != nil {
ctx.ServerError("CanCreateOrgRepo", err)
return
@@ -489,7 +489,7 @@ func CreateOrgRepo(ctx *context.APIContext) {
return
}
- if !models.HasOrgOrUserVisible(org, ctx.User) {
+ if !models.HasOrgOrUserVisible(org.AsUser(), ctx.User) {
ctx.NotFound("HasOrgOrUserVisible", nil)
return
}
@@ -504,7 +504,7 @@ func CreateOrgRepo(ctx *context.APIContext) {
return
}
}
- CreateUserRepo(ctx, org, *opt)
+ CreateUserRepo(ctx, org.AsUser(), *opt)
}
// Get one repository
diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go
index c13a2e4857..f16e2bb081 100644
--- a/routers/api/v1/repo/transfer.go
+++ b/routers/api/v1/repo/transfer.go
@@ -64,7 +64,7 @@ func Transfer(ctx *context.APIContext) {
}
if newOwner.Type == models.UserTypeOrganization {
- if !ctx.User.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !newOwner.HasMemberWithUserID(ctx.User.ID) {
+ if !ctx.User.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) {
// The user shouldn't know about this organization
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
return
@@ -78,7 +78,7 @@ func Transfer(ctx *context.APIContext) {
return
}
- org := convert.ToOrganization(newOwner)
+ org := convert.ToOrganization(models.OrgFromUser(newOwner))
for _, tID := range *opts.TeamIDs {
team, err := models.GetTeamByID(tID)
if err != nil {
diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go
index 5116c17ab2..3c9a17a0be 100644
--- a/routers/api/v1/user/repo.go
+++ b/routers/api/v1/user/repo.go
@@ -157,5 +157,5 @@ func ListOrgRepos(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/RepositoryList"
- listUserRepos(ctx, ctx.Org.Organization, ctx.IsSigned)
+ listUserRepos(ctx, ctx.Org.Organization.AsUser(), ctx.IsSigned)
}
diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go
index aef9b8f4ce..1f0a35ce22 100644
--- a/routers/api/v1/utils/hook.go
+++ b/routers/api/v1/utils/hook.go
@@ -75,7 +75,7 @@ func AddOrgHook(ctx *context.APIContext, form *api.CreateHookOption) {
org := ctx.Org.Organization
hook, ok := addHook(ctx, form, org.ID, 0)
if ok {
- ctx.JSON(http.StatusCreated, convert.ToHook(org.HomeLink(), hook))
+ ctx.JSON(http.StatusCreated, convert.ToHook(org.AsUser().HomeLink(), hook))
}
}
@@ -185,7 +185,7 @@ func EditOrgHook(ctx *context.APIContext, form *api.EditHookOption, hookID int64
if err != nil {
return
}
- ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), updated))
+ ctx.JSON(http.StatusOK, convert.ToHook(org.AsUser().HomeLink(), updated))
}
// EditRepoHook edit webhook `w` according to `form`. Writes to `ctx` accordingly
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")
}
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index 95363258e9..129287b96a 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -2644,13 +2644,15 @@ func handleTeamMentions(ctx *context.Context) {
return
}
- isAdmin := false
+ var isAdmin bool
var err error
+ var teams []*models.Team
+ var org = models.OrgFromUser(ctx.Repo.Owner)
// Admin has super access.
if ctx.User.IsAdmin {
isAdmin = true
} else {
- isAdmin, err = ctx.Repo.Owner.IsOwnedBy(ctx.User.ID)
+ isAdmin, err = org.IsOwnedBy(ctx.User.ID)
if err != nil {
ctx.ServerError("IsOwnedBy", err)
return
@@ -2658,19 +2660,20 @@ func handleTeamMentions(ctx *context.Context) {
}
if isAdmin {
- if err := ctx.Repo.Owner.LoadTeams(); err != nil {
+ teams, err = org.LoadTeams()
+ if err != nil {
ctx.ServerError("LoadTeams", err)
return
}
} else {
- ctx.Repo.Owner.Teams, err = ctx.Repo.Owner.GetUserTeams(ctx.User.ID)
+ teams, err = org.GetUserTeams(ctx.User.ID)
if err != nil {
ctx.ServerError("GetUserTeams", err)
return
}
}
- ctx.Data["MentionableTeams"] = ctx.Repo.Owner.Teams
+ ctx.Data["MentionableTeams"] = teams
ctx.Data["MentionableTeamsOrg"] = ctx.Repo.Owner.Name
ctx.Data["MentionableTeamsOrgAvatar"] = ctx.Repo.Owner.AvatarLink()
}
diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go
index b97f57175b..c6fa8c4c8c 100644
--- a/routers/web/repo/issue_label.go
+++ b/routers/web/repo/issue_label.go
@@ -88,7 +88,7 @@ func RetrieveLabels(ctx *context.Context) {
ctx.ServerError("org.IsOwnedBy", err)
return
}
- ctx.Org.OrgLink = org.OrganisationLink()
+ ctx.Org.OrgLink = org.AsUser().OrganisationLink()
ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner
ctx.Data["OrganizationLink"] = ctx.Org.OrgLink
}
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 4337278214..d5aa480d1f 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -217,7 +217,7 @@ func ForkPost(ctx *context.Context) {
// Check ownership of organization.
if ctxUser.IsOrganization() {
- isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID)
+ isOwner, err := models.OrgFromUser(ctxUser).IsOwnedBy(ctx.User.ID)
if err != nil {
ctx.ServerError("IsOwnedBy", err)
return
diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go
index 5e15415d6a..2d6189824d 100644
--- a/routers/web/repo/repo.go
+++ b/routers/web/repo/repo.go
@@ -94,7 +94,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
return nil
}
if !ctx.User.IsAdmin {
- canCreate, err := org.CanCreateOrgRepo(ctx.User.ID)
+ canCreate, err := models.OrgFromUser(org).CanCreateOrgRepo(ctx.User.ID)
if err != nil {
ctx.ServerError("CanCreateOrgRepo", err)
return nil
diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go
index 641052316c..9b5f635988 100644
--- a/routers/web/repo/setting.go
+++ b/routers/web/repo/setting.go
@@ -588,7 +588,7 @@ func SettingsPost(ctx *context.Context) {
}
if newOwner.Type == models.UserTypeOrganization {
- if !ctx.User.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !newOwner.HasMemberWithUserID(ctx.User.ID) {
+ if !ctx.User.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) {
// The user shouldn't know about this organization
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
return
@@ -879,7 +879,7 @@ func AddTeamPost(ctx *context.Context) {
return
}
- team, err := ctx.Repo.Owner.GetTeam(name)
+ team, err := models.OrgFromUser(ctx.Repo.Owner).GetTeam(name)
if err != nil {
if models.IsErrTeamNotExist(err) {
ctx.Flash.Error(ctx.Tr("form.team_not_exist"))
diff --git a/routers/web/repo/setting_protected_branch.go b/routers/web/repo/setting_protected_branch.go
index 32105b1d43..b13dfae683 100644
--- a/routers/web/repo/setting_protected_branch.go
+++ b/routers/web/repo/setting_protected_branch.go
@@ -156,7 +156,7 @@ func SettingsProtectedBranch(c *context.Context) {
}
if c.Repo.Owner.IsOrganization() {
- teams, err := c.Repo.Owner.TeamsWithAccessToRepo(c.Repo.Repository.ID, models.AccessModeRead)
+ teams, err := models.OrgFromUser(c.Repo.Owner).TeamsWithAccessToRepo(c.Repo.Repository.ID, models.AccessModeRead)
if err != nil {
c.ServerError("Repo.Owner.TeamsWithAccessToRepo", err)
return
diff --git a/routers/web/repo/tag.go b/routers/web/repo/tag.go
index b4d268759c..4383b6214a 100644
--- a/routers/web/repo/tag.go
+++ b/routers/web/repo/tag.go
@@ -149,7 +149,7 @@ func setTagsContext(ctx *context.Context) error {
ctx.Data["Users"] = users
if ctx.Repo.Owner.IsOrganization() {
- teams, err := ctx.Repo.Owner.TeamsWithAccessToRepo(ctx.Repo.Repository.ID, models.AccessModeRead)
+ teams, err := models.OrgFromUser(ctx.Repo.Owner).TeamsWithAccessToRepo(ctx.Repo.Repository.ID, models.AccessModeRead)
if err != nil {
ctx.ServerError("Repo.Owner.TeamsWithAccessToRepo", err)
return err
diff --git a/routers/web/user/home.go b/routers/web/user/home.go
index b9f5d044fa..c0ecd0c2a0 100644
--- a/routers/web/user/home.go
+++ b/routers/web/user/home.go
@@ -47,8 +47,8 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
ctxUser := ctx.User
orgName := ctx.Params(":org")
if len(orgName) > 0 {
- ctxUser = ctx.Org.Organization
- ctx.Data["Teams"] = ctx.Org.Organization.Teams
+ ctxUser = ctx.Org.Organization.AsUser()
+ ctx.Data["Teams"] = ctx.Org.Teams
}
ctx.Data["ContextUser"] = ctxUser
@@ -97,9 +97,9 @@ func Dashboard(ctx *context.Context) {
if ctxUser.IsOrganization() {
var env models.AccessibleReposEnvironment
if ctx.Org.Team != nil {
- env = ctxUser.AccessibleTeamReposEnv(ctx.Org.Team)
+ env = models.OrgFromUser(ctxUser).AccessibleTeamReposEnv(ctx.Org.Team)
} else {
- env, err = ctxUser.AccessibleReposEnv(ctx.User.ID)
+ env, err = models.OrgFromUser(ctxUser).AccessibleReposEnv(ctx.User.ID)
if err != nil {
ctx.ServerError("AccessibleReposEnv", err)
return
@@ -756,9 +756,9 @@ func getActiveTeamOrOrgRepoIds(ctxUser *models.User, team *models.Team, unitType
var env models.AccessibleReposEnvironment
if team != nil {
- env = ctxUser.AccessibleTeamReposEnv(team)
+ env = models.OrgFromUser(ctxUser).AccessibleTeamReposEnv(team)
} else {
- env, err = ctxUser.AccessibleReposEnv(ctxUser.ID)
+ env, err = models.OrgFromUser(ctxUser).AccessibleReposEnv(ctxUser.ID)
if err != nil {
return nil, fmt.Errorf("AccessibleReposEnv: %v", err)
}
diff --git a/routers/web/user/oauth.go b/routers/web/user/oauth.go
index 3210d033d3..7b1854c521 100644
--- a/routers/web/user/oauth.go
+++ b/routers/web/user/oauth.go
@@ -283,11 +283,11 @@ func getOAuthGroupsForUser(user *models.User) ([]string, error) {
var groups []string
for _, org := range orgs {
groups = append(groups, org.Name)
-
- if err := org.LoadTeams(); err != nil {
+ teams, err := org.LoadTeams()
+ if err != nil {
return nil, fmt.Errorf("LoadTeams: %v", err)
}
- for _, team := range org.Teams {
+ for _, team := range teams {
if team.IsMember(user.ID) {
groups = append(groups, org.Name+":"+team.LowerName)
}