diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-10 03:57:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-09 20:57:58 +0100 |
commit | 99b2858e628d92bba252be72def409af77af735b (patch) | |
tree | 56159cf10b271307911e6f01626c0c3efba789ab /routers/api | |
parent | b6b1e716654fec3b16d245ef65cf42e57e1bb5b6 (diff) | |
download | gitea-99b2858e628d92bba252be72def409af77af735b.tar.gz gitea-99b2858e628d92bba252be72def409af77af735b.zip |
Move unit into models/unit/ (#17576)
* Move unit into models/unit/
* Rename unit.UnitType as unit.Type
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/api.go | 101 | ||||
-rw-r--r-- | routers/api/v1/org/team.go | 5 | ||||
-rw-r--r-- | routers/api/v1/repo/file.go | 5 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 5 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_tracked_time.go | 5 | ||||
-rw-r--r-- | routers/api/v1/repo/mirror.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 13 | ||||
-rw-r--r-- | routers/api/v1/repo/release.go | 3 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 61 |
9 files changed, 105 insertions, 97 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 70d7cb40f8..8f852a96ce 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -70,6 +70,7 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -253,7 +254,7 @@ func reqAdmin() func(ctx *context.APIContext) { } // reqRepoWriter user should have a permission to write to a repo, or be a site admin -func reqRepoWriter(unitTypes ...models.UnitType) func(ctx *context.APIContext) { +func reqRepoWriter(unitTypes ...unit.Type) func(ctx *context.APIContext) { return func(ctx *context.APIContext) { if !ctx.IsUserRepoWriter(unitTypes) && !ctx.IsUserRepoAdmin() && !ctx.IsUserSiteAdmin() { ctx.Error(http.StatusForbidden, "reqRepoWriter", "user should have a permission to write to a repo") @@ -263,7 +264,7 @@ func reqRepoWriter(unitTypes ...models.UnitType) func(ctx *context.APIContext) { } // reqRepoReader user should have specific read permission or be a repo admin or a site admin -func reqRepoReader(unitType models.UnitType) func(ctx *context.APIContext) { +func reqRepoReader(unitType unit.Type) func(ctx *context.APIContext) { return func(ctx *context.APIContext) { if !ctx.IsUserRepoReaderSpecific(unitType) && !ctx.IsUserRepoAdmin() && !ctx.IsUserSiteAdmin() { ctx.Error(http.StatusForbidden, "reqRepoReader", "user should have specific read permission or be a repo admin or a site admin") @@ -450,19 +451,19 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) { } func mustEnableIssues(ctx *context.APIContext) { - if !ctx.Repo.CanRead(models.UnitTypeIssues) { + if !ctx.Repo.CanRead(unit.TypeIssues) { if log.IsTrace() { if ctx.IsSigned { log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+ "User in Repo has Permissions: %-+v", ctx.User, - models.UnitTypeIssues, + unit.TypeIssues, ctx.Repo.Repository, ctx.Repo.Permission) } else { log.Trace("Permission Denied: Anonymous user cannot read %-v in Repo %-v\n"+ "Anonymous user in Repo has Permissions: %-+v", - models.UnitTypeIssues, + unit.TypeIssues, ctx.Repo.Repository, ctx.Repo.Permission) } @@ -473,19 +474,19 @@ func mustEnableIssues(ctx *context.APIContext) { } func mustAllowPulls(ctx *context.APIContext) { - if !(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(models.UnitTypePullRequests)) { + if !(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(unit.TypePullRequests)) { if ctx.Repo.Repository.CanEnablePulls() && log.IsTrace() { if ctx.IsSigned { log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+ "User in Repo has Permissions: %-+v", ctx.User, - models.UnitTypePullRequests, + unit.TypePullRequests, ctx.Repo.Repository, ctx.Repo.Permission) } else { log.Trace("Permission Denied: Anonymous user cannot read %-v in Repo %-v\n"+ "Anonymous user in Repo has Permissions: %-+v", - models.UnitTypePullRequests, + unit.TypePullRequests, ctx.Repo.Repository, ctx.Repo.Permission) } @@ -496,22 +497,22 @@ func mustAllowPulls(ctx *context.APIContext) { } func mustEnableIssuesOrPulls(ctx *context.APIContext) { - if !ctx.Repo.CanRead(models.UnitTypeIssues) && - !(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(models.UnitTypePullRequests)) { + if !ctx.Repo.CanRead(unit.TypeIssues) && + !(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(unit.TypePullRequests)) { if ctx.Repo.Repository.CanEnablePulls() && log.IsTrace() { if ctx.IsSigned { log.Trace("Permission Denied: User %-v cannot read %-v and %-v in Repo %-v\n"+ "User in Repo has Permissions: %-+v", ctx.User, - models.UnitTypeIssues, - models.UnitTypePullRequests, + unit.TypeIssues, + unit.TypePullRequests, ctx.Repo.Repository, ctx.Repo.Permission) } else { log.Trace("Permission Denied: Anonymous user cannot read %-v and %-v in Repo %-v\n"+ "Anonymous user in Repo has Permissions: %-+v", - models.UnitTypeIssues, - models.UnitTypePullRequests, + unit.TypeIssues, + unit.TypePullRequests, ctx.Repo.Repository, ctx.Repo.Permission) } @@ -522,7 +523,7 @@ func mustEnableIssuesOrPulls(ctx *context.APIContext) { } func mustEnableWiki(ctx *context.APIContext) { - if !(ctx.Repo.CanRead(models.UnitTypeWiki)) { + if !(ctx.Repo.CanRead(unit.TypeWiki)) { ctx.NotFound() return } @@ -726,7 +727,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { m.Combo("").Get(reqAnyRepoReader(), repo.Get). Delete(reqToken(), reqOwner(), repo.Delete). Patch(reqToken(), reqAdmin(), bind(api.EditRepoOption{}), repo.Edit) - m.Post("/generate", reqToken(), reqRepoReader(models.UnitTypeCode), bind(api.GenerateRepoOption{}), repo.Generate) + m.Post("/generate", reqToken(), reqRepoReader(unit.TypeCode), bind(api.GenerateRepoOption{}), repo.Generate) m.Post("/transfer", reqOwner(), bind(api.TransferRepoOption{}), repo.Transfer) m.Combo("/notifications"). Get(reqToken(), notify.ListRepoNotifications). @@ -763,16 +764,16 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { Put(reqAdmin(), repo.AddTeam). Delete(reqAdmin(), repo.DeleteTeam) }, reqToken()) - m.Get("/raw/*", context.RepoRefForAPI, reqRepoReader(models.UnitTypeCode), repo.GetRawFile) - m.Get("/archive/*", reqRepoReader(models.UnitTypeCode), repo.GetArchive) + m.Get("/raw/*", context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFile) + m.Get("/archive/*", reqRepoReader(unit.TypeCode), repo.GetArchive) m.Combo("/forks").Get(repo.ListForks). - Post(reqToken(), reqRepoReader(models.UnitTypeCode), bind(api.CreateForkOption{}), repo.CreateFork) + Post(reqToken(), reqRepoReader(unit.TypeCode), bind(api.CreateForkOption{}), repo.CreateFork) m.Group("/branches", func() { m.Get("", repo.ListBranches) m.Get("/*", repo.GetBranch) - m.Delete("/*", context.ReferencesGitRepo(false), reqRepoWriter(models.UnitTypeCode), repo.DeleteBranch) - m.Post("", reqRepoWriter(models.UnitTypeCode), bind(api.CreateBranchRepoOption{}), repo.CreateBranch) - }, reqRepoReader(models.UnitTypeCode)) + m.Delete("/*", context.ReferencesGitRepo(false), reqRepoWriter(unit.TypeCode), repo.DeleteBranch) + m.Post("", reqRepoWriter(unit.TypeCode), bind(api.CreateBranchRepoOption{}), repo.CreateBranch) + }, reqRepoReader(unit.TypeCode)) m.Group("/branch_protections", func() { m.Get("", repo.ListBranchProtections) m.Post("", bind(api.CreateBranchProtectionOption{}), repo.CreateBranchProtection) @@ -785,9 +786,9 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { m.Group("/tags", func() { m.Get("", repo.ListTags) m.Get("/*", repo.GetTag) - m.Post("", reqRepoWriter(models.UnitTypeCode), bind(api.CreateTagOption{}), repo.CreateTag) + m.Post("", reqRepoWriter(unit.TypeCode), bind(api.CreateTagOption{}), repo.CreateTag) m.Delete("/*", repo.DeleteTag) - }, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true)) + }, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(true)) m.Group("/keys", func() { m.Combo("").Get(repo.ListDeployKeys). Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey) @@ -801,10 +802,10 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { m.Group("/wiki", func() { m.Combo("/page/{pageName}"). Get(repo.GetWikiPage). - Patch(mustNotBeArchived, reqRepoWriter(models.UnitTypeWiki), bind(api.CreateWikiPageOptions{}), repo.EditWikiPage). - Delete(mustNotBeArchived, reqRepoWriter(models.UnitTypeWiki), repo.DeleteWikiPage) + Patch(mustNotBeArchived, reqRepoWriter(unit.TypeWiki), bind(api.CreateWikiPageOptions{}), repo.EditWikiPage). + Delete(mustNotBeArchived, reqRepoWriter(unit.TypeWiki), repo.DeleteWikiPage) m.Get("/revisions/{pageName}", repo.ListPageRevisions) - m.Post("/new", mustNotBeArchived, reqRepoWriter(models.UnitTypeWiki), bind(api.CreateWikiPageOptions{}), repo.NewWikiPage) + m.Post("/new", mustNotBeArchived, reqRepoWriter(unit.TypeWiki), bind(api.CreateWikiPageOptions{}), repo.NewWikiPage) m.Get("/pages", repo.ListWikiPages) }, mustEnableWiki) m.Group("/issues", func() { @@ -866,19 +867,19 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { }, mustEnableIssuesOrPulls) m.Group("/labels", func() { m.Combo("").Get(repo.ListLabels). - Post(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), bind(api.CreateLabelOption{}), repo.CreateLabel) + Post(reqToken(), reqRepoWriter(unit.TypeIssues, unit.TypePullRequests), bind(api.CreateLabelOption{}), repo.CreateLabel) m.Combo("/{id}").Get(repo.GetLabel). - Patch(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), bind(api.EditLabelOption{}), repo.EditLabel). - Delete(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), repo.DeleteLabel) + Patch(reqToken(), reqRepoWriter(unit.TypeIssues, unit.TypePullRequests), bind(api.EditLabelOption{}), repo.EditLabel). + Delete(reqToken(), reqRepoWriter(unit.TypeIssues, unit.TypePullRequests), repo.DeleteLabel) }) m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown) m.Post("/markdown/raw", misc.MarkdownRaw) m.Group("/milestones", func() { m.Combo("").Get(repo.ListMilestones). - Post(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), bind(api.CreateMilestoneOption{}), repo.CreateMilestone) + Post(reqToken(), reqRepoWriter(unit.TypeIssues, unit.TypePullRequests), bind(api.CreateMilestoneOption{}), repo.CreateMilestone) m.Combo("/{id}").Get(repo.GetMilestone). - Patch(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), bind(api.EditMilestoneOption{}), repo.EditMilestone). - Delete(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), repo.DeleteMilestone) + Patch(reqToken(), reqRepoWriter(unit.TypeIssues, unit.TypePullRequests), bind(api.EditMilestoneOption{}), repo.EditMilestone). + Delete(reqToken(), reqRepoWriter(unit.TypeIssues, unit.TypePullRequests), repo.DeleteMilestone) }) m.Get("/stargazers", repo.ListStargazers) m.Get("/subscribers", repo.ListSubscribers) @@ -889,27 +890,27 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { }) m.Group("/releases", func() { m.Combo("").Get(repo.ListReleases). - Post(reqToken(), reqRepoWriter(models.UnitTypeReleases), context.ReferencesGitRepo(false), bind(api.CreateReleaseOption{}), repo.CreateRelease) + Post(reqToken(), reqRepoWriter(unit.TypeReleases), context.ReferencesGitRepo(false), bind(api.CreateReleaseOption{}), repo.CreateRelease) m.Group("/{id}", func() { m.Combo("").Get(repo.GetRelease). - Patch(reqToken(), reqRepoWriter(models.UnitTypeReleases), context.ReferencesGitRepo(false), bind(api.EditReleaseOption{}), repo.EditRelease). - Delete(reqToken(), reqRepoWriter(models.UnitTypeReleases), repo.DeleteRelease) + Patch(reqToken(), reqRepoWriter(unit.TypeReleases), context.ReferencesGitRepo(false), bind(api.EditReleaseOption{}), repo.EditRelease). + Delete(reqToken(), reqRepoWriter(unit.TypeReleases), repo.DeleteRelease) m.Group("/assets", func() { m.Combo("").Get(repo.ListReleaseAttachments). - Post(reqToken(), reqRepoWriter(models.UnitTypeReleases), repo.CreateReleaseAttachment) + Post(reqToken(), reqRepoWriter(unit.TypeReleases), repo.CreateReleaseAttachment) m.Combo("/{asset}").Get(repo.GetReleaseAttachment). - Patch(reqToken(), reqRepoWriter(models.UnitTypeReleases), bind(api.EditAttachmentOptions{}), repo.EditReleaseAttachment). - Delete(reqToken(), reqRepoWriter(models.UnitTypeReleases), repo.DeleteReleaseAttachment) + Patch(reqToken(), reqRepoWriter(unit.TypeReleases), bind(api.EditAttachmentOptions{}), repo.EditReleaseAttachment). + Delete(reqToken(), reqRepoWriter(unit.TypeReleases), repo.DeleteReleaseAttachment) }) }) m.Group("/tags", func() { m.Combo("/{tag}"). Get(repo.GetReleaseByTag). - Delete(reqToken(), reqRepoWriter(models.UnitTypeReleases), repo.DeleteReleaseByTag) + Delete(reqToken(), reqRepoWriter(unit.TypeReleases), repo.DeleteReleaseByTag) }) - }, reqRepoReader(models.UnitTypeReleases)) - m.Post("/mirror-sync", reqToken(), reqRepoWriter(models.UnitTypeCode), repo.MirrorSync) - m.Get("/editorconfig/{filename}", context.RepoRefForAPI, reqRepoReader(models.UnitTypeCode), repo.GetEditorconfig) + }, reqRepoReader(unit.TypeReleases)) + m.Post("/mirror-sync", reqToken(), reqRepoWriter(unit.TypeCode), repo.MirrorSync) + m.Get("/editorconfig/{filename}", context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetEditorconfig) m.Group("/pulls", func() { m.Combo("").Get(repo.ListPullRequests). Post(reqToken(), mustNotBeArchived, bind(api.CreatePullRequestOption{}), repo.CreatePullRequest) @@ -940,18 +941,18 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { Delete(reqToken(), bind(api.PullReviewRequestOptions{}), repo.DeleteReviewRequests). Post(reqToken(), bind(api.PullReviewRequestOptions{}), repo.CreateReviewRequests) }) - }, mustAllowPulls, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(false)) + }, mustAllowPulls, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(false)) m.Group("/statuses", func() { m.Combo("/{sha}").Get(repo.GetCommitStatuses). Post(reqToken(), bind(api.CreateStatusOption{}), repo.NewCommitStatus) - }, reqRepoReader(models.UnitTypeCode)) + }, reqRepoReader(unit.TypeCode)) m.Group("/commits", func() { m.Get("", repo.GetAllCommits) m.Group("/{ref}", func() { m.Get("/status", repo.GetCombinedCommitStatusByRef) m.Get("/statuses", repo.GetCommitStatusesByRef) }) - }, reqRepoReader(models.UnitTypeCode)) + }, reqRepoReader(unit.TypeCode)) m.Group("/git", func() { m.Group("/commits", func() { m.Get("/{sha}", repo.GetSingleCommit) @@ -963,7 +964,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { m.Get("/blobs/{sha}", context.RepoRefForAPI, repo.GetBlob) m.Get("/tags/{sha}", context.RepoRefForAPI, repo.GetAnnotatedTag) m.Get("/notes/{sha}", repo.GetNote) - }, reqRepoReader(models.UnitTypeCode)) + }, reqRepoReader(unit.TypeCode)) m.Group("/contents", func() { m.Get("", repo.GetContentsList) m.Get("/*", repo.GetContents) @@ -971,8 +972,8 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { m.Post("", bind(api.CreateFileOptions{}), repo.CreateFile) m.Put("", bind(api.UpdateFileOptions{}), repo.UpdateFile) m.Delete("", bind(api.DeleteFileOptions{}), repo.DeleteFile) - }, reqRepoWriter(models.UnitTypeCode), reqToken()) - }, reqRepoReader(models.UnitTypeCode)) + }, reqRepoWriter(unit.TypeCode), reqToken()) + }, reqRepoReader(unit.TypeCode)) m.Get("/signing-key.gpg", misc.SigningKey) m.Group("/topics", func() { m.Combo("").Get(repo.ListTopics). @@ -983,7 +984,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { }, reqAdmin()) }, reqAnyRepoReader()) m.Get("/issue_templates", context.ReferencesGitRepo(false), repo.GetIssueTemplates) - m.Get("/languages", reqRepoReader(models.UnitTypeCode), repo.GetLanguages) + m.Get("/languages", reqRepoReader(unit.TypeCode), repo.GetLanguages) }, repoAssignment()) }) diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index a84763d6f6..0dc1b68aee 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -9,6 +9,7 @@ import ( "net/http" "code.gitea.io/gitea/models" + unit_model "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/log" @@ -172,7 +173,7 @@ func CreateTeam(ctx *context.APIContext) { Authorize: models.ParseAccessMode(form.Permission), } - unitTypes := models.FindUnitTypes(form.Units...) + unitTypes := unit_model.FindUnitTypes(form.Units...) if team.Authorize < models.AccessModeOwner { var units = make([]*models.TeamUnit, 0, len(form.Units)) @@ -260,7 +261,7 @@ func EditTeam(ctx *context.APIContext) { if team.Authorize < models.AccessModeOwner { if len(form.Units) > 0 { var units = make([]*models.TeamUnit, 0, len(form.Units)) - unitTypes := models.FindUnitTypes(form.Units...) + unitTypes := unit_model.FindUnitTypes(form.Units...) for _, tp := range unitTypes { units = append(units, &models.TeamUnit{ OrgID: ctx.Org.Team.OrgID, diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index d9451b8090..009b8a26d6 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -12,6 +12,7 @@ import ( "time" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/repofiles" @@ -182,12 +183,12 @@ func GetEditorconfig(ctx *context.APIContext) { // canWriteFiles returns true if repository is editable and user has proper access level. func canWriteFiles(r *context.Repository) bool { - return r.Permission.CanWrite(models.UnitTypeCode) && !r.Repository.IsMirror && !r.Repository.IsArchived + return r.Permission.CanWrite(unit.TypeCode) && !r.Repository.IsMirror && !r.Repository.IsArchived } // canReadFiles returns true if repository is readable and user has proper access level. func canReadFiles(r *context.Repository) bool { - return r.Permission.CanRead(models.UnitTypeCode) + return r.Permission.CanRead(unit.TypeCode) } // CreateFile handles API call for creating a file diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 17a3becd5b..a2454b8618 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/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" @@ -582,7 +583,7 @@ func CreateIssue(ctx *context.APIContext) { // "$ref": "#/responses/validationError" form := web.GetForm(ctx).(*api.CreateIssueOption) var deadlineUnix timeutil.TimeStamp - if form.Deadline != nil && ctx.Repo.CanWrite(models.UnitTypeIssues) { + if form.Deadline != nil && ctx.Repo.CanWrite(unit.TypeIssues) { deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix()) } @@ -599,7 +600,7 @@ func CreateIssue(ctx *context.APIContext) { var assigneeIDs = make([]int64, 0) var err error - if ctx.Repo.CanWrite(models.UnitTypeIssues) { + if ctx.Repo.CanWrite(unit.TypeIssues) { issue.MilestoneID = form.Milestone assigneeIDs, err = models.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees) if err != nil { diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index e9d8fbab26..f73e63547b 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -10,6 +10,7 @@ import ( "time" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" @@ -108,7 +109,7 @@ func ListTrackedTimes(ctx *context.APIContext) { cantSetUser := !ctx.User.IsAdmin && opts.UserID != ctx.User.ID && - !ctx.IsUserRepoWriter([]models.UnitType{models.UnitTypeIssues}) + !ctx.IsUserRepoWriter([]unit.Type{unit.TypeIssues}) if cantSetUser { if opts.UserID == 0 { @@ -527,7 +528,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) { cantSetUser := !ctx.User.IsAdmin && opts.UserID != ctx.User.ID && - !ctx.IsUserRepoWriter([]models.UnitType{models.UnitTypeIssues}) + !ctx.IsUserRepoWriter([]unit.Type{unit.TypeIssues}) if cantSetUser { if opts.UserID == 0 { diff --git a/routers/api/v1/repo/mirror.go b/routers/api/v1/repo/mirror.go index 67d0c7ee1c..c9ac3e8292 100644 --- a/routers/api/v1/repo/mirror.go +++ b/routers/api/v1/repo/mirror.go @@ -7,7 +7,7 @@ package repo import ( "net/http" - "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" mirror_service "code.gitea.io/gitea/services/mirror" @@ -39,7 +39,7 @@ func MirrorSync(ctx *context.APIContext) { repo := ctx.Repo.Repository - if !ctx.Repo.CanWrite(models.UnitTypeCode) { + if !ctx.Repo.CanWrite(unit.TypeCode) { ctx.Error(http.StatusForbidden, "MirrorSync", "Must have write access") } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index f2a1d7fe63..7f377edc3f 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -14,6 +14,7 @@ import ( "time" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/git" @@ -481,7 +482,7 @@ func EditPullRequest(ctx *context.APIContext) { issue := pr.Issue issue.Repo = ctx.Repo.Repository - if !issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWrite(models.UnitTypePullRequests) { + if !issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWrite(unit.TypePullRequests) { ctx.Status(http.StatusForbidden) return } @@ -518,7 +519,7 @@ func EditPullRequest(ctx *context.APIContext) { // Pass one or more user logins to replace the set of assignees on this Issue. // Send an empty array ([]) to clear all assignees from the Issue. - if ctx.Repo.CanWrite(models.UnitTypePullRequests) && (form.Assignees != nil || len(form.Assignee) > 0) { + if ctx.Repo.CanWrite(unit.TypePullRequests) && (form.Assignees != nil || len(form.Assignee) > 0) { err = issue_service.UpdateAssignees(issue, form.Assignee, form.Assignees, ctx.User) if err != nil { if models.IsErrUserNotExist(err) { @@ -530,7 +531,7 @@ func EditPullRequest(ctx *context.APIContext) { } } - if ctx.Repo.CanWrite(models.UnitTypePullRequests) && form.Milestone != 0 && + if ctx.Repo.CanWrite(unit.TypePullRequests) && form.Milestone != 0 && issue.MilestoneID != form.Milestone { oldMilestoneID := issue.MilestoneID issue.MilestoneID = form.Milestone @@ -540,7 +541,7 @@ func EditPullRequest(ctx *context.APIContext) { } } - if ctx.Repo.CanWrite(models.UnitTypePullRequests) && form.Labels != nil { + if ctx.Repo.CanWrite(unit.TypePullRequests) && form.Labels != nil { labels, err := models.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels) if err != nil { ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDsError", err) @@ -978,7 +979,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err) return nil, nil, nil, nil, "", "" } - if !permBase.CanReadIssuesOrPulls(true) || !permBase.CanRead(models.UnitTypeCode) { + if !permBase.CanReadIssuesOrPulls(true) || !permBase.CanRead(unit.TypeCode) { if log.IsTrace() { log.Trace("Permission Denied: User %-v cannot create/read pull requests or cannot read code in Repo %-v\nUser in baseRepo has Permissions: %-+v", ctx.User, @@ -997,7 +998,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err) return nil, nil, nil, nil, "", "" } - if !permHead.CanRead(models.UnitTypeCode) { + if !permHead.CanRead(unit.TypeCode) { if log.IsTrace() { log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v", ctx.User, diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index a600a1e33f..08ebde4e0c 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -8,6 +8,7 @@ import ( "net/http" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" @@ -114,7 +115,7 @@ func ListReleases(ctx *context.APIContext) { opts := models.FindReleasesOptions{ ListOptions: listOptions, - IncludeDrafts: ctx.Repo.AccessMode >= models.AccessModeWrite || ctx.Repo.UnitAccessMode(models.UnitTypeReleases) >= models.AccessModeWrite, + IncludeDrafts: ctx.Repo.AccessMode >= models.AccessModeWrite || ctx.Repo.UnitAccessMode(unit.TypeReleases) >= models.AccessModeWrite, IncludeTags: false, IsDraft: ctx.FormOptionalBool("draft"), IsPreRelease: ctx.FormOptionalBool("pre-release"), diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 0f85d917d1..22f9da614d 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -12,6 +12,7 @@ import ( "time" "code.gitea.io/gitea/models" + unit_model "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/git" @@ -735,10 +736,10 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { repo := ctx.Repo.Repository var units []models.RepoUnit - var deleteUnitTypes []models.UnitType + var deleteUnitTypes []unit_model.Type if opts.HasIssues != nil { - if *opts.HasIssues && opts.ExternalTracker != nil && !models.UnitTypeExternalTracker.UnitGlobalDisabled() { + if *opts.HasIssues && opts.ExternalTracker != nil && !unit_model.TypeExternalTracker.UnitGlobalDisabled() { // Check that values are valid if !validation.IsValidExternalURL(opts.ExternalTracker.ExternalTrackerURL) { err := fmt.Errorf("External tracker URL not valid") @@ -753,15 +754,15 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeExternalTracker, + Type: unit_model.TypeExternalTracker, Config: &models.ExternalTrackerConfig{ ExternalTrackerURL: opts.ExternalTracker.ExternalTrackerURL, ExternalTrackerFormat: opts.ExternalTracker.ExternalTrackerFormat, ExternalTrackerStyle: opts.ExternalTracker.ExternalTrackerStyle, }, }) - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeIssues) - } else if *opts.HasIssues && opts.ExternalTracker == nil && !models.UnitTypeIssues.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues) + } else if *opts.HasIssues && opts.ExternalTracker == nil && !unit_model.TypeIssues.UnitGlobalDisabled() { // Default to built-in tracker var config *models.IssuesConfig @@ -771,7 +772,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { AllowOnlyContributorsToTrackTime: opts.InternalTracker.AllowOnlyContributorsToTrackTime, EnableDependencies: opts.InternalTracker.EnableIssueDependencies, } - } else if unit, err := repo.GetUnit(models.UnitTypeIssues); err != nil { + } else if unit, err := repo.GetUnit(unit_model.TypeIssues); err != nil { // Unit type doesn't exist so we make a new config file with default values config = &models.IssuesConfig{ EnableTimetracker: true, @@ -784,22 +785,22 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeIssues, + Type: unit_model.TypeIssues, Config: config, }) - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalTracker) + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalTracker) } else if !*opts.HasIssues { - if !models.UnitTypeExternalTracker.UnitGlobalDisabled() { - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalTracker) + if !unit_model.TypeExternalTracker.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalTracker) } - if !models.UnitTypeIssues.UnitGlobalDisabled() { - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeIssues) + if !unit_model.TypeIssues.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues) } } } if opts.HasWiki != nil { - if *opts.HasWiki && opts.ExternalWiki != nil && !models.UnitTypeExternalWiki.UnitGlobalDisabled() { + if *opts.HasWiki && opts.ExternalWiki != nil && !unit_model.TypeExternalWiki.UnitGlobalDisabled() { // Check that values are valid if !validation.IsValidExternalURL(opts.ExternalWiki.ExternalWikiURL) { err := fmt.Errorf("External wiki URL not valid") @@ -809,36 +810,36 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeExternalWiki, + Type: unit_model.TypeExternalWiki, Config: &models.ExternalWikiConfig{ ExternalWikiURL: opts.ExternalWiki.ExternalWikiURL, }, }) - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeWiki) - } else if *opts.HasWiki && opts.ExternalWiki == nil && !models.UnitTypeWiki.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeWiki) + } else if *opts.HasWiki && opts.ExternalWiki == nil && !unit_model.TypeWiki.UnitGlobalDisabled() { config := &models.UnitConfig{} units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeWiki, + Type: unit_model.TypeWiki, Config: config, }) - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalWiki) + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki) } else if !*opts.HasWiki { - if !models.UnitTypeExternalWiki.UnitGlobalDisabled() { - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalWiki) + if !unit_model.TypeExternalWiki.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki) } - if !models.UnitTypeWiki.UnitGlobalDisabled() { - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeWiki) + if !unit_model.TypeWiki.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeWiki) } } } if opts.HasPullRequests != nil { - if *opts.HasPullRequests && !models.UnitTypePullRequests.UnitGlobalDisabled() { + if *opts.HasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() { // We do allow setting individual PR settings through the API, so // we get the config settings and then set them // if those settings were provided in the opts. - unit, err := repo.GetUnit(models.UnitTypePullRequests) + unit, err := repo.GetUnit(unit_model.TypePullRequests) var config *models.PullRequestsConfig if err != nil { // Unit type doesn't exist so we make a new config file with default values @@ -887,22 +888,22 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypePullRequests, + Type: unit_model.TypePullRequests, Config: config, }) - } else if !*opts.HasPullRequests && !models.UnitTypePullRequests.UnitGlobalDisabled() { - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypePullRequests) + } else if !*opts.HasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePullRequests) } } - if opts.HasProjects != nil && !models.UnitTypeProjects.UnitGlobalDisabled() { + if opts.HasProjects != nil && !unit_model.TypeProjects.UnitGlobalDisabled() { if *opts.HasProjects { units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeProjects, + Type: unit_model.TypeProjects, }) } else { - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeProjects) + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeProjects) } } |