aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/org
diff options
context:
space:
mode:
Diffstat (limited to 'routers/web/org')
-rw-r--r--routers/web/org/home.go9
-rw-r--r--routers/web/org/members.go19
-rw-r--r--routers/web/org/org.go8
-rw-r--r--routers/web/org/teams.go49
4 files changed, 44 insertions, 41 deletions
diff --git a/routers/web/org/home.go b/routers/web/org/home.go
index 1466731b9e..24a0f13b54 100644
--- a/routers/web/org/home.go
+++ b/routers/web/org/home.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/organization"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -39,7 +40,7 @@ func Home(ctx *context.Context) {
org := ctx.Org.Organization
- if !models.HasOrgOrUserVisible(org.AsUser(), ctx.Doer) {
+ if !organization.HasOrgOrUserVisible(ctx, org.AsUser(), ctx.Doer) {
ctx.NotFound("HasOrgOrUserVisible", nil)
return
}
@@ -122,7 +123,7 @@ func Home(ctx *context.Context) {
return
}
- opts := &models.FindOrgMembersOpts{
+ opts := &organization.FindOrgMembersOpts{
OrgID: org.ID,
PublicOnly: true,
ListOptions: db.ListOptions{Page: 1, PageSize: 25},
@@ -137,13 +138,13 @@ func Home(ctx *context.Context) {
opts.PublicOnly = !isMember && !ctx.Doer.IsAdmin
}
- members, _, err := models.FindOrgMembers(opts)
+ members, _, err := organization.FindOrgMembers(opts)
if err != nil {
ctx.ServerError("FindOrgMembers", err)
return
}
- membersCount, err := models.CountOrgMembers(opts)
+ membersCount, err := organization.CountOrgMembers(opts)
if err != nil {
ctx.ServerError("CountOrgMembers", err)
return
diff --git a/routers/web/org/members.go b/routers/web/org/members.go
index 9e65e61404..add8e724bd 100644
--- a/routers/web/org/members.go
+++ b/routers/web/org/members.go
@@ -9,6 +9,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -31,7 +32,7 @@ func Members(ctx *context.Context) {
page = 1
}
- opts := &models.FindOrgMembersOpts{
+ opts := &organization.FindOrgMembersOpts{
OrgID: org.ID,
PublicOnly: true,
}
@@ -45,7 +46,7 @@ func Members(ctx *context.Context) {
opts.PublicOnly = !isMember && !ctx.Doer.IsAdmin
}
- total, err := models.CountOrgMembers(opts)
+ total, err := organization.CountOrgMembers(opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CountOrgMembers")
return
@@ -54,7 +55,7 @@ func Members(ctx *context.Context) {
pager := context.NewPagination(int(total), setting.UI.MembersPagingNum, page, 5)
opts.ListOptions.Page = page
opts.ListOptions.PageSize = setting.UI.MembersPagingNum
- members, membersIsPublic, err := models.FindOrgMembers(opts)
+ members, membersIsPublic, err := organization.FindOrgMembers(opts)
if err != nil {
ctx.ServerError("GetMembers", err)
return
@@ -84,20 +85,20 @@ func MembersAction(ctx *context.Context) {
ctx.Error(http.StatusNotFound)
return
}
- err = models.ChangeOrgUserStatus(org.ID, uid, false)
+ err = organization.ChangeOrgUserStatus(org.ID, uid, false)
case "public":
if ctx.Doer.ID != uid && !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound)
return
}
- err = models.ChangeOrgUserStatus(org.ID, uid, true)
+ err = organization.ChangeOrgUserStatus(org.ID, uid, true)
case "remove":
if !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound)
return
}
- err = org.RemoveMember(uid)
- if models.IsErrLastOrgOwner(err) {
+ err = models.RemoveOrgUser(org.ID, uid)
+ if organization.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": ctx.Org.OrgLink + "/members",
@@ -105,8 +106,8 @@ func MembersAction(ctx *context.Context) {
return
}
case "leave":
- err = org.RemoveMember(ctx.Doer.ID)
- if models.IsErrLastOrgOwner(err) {
+ err = models.RemoveOrgUser(org.ID, ctx.Doer.ID)
+ if organization.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": ctx.Org.OrgLink + "/members",
diff --git a/routers/web/org/org.go b/routers/web/org/org.go
index b641f768b2..32d8787995 100644
--- a/routers/web/org/org.go
+++ b/routers/web/org/org.go
@@ -9,8 +9,8 @@ import (
"errors"
"net/http"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/organization"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -51,7 +51,7 @@ func CreatePost(ctx *context.Context) {
return
}
- org := &models.Organization{
+ org := &organization.Organization{
Name: form.OrgName,
IsActive: true,
Type: user_model.UserTypeOrganization,
@@ -59,7 +59,7 @@ func CreatePost(ctx *context.Context) {
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
}
- if err := models.CreateOrganization(org, ctx.Doer); err != nil {
+ if err := organization.CreateOrganization(org, ctx.Doer); err != nil {
ctx.Data["Err_OrgName"] = true
switch {
case user_model.IsErrUserAlreadyExist(err):
@@ -68,7 +68,7 @@ func CreatePost(ctx *context.Context) {
ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(db.ErrNameReserved).Name), tplCreateOrg, &form)
case db.IsErrNamePatternNotAllowed(err):
ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form)
- case models.IsErrUserNotAllowedCreateOrg(err):
+ case organization.IsErrUserNotAllowedCreateOrg(err):
ctx.RenderWithErr(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form)
default:
ctx.ServerError("CreateOrganization", err)
diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go
index d13c4e854d..034a8ce978 100644
--- a/routers/web/org/teams.go
+++ b/routers/web/org/teams.go
@@ -13,6 +13,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
repo_model "code.gitea.io/gitea/models/repo"
unit_model "code.gitea.io/gitea/models/unit"
@@ -43,7 +44,7 @@ func Teams(ctx *context.Context) {
ctx.Data["PageIsOrgTeams"] = true
for _, t := range ctx.Org.Teams {
- if err := t.GetMembers(&models.SearchMembersOptions{}); err != nil {
+ if err := t.GetMembersCtx(ctx); err != nil {
ctx.ServerError("GetMembers", err)
return
}
@@ -69,11 +70,11 @@ func TeamsAction(ctx *context.Context) {
ctx.Error(http.StatusNotFound)
return
}
- err = ctx.Org.Team.AddMember(ctx.Doer.ID)
+ err = models.AddTeamMember(ctx.Org.Team, ctx.Doer.ID)
case "leave":
- err = ctx.Org.Team.RemoveMember(ctx.Doer.ID)
+ err = models.RemoveTeamMember(ctx.Org.Team, ctx.Doer.ID)
if err != nil {
- if models.IsErrLastOrgOwner(err) {
+ if organization.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
} else {
log.Error("Action(%s): %v", ctx.Params(":action"), err)
@@ -94,9 +95,9 @@ func TeamsAction(ctx *context.Context) {
ctx.Error(http.StatusNotFound)
return
}
- err = ctx.Org.Team.RemoveMember(uid)
+ err = models.RemoveTeamMember(ctx.Org.Team, uid)
if err != nil {
- if models.IsErrLastOrgOwner(err) {
+ if organization.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
} else {
log.Error("Action(%s): %v", ctx.Params(":action"), err)
@@ -139,14 +140,14 @@ func TeamsAction(ctx *context.Context) {
if ctx.Org.Team.IsMember(u.ID) {
ctx.Flash.Error(ctx.Tr("org.teams.add_duplicate_users"))
} else {
- err = ctx.Org.Team.AddMember(u.ID)
+ err = models.AddTeamMember(ctx.Org.Team, u.ID)
}
page = "team"
}
if err != nil {
- if models.IsErrLastOrgOwner(err) {
+ if organization.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
} else {
log.Error("Action(%s): %v", ctx.Params(":action"), err)
@@ -191,13 +192,13 @@ func TeamsRepoAction(ctx *context.Context) {
ctx.ServerError("GetRepositoryByName", err)
return
}
- err = ctx.Org.Team.AddRepository(repo)
+ err = models.AddRepository(ctx.Org.Team, repo)
case "remove":
- err = ctx.Org.Team.RemoveRepository(ctx.FormInt64("repoid"))
+ err = models.RemoveRepository(ctx.Org.Team, ctx.FormInt64("repoid"))
case "addall":
- err = ctx.Org.Team.AddAllRepositories()
+ err = models.AddAllRepositories(ctx.Org.Team)
case "removeall":
- err = ctx.Org.Team.RemoveAllRepositories()
+ err = models.RemoveAllRepositories(ctx.Org.Team)
}
if err != nil {
@@ -220,7 +221,7 @@ func NewTeam(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true
ctx.Data["PageIsOrgTeamsNew"] = true
- ctx.Data["Team"] = &models.Team{}
+ ctx.Data["Team"] = &organization.Team{}
ctx.Data["Units"] = unit_model.Units
ctx.HTML(http.StatusOK, tplTeamNew)
}
@@ -251,7 +252,7 @@ func NewTeamPost(ctx *context.Context) {
p = unit_model.MinUnitAccessMode(unitPerms)
}
- t := &models.Team{
+ t := &organization.Team{
OrgID: ctx.Org.Organization.ID,
Name: form.TeamName,
Description: form.Description,
@@ -261,9 +262,9 @@ func NewTeamPost(ctx *context.Context) {
}
if t.AccessMode < perm.AccessModeAdmin {
- units := make([]*models.TeamUnit, 0, len(unitPerms))
+ units := make([]*organization.TeamUnit, 0, len(unitPerms))
for tp, perm := range unitPerms {
- units = append(units, &models.TeamUnit{
+ units = append(units, &organization.TeamUnit{
OrgID: ctx.Org.Organization.ID,
Type: tp,
AccessMode: perm,
@@ -291,7 +292,7 @@ func NewTeamPost(ctx *context.Context) {
if err := models.NewTeam(t); err != nil {
ctx.Data["Err_TeamName"] = true
switch {
- case models.IsErrTeamAlreadyExist(err):
+ case organization.IsErrTeamAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form)
default:
ctx.ServerError("NewTeam", err)
@@ -307,7 +308,7 @@ func TeamMembers(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true
ctx.Data["PageIsOrgTeamMembers"] = true
- if err := ctx.Org.Team.GetMembers(&models.SearchMembersOptions{}); err != nil {
+ if err := ctx.Org.Team.GetMembersCtx(ctx); err != nil {
ctx.ServerError("GetMembers", err)
return
}
@@ -320,7 +321,7 @@ func TeamRepositories(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true
ctx.Data["PageIsOrgTeamRepos"] = true
- if err := ctx.Org.Team.GetRepositories(&models.SearchOrgTeamOptions{}); err != nil {
+ if err := ctx.Org.Team.GetRepositoriesCtx(ctx); err != nil {
ctx.ServerError("GetRepositories", err)
return
}
@@ -374,17 +375,17 @@ func EditTeamPost(ctx *context.Context) {
}
t.Description = form.Description
if t.AccessMode < perm.AccessModeAdmin {
- units := make([]models.TeamUnit, 0, len(unitPerms))
+ units := make([]organization.TeamUnit, 0, len(unitPerms))
for tp, perm := range unitPerms {
- units = append(units, models.TeamUnit{
+ units = append(units, organization.TeamUnit{
OrgID: t.OrgID,
TeamID: t.ID,
Type: tp,
AccessMode: perm,
})
}
- if err := models.UpdateTeamUnits(t, units); err != nil {
- ctx.Error(http.StatusInternalServerError, "LoadIssue", err.Error())
+ if err := organization.UpdateTeamUnits(t, units); err != nil {
+ ctx.Error(http.StatusInternalServerError, "UpdateTeamUnits", err.Error())
return
}
}
@@ -403,7 +404,7 @@ func EditTeamPost(ctx *context.Context) {
if err := models.UpdateTeam(t, isAuthChanged, isIncludeAllChanged); err != nil {
ctx.Data["Err_TeamName"] = true
switch {
- case models.IsErrTeamAlreadyExist(err):
+ case organization.IsErrTeamAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form)
default:
ctx.ServerError("UpdateTeam", err)