diff options
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r-- | routers/api/v1/repo/branch.go | 25 | ||||
-rw-r--r-- | routers/api/v1/repo/fork.go | 5 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 5 | ||||
-rw-r--r-- | routers/api/v1/repo/migrate.go | 3 | ||||
-rw-r--r-- | routers/api/v1/repo/pull_review.go | 9 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 9 | ||||
-rw-r--r-- | routers/api/v1/repo/teams.go | 17 | ||||
-rw-r--r-- | routers/api/v1/repo/transfer.go | 9 |
8 files changed, 45 insertions, 37 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index 065bad2708..f22bed813e 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -11,6 +11,7 @@ import ( "net/http" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/organization" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" @@ -448,27 +449,27 @@ func CreateBranchProtection(ctx *context.APIContext) { } var whitelistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64 if repo.Owner.IsOrganization() { - whitelistTeams, err = models.GetTeamIDsByNames(repo.OwnerID, form.PushWhitelistTeams, false) + whitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.PushWhitelistTeams, false) if err != nil { - if models.IsErrTeamNotExist(err) { + if organization.IsErrTeamNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) return } ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err) return } - mergeWhitelistTeams, err = models.GetTeamIDsByNames(repo.OwnerID, form.MergeWhitelistTeams, false) + mergeWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.MergeWhitelistTeams, false) if err != nil { - if models.IsErrTeamNotExist(err) { + if organization.IsErrTeamNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) return } ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err) return } - approvalsWhitelistTeams, err = models.GetTeamIDsByNames(repo.OwnerID, form.ApprovalsWhitelistTeams, false) + approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.ApprovalsWhitelistTeams, false) if err != nil { - if models.IsErrTeamNotExist(err) { + if organization.IsErrTeamNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) return } @@ -692,9 +693,9 @@ func EditBranchProtection(ctx *context.APIContext) { var whitelistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64 if repo.Owner.IsOrganization() { if form.PushWhitelistTeams != nil { - whitelistTeams, err = models.GetTeamIDsByNames(repo.OwnerID, form.PushWhitelistTeams, false) + whitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.PushWhitelistTeams, false) if err != nil { - if models.IsErrTeamNotExist(err) { + if organization.IsErrTeamNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) return } @@ -705,9 +706,9 @@ func EditBranchProtection(ctx *context.APIContext) { whitelistTeams = protectBranch.WhitelistTeamIDs } if form.MergeWhitelistTeams != nil { - mergeWhitelistTeams, err = models.GetTeamIDsByNames(repo.OwnerID, form.MergeWhitelistTeams, false) + mergeWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.MergeWhitelistTeams, false) if err != nil { - if models.IsErrTeamNotExist(err) { + if organization.IsErrTeamNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) return } @@ -718,9 +719,9 @@ func EditBranchProtection(ctx *context.APIContext) { mergeWhitelistTeams = protectBranch.MergeWhitelistTeamIDs } if form.ApprovalsWhitelistTeams != nil { - approvalsWhitelistTeams, err = models.GetTeamIDsByNames(repo.OwnerID, form.ApprovalsWhitelistTeams, false) + approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.ApprovalsWhitelistTeams, false) if err != nil { - if models.IsErrTeamNotExist(err) { + if organization.IsErrTeamNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) return } diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go index 6cf51b2467..aaff9107cf 100644 --- a/routers/api/v1/repo/fork.go +++ b/routers/api/v1/repo/fork.go @@ -10,6 +10,7 @@ import ( "net/http" "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" user_model "code.gitea.io/gitea/models/user" @@ -108,9 +109,9 @@ func CreateFork(ctx *context.APIContext) { if form.Organization == nil { forker = ctx.Doer } else { - org, err := models.GetOrgByName(*form.Organization) + org, err := organization.GetOrgByName(*form.Organization) if err != nil { - if models.IsErrOrgNotExist(err) { + if organization.IsErrOrgNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) } else { ctx.Error(http.StatusInternalServerError, "GetOrgByName", err) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index ef8c2d008e..05c9c27144 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" @@ -161,9 +162,9 @@ func SearchIssues(ctx *context.APIContext) { ctx.Error(http.StatusBadRequest, "", "Owner organisation is required for filtering on team") return } - team, err := models.GetTeam(opts.OwnerID, ctx.FormString("team")) + team, err := organization.GetTeam(opts.OwnerID, ctx.FormString("team")) if err != nil { - if models.IsErrTeamNotExist(err) { + if organization.IsErrTeamNotExist(err) { ctx.Error(http.StatusBadRequest, "Team not found", err) } else { ctx.Error(http.StatusInternalServerError, "GetUserByName", err) diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index 1461c2a145..1adf5bbe86 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/perm" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" @@ -90,7 +91,7 @@ func Migrate(ctx *context.APIContext) { if repoOwner.IsOrganization() { // Check ownership of organization. - isOwner, err := models.OrgFromUser(repoOwner).IsOwnedBy(ctx.Doer.ID) + isOwner, err := organization.OrgFromUser(repoOwner).IsOwnedBy(ctx.Doer.ID) if err != nil { ctx.Error(http.StatusInternalServerError, "IsOwnedBy", err) return diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go index b4a484f68c..331b78e1d8 100644 --- a/routers/api/v1/repo/pull_review.go +++ b/routers/api/v1/repo/pull_review.go @@ -10,6 +10,7 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/organization" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" @@ -722,12 +723,12 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions if ctx.Repo.Repository.Owner.IsOrganization() && len(opts.TeamReviewers) > 0 { - teamReviewers := make([]*models.Team, 0, len(opts.TeamReviewers)) + teamReviewers := make([]*organization.Team, 0, len(opts.TeamReviewers)) for _, t := range opts.TeamReviewers { - var teamReviewer *models.Team - teamReviewer, err = models.GetTeam(ctx.Repo.Owner.ID, t) + var teamReviewer *organization.Team + teamReviewer, err = organization.GetTeam(ctx.Repo.Owner.ID, t) if err != nil { - if models.IsErrTeamNotExist(err) { + if organization.IsErrTeamNotExist(err) { ctx.NotFound("TeamNotExist", fmt.Sprintf("Team '%s' not exist", t)) return } diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 7e386d2e5b..2d979235a0 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + "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" @@ -398,7 +399,7 @@ func Generate(ctx *context.APIContext) { } if !ctx.Doer.IsAdmin { - canCreate, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.Doer.ID) + canCreate, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.Doer.ID) if err != nil { ctx.ServerError("CanCreateOrgRepo", err) return @@ -484,9 +485,9 @@ func CreateOrgRepo(ctx *context.APIContext) { // "403": // "$ref": "#/responses/forbidden" opt := web.GetForm(ctx).(*api.CreateRepoOption) - org, err := models.GetOrgByName(ctx.Params(":org")) + org, err := organization.GetOrgByName(ctx.Params(":org")) if err != nil { - if models.IsErrOrgNotExist(err) { + if organization.IsErrOrgNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) } else { ctx.Error(http.StatusInternalServerError, "GetOrgByName", err) @@ -494,7 +495,7 @@ func CreateOrgRepo(ctx *context.APIContext) { return } - if !models.HasOrgOrUserVisible(org.AsUser(), ctx.Doer) { + if !organization.HasOrgOrUserVisible(ctx, org.AsUser(), ctx.Doer) { ctx.NotFound("HasOrgOrUserVisible", nil) return } diff --git a/routers/api/v1/repo/teams.go b/routers/api/v1/repo/teams.go index 024224b5a3..1e3ea326d3 100644 --- a/routers/api/v1/repo/teams.go +++ b/routers/api/v1/repo/teams.go @@ -9,6 +9,7 @@ import ( "net/http" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" @@ -41,7 +42,7 @@ func ListTeams(ctx *context.APIContext) { return } - teams, err := models.GetRepoTeams(ctx.Repo.Repository) + teams, err := organization.GetRepoTeams(ctx.Repo.Repository) if err != nil { ctx.InternalServerError(err) return @@ -101,7 +102,7 @@ func IsTeam(ctx *context.APIContext) { return } - if team.HasRepository(ctx.Repo.Repository.ID) { + if models.HasRepository(team, ctx.Repo.Repository.ID) { if err := team.GetUnits(); err != nil { ctx.Error(http.StatusInternalServerError, "GetUnits", err) return @@ -196,20 +197,20 @@ func changeRepoTeam(ctx *context.APIContext, add bool) { return } - repoHasTeam := team.HasRepository(ctx.Repo.Repository.ID) + repoHasTeam := models.HasRepository(team, ctx.Repo.Repository.ID) var err error if add { if repoHasTeam { ctx.Error(http.StatusUnprocessableEntity, "alreadyAdded", fmt.Errorf("team '%s' is already added to repo", team.Name)) return } - err = team.AddRepository(ctx.Repo.Repository) + err = models.AddRepository(team, ctx.Repo.Repository) } else { if !repoHasTeam { ctx.Error(http.StatusUnprocessableEntity, "notAdded", fmt.Errorf("team '%s' was not added to repo", team.Name)) return } - err = team.RemoveRepository(ctx.Repo.Repository.ID) + err = models.RemoveRepository(team, ctx.Repo.Repository.ID) } if err != nil { ctx.InternalServerError(err) @@ -219,10 +220,10 @@ func changeRepoTeam(ctx *context.APIContext, add bool) { ctx.Status(http.StatusNoContent) } -func getTeamByParam(ctx *context.APIContext) *models.Team { - team, err := models.GetTeam(ctx.Repo.Owner.ID, ctx.Params(":team")) +func getTeamByParam(ctx *context.APIContext) *organization.Team { + team, err := organization.GetTeam(ctx.Repo.Owner.ID, ctx.Params(":team")) if err != nil { - if models.IsErrTeamNotExist(err) { + if organization.IsErrTeamNotExist(err) { ctx.Error(http.StatusNotFound, "TeamNotExit", err) return nil } diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go index e149f9c8f0..7578fbd187 100644 --- a/routers/api/v1/repo/transfer.go +++ b/routers/api/v1/repo/transfer.go @@ -9,6 +9,7 @@ import ( "net/http" "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" user_model "code.gitea.io/gitea/models/user" @@ -67,23 +68,23 @@ func Transfer(ctx *context.APIContext) { } if newOwner.Type == user_model.UserTypeOrganization { - if !ctx.Doer.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.Doer.ID) { + if !ctx.Doer.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx.Doer.ID) { // The user shouldn't know about this organization ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found") return } } - var teams []*models.Team + var teams []*organization.Team if opts.TeamIDs != nil { if !newOwner.IsOrganization() { ctx.Error(http.StatusUnprocessableEntity, "repoTransfer", "Teams can only be added to organization-owned repositories") return } - org := convert.ToOrganization(models.OrgFromUser(newOwner)) + org := convert.ToOrganization(organization.OrgFromUser(newOwner)) for _, tID := range *opts.TeamIDs { - team, err := models.GetTeamByID(tID) + team, err := organization.GetTeamByID(tID) if err != nil { ctx.Error(http.StatusUnprocessableEntity, "team", fmt.Errorf("team %d not found", tID)) return |