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 | |
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')
29 files changed, 263 insertions, 236 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) } } diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go index 3e4995376c..04c334b38f 100644 --- a/routers/private/hook_pre_receive.go +++ b/routers/private/hook_pre_receive.go @@ -12,6 +12,7 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" gitea_context "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -58,7 +59,7 @@ func (ctx *preReceiveContext) Perm() *models.Permission { // CanWriteCode returns true if can write code func (ctx *preReceiveContext) CanWriteCode() bool { if !ctx.checkedCanWriteCode { - ctx.canWriteCode = ctx.Perm().CanWrite(models.UnitTypeCode) + ctx.canWriteCode = ctx.Perm().CanWrite(unit.TypeCode) ctx.checkedCanWriteCode = true } return ctx.canWriteCode @@ -81,7 +82,7 @@ func (ctx *preReceiveContext) AssertCanWriteCode() bool { // CanCreatePullRequest returns true if can create pull requests func (ctx *preReceiveContext) CanCreatePullRequest() bool { if !ctx.checkedCanCreatePullRequest { - ctx.canCreatePullRequest = ctx.Perm().CanRead(models.UnitTypePullRequests) + ctx.canCreatePullRequest = ctx.Perm().CanRead(unit.TypePullRequests) ctx.checkedCanCreatePullRequest = true } return ctx.canCreatePullRequest diff --git a/routers/private/serv.go b/routers/private/serv.go index b3edd7fc24..a7ef980d2d 100644 --- a/routers/private/serv.go +++ b/routers/private/serv.go @@ -11,6 +11,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/git" "code.gitea.io/gitea/modules/log" @@ -93,12 +94,12 @@ func ServCommand(ctx *context.PrivateContext) { } // The default unit we're trying to look at is code - unitType := models.UnitTypeCode + unitType := unit.TypeCode // Unless we're a wiki... if strings.HasSuffix(repoName, ".wiki") { // in which case we need to look at the wiki - unitType = models.UnitTypeWiki + unitType = unit.TypeWiki // And we'd better munge the reponame and tell downstream we're looking at a wiki results.IsWiki = true results.RepoName = repoName[:len(repoName)-5] @@ -295,7 +296,7 @@ func ServCommand(ctx *context.PrivateContext) { } } else { // Because of the special ref "refs/for" we will need to delay write permission check - if git.SupportProcReceive && unitType == models.UnitTypeCode { + if git.SupportProcReceive && unitType == unit.TypeCode { mode = models.AccessModeRead } @@ -362,7 +363,7 @@ func ServCommand(ctx *context.PrivateContext) { if results.IsWiki { // Ensure the wiki is enabled before we allow access to it - if _, err := repo.GetUnit(models.UnitTypeWiki); err != nil { + if _, err := repo.GetUnit(unit.TypeWiki); err != nil { if models.IsErrUnitTypeNotExist(err) { ctx.JSON(http.StatusForbidden, private.ErrServCommand{ Results: results, diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index a9b159468d..6ff48be0f8 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -8,6 +8,7 @@ import ( "net/http" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" code_indexer "code.gitea.io/gitea/modules/indexer/code" @@ -77,7 +78,7 @@ func Code(ctx *context.Context) { var rightRepoMap = make(map[int64]*models.Repository, len(repoMaps)) repoIDs = make([]int64, 0, len(repoMaps)) for id, repo := range repoMaps { - if repo.CheckUnitUser(ctx.User, models.UnitTypeCode) { + if repo.CheckUnitUser(ctx.User, unit.TypeCode) { rightRepoMap[id] = repo repoIDs = append(repoIDs, id) } diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index c93fcd062b..3fe97142ae 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -11,6 +11,7 @@ import ( "strings" "code.gitea.io/gitea/models" + unit_model "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" @@ -216,7 +217,7 @@ func NewTeam(ctx *context.Context) { ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeamsNew"] = true ctx.Data["Team"] = &models.Team{} - ctx.Data["Units"] = models.Units + ctx.Data["Units"] = unit_model.Units ctx.HTML(http.StatusOK, tplTeamNew) } @@ -226,7 +227,7 @@ func NewTeamPost(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Organization.FullName ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeamsNew"] = true - ctx.Data["Units"] = models.Units + ctx.Data["Units"] = unit_model.Units var includesAllRepositories = form.RepoAccess == "all" t := &models.Team{ @@ -305,7 +306,7 @@ func EditTeam(ctx *context.Context) { ctx.Data["PageIsOrgTeams"] = true ctx.Data["team_name"] = ctx.Org.Team.Name ctx.Data["desc"] = ctx.Org.Team.Description - ctx.Data["Units"] = models.Units + ctx.Data["Units"] = unit_model.Units ctx.HTML(http.StatusOK, tplTeamNew) } @@ -316,7 +317,7 @@ func EditTeamPost(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Organization.FullName ctx.Data["PageIsOrgTeams"] = true ctx.Data["Team"] = t - ctx.Data["Units"] = models.Units + ctx.Data["Units"] = unit_model.Units isAuthChanged := false isIncludeAllChanged := false diff --git a/routers/web/repo/activity.go b/routers/web/repo/activity.go index f9d248b06e..ae37b51403 100644 --- a/routers/web/repo/activity.go +++ b/routers/web/repo/activity.go @@ -9,6 +9,7 @@ import ( "time" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" ) @@ -52,10 +53,10 @@ func Activity(ctx *context.Context) { var err error if ctx.Data["Activity"], err = models.GetActivityStats(ctx.Repo.Repository, timeFrom, - ctx.Repo.CanRead(models.UnitTypeReleases), - ctx.Repo.CanRead(models.UnitTypeIssues), - ctx.Repo.CanRead(models.UnitTypePullRequests), - ctx.Repo.CanRead(models.UnitTypeCode)); err != nil { + ctx.Repo.CanRead(unit.TypeReleases), + ctx.Repo.CanRead(unit.TypeIssues), + ctx.Repo.CanRead(unit.TypePullRequests), + ctx.Repo.CanRead(unit.TypeCode)); err != nil { ctx.ServerError("GetActivityStats", err) return } diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index 32cfc2adff..991beeace2 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -12,6 +12,7 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" @@ -51,9 +52,9 @@ func Branches(ctx *context.Context) { ctx.Data["IsRepoToolbarBranches"] = true ctx.Data["DefaultBranch"] = ctx.Repo.Repository.DefaultBranch ctx.Data["AllowsPulls"] = ctx.Repo.Repository.AllowsPulls() - ctx.Data["IsWriter"] = ctx.Repo.CanWrite(models.UnitTypeCode) + ctx.Data["IsWriter"] = ctx.Repo.CanWrite(unit.TypeCode) ctx.Data["IsMirror"] = ctx.Repo.Repository.IsMirror - ctx.Data["CanPull"] = ctx.Repo.CanWrite(models.UnitTypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)) + ctx.Data["CanPull"] = ctx.Repo.CanWrite(unit.TypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)) ctx.Data["PageIsViewCode"] = true ctx.Data["PageIsBranches"] = true @@ -208,7 +209,7 @@ func loadBranches(ctx *context.Context, skip, limit int) ([]*Branch, int) { log.Debug("loadOneBranch: load default: '%s'", defaultBranch.Name) branches = append(branches, loadOneBranch(ctx, defaultBranch, protectedBranches, repoIDToRepo, repoIDToGitRepo)) - if ctx.Repo.CanWrite(models.UnitTypeCode) { + if ctx.Repo.CanWrite(unit.TypeCode) { deletedBranches, err := getDeletedBranches(ctx) if err != nil { ctx.ServerError("getDeletedBranches", err) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 555abc1c8b..86ecc2bab1 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -17,6 +17,7 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/charset" "code.gitea.io/gitea/modules/context" @@ -384,7 +385,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { ctx.ServerError("GetUserRepoPermission", err) return nil } - if !permBase.CanRead(models.UnitTypeCode) { + if !permBase.CanRead(unit.TypeCode) { if log.IsTrace() { log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in baseRepo has Permissions: %-+v", ctx.User, @@ -403,7 +404,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { ctx.ServerError("GetUserRepoPermission", err) return 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, @@ -422,7 +423,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { if rootRepo != nil && rootRepo.ID != ci.HeadRepo.ID && rootRepo.ID != baseRepo.ID { - canRead := rootRepo.CheckUnitUser(ctx.User, models.UnitTypeCode) + canRead := rootRepo.CheckUnitUser(ctx.User, unit.TypeCode) if canRead { ctx.Data["RootRepo"] = rootRepo if !fileOnly { @@ -447,7 +448,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { ownForkRepo.ID != ci.HeadRepo.ID && ownForkRepo.ID != baseRepo.ID && (rootRepo == nil || ownForkRepo.ID != rootRepo.ID) { - canRead := ownForkRepo.CheckUnitUser(ctx.User, models.UnitTypeCode) + canRead := ownForkRepo.CheckUnitUser(ctx.User, unit.TypeCode) if canRead { ctx.Data["OwnForkRepo"] = ownForkRepo if !fileOnly { @@ -542,7 +543,7 @@ func PrepareCompareDiff( if (headCommitID == ci.CompareInfo.MergeBase && !ci.DirectComparison) || headCommitID == ci.CompareInfo.BaseCommitID { ctx.Data["IsNothingToCompare"] = true - if unit, err := repo.GetUnit(models.UnitTypePullRequests); err == nil { + if unit, err := repo.GetUnit(unit.TypePullRequests); err == nil { config := unit.PullRequestsConfig() if !config.AutodetectManualMerge { @@ -736,7 +737,7 @@ func CompareDiff(ctx *context.Context) { ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "comment") - ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypePullRequests) + ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(unit.TypePullRequests) ctx.HTML(http.StatusOK, tplCompare) } diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index f272583499..d9f8c20092 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -12,6 +12,7 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/charset" "code.gitea.io/gitea/modules/context" @@ -331,7 +332,7 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b } } - if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) { + if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(unit.TypePullRequests) { ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + util.PathEscapeSegments(ctx.Repo.BranchName) + "..." + util.PathEscapeSegments(form.NewBranchName)) } else { ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(branchName) + "/" + util.PathEscapeSegments(form.TreePath)) @@ -517,7 +518,7 @@ func DeleteFilePost(ctx *context.Context) { } ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", ctx.Repo.TreePath)) - if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) { + if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(unit.TypePullRequests) { ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + util.PathEscapeSegments(ctx.Repo.BranchName) + "..." + util.PathEscapeSegments(form.NewBranchName)) } else { treePath := path.Dir(ctx.Repo.TreePath) @@ -722,7 +723,7 @@ func UploadFilePost(ctx *context.Context) { return } - if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) { + if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(unit.TypePullRequests) { ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + util.PathEscapeSegments(ctx.Repo.BranchName) + "..." + util.PathEscapeSegments(form.NewBranchName)) } else { ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(branchName) + "/" + util.PathEscapeSegments(form.TreePath)) diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index 162338a959..7c5dcd42be 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -22,6 +22,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -99,11 +100,11 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { } isWiki := false - var unitType = models.UnitTypeCode + var unitType = unit.TypeCode var wikiRepoName string if strings.HasSuffix(reponame, ".wiki") { isWiki = true - unitType = models.UnitTypeWiki + unitType = unit.TypeWiki wikiRepoName = reponame reponame = reponame[:len(reponame)-5] } @@ -270,7 +271,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { if isWiki { // Ensure the wiki is enabled before we allow access to it - if _, err := repo.GetUnit(models.UnitTypeWiki); err != nil { + if _, err := repo.GetUnit(unit.TypeWiki); err != nil { if models.IsErrUnitTypeNotExist(err) { ctx.HandleText(http.StatusForbidden, "repository wiki is disabled") return diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 2782e8d629..93b6b7a305 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" @@ -82,13 +83,13 @@ func MustAllowUserComment(ctx *context.Context) { // MustEnableIssues check if repository enable internal issues func MustEnableIssues(ctx *context.Context) { - if !ctx.Repo.CanRead(models.UnitTypeIssues) && - !ctx.Repo.CanRead(models.UnitTypeExternalTracker) { + if !ctx.Repo.CanRead(unit.TypeIssues) && + !ctx.Repo.CanRead(unit.TypeExternalTracker) { ctx.NotFound("MustEnableIssues", nil) return } - unit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker) + unit, err := ctx.Repo.Repository.GetUnit(unit.TypeExternalTracker) if err == nil { ctx.Redirect(unit.ExternalTrackerConfig().ExternalTrackerURL) return @@ -97,7 +98,7 @@ func MustEnableIssues(ctx *context.Context) { // MustAllowPulls check if repository enable pull requests and user have right to do that func MustAllowPulls(ctx *context.Context) { - if !ctx.Repo.Repository.CanEnablePulls() || !ctx.Repo.CanRead(models.UnitTypePullRequests) { + if !ctx.Repo.Repository.CanEnablePulls() || !ctx.Repo.CanRead(unit.TypePullRequests) { ctx.NotFound("MustAllowPulls", nil) return } @@ -790,7 +791,7 @@ func NewIssue(ctx *context.Context) { body := ctx.FormString("body") ctx.Data["BodyQuery"] = body - ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(models.UnitTypeProjects) + ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(unit.TypeProjects) ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "comment") @@ -828,7 +829,7 @@ func NewIssue(ctx *context.Context) { return } - ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypeIssues) + ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(unit.TypeIssues) ctx.HTML(http.StatusOK, tplIssueNew) } @@ -1065,7 +1066,7 @@ func getBranchData(ctx *context.Context, issue *models.Issue) { func ViewIssue(ctx *context.Context) { if ctx.Params(":type") == "issues" { // If issue was requested we check if repo has external tracker and redirect - extIssueUnit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker) + extIssueUnit, err := ctx.Repo.Repository.GetUnit(unit.TypeExternalTracker) if err == nil && extIssueUnit != nil { if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" { metas := ctx.Repo.Repository.ComposeMetas() @@ -1114,9 +1115,9 @@ func ViewIssue(ctx *context.Context) { ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0 } - if issue.IsPull && !ctx.Repo.CanRead(models.UnitTypeIssues) { + if issue.IsPull && !ctx.Repo.CanRead(unit.TypeIssues) { ctx.Data["IssueType"] = "pulls" - } else if !issue.IsPull && !ctx.Repo.CanRead(models.UnitTypePullRequests) { + } else if !issue.IsPull && !ctx.Repo.CanRead(unit.TypePullRequests) { ctx.Data["IssueType"] = "issues" } else { ctx.Data["IssueType"] = "all" @@ -1125,7 +1126,7 @@ func ViewIssue(ctx *context.Context) { ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireTribute"] = true ctx.Data["RequireSimpleMDE"] = true - ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(models.UnitTypeProjects) + ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(unit.TypeProjects) ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "comment") @@ -1224,7 +1225,7 @@ func ViewIssue(ctx *context.Context) { } if issue.IsPull { - canChooseReviewer := ctx.Repo.CanWrite(models.UnitTypePullRequests) + canChooseReviewer := ctx.Repo.CanWrite(unit.TypePullRequests) if !canChooseReviewer && ctx.User != nil && ctx.IsSigned { canChooseReviewer, err = models.IsOfficialReviewer(issue, ctx.User) if err != nil { @@ -1481,7 +1482,7 @@ func ViewIssue(ctx *context.Context) { ctx.ServerError("GetUserRepoPermission", err) return } - if perm.CanWrite(models.UnitTypeCode) { + if perm.CanWrite(unit.TypeCode) { // Check if branch is not protected if protected, err := pull.HeadRepo.IsProtectedBranch(pull.HeadBranch); err != nil { log.Error("IsProtectedBranch: %v", err) @@ -1512,7 +1513,7 @@ func ViewIssue(ctx *context.Context) { } } - prUnit, err := repo.GetUnit(models.UnitTypePullRequests) + prUnit, err := repo.GetUnit(unit.TypePullRequests) if err != nil { ctx.ServerError("GetUnit", err) return @@ -1618,7 +1619,7 @@ func ViewIssue(ctx *context.Context) { ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string) ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID) ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) - ctx.Data["HasProjectsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypeProjects) + ctx.Data["HasProjectsWritePermission"] = ctx.Repo.CanWrite(unit.TypeProjects) ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.User.IsAdmin) ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons ctx.Data["RefEndName"] = git.RefEndName(issue.Ref) @@ -1645,8 +1646,8 @@ func GetActionIssue(ctx *context.Context) *models.Issue { } func checkIssueRights(ctx *context.Context, issue *models.Issue) { - if issue.IsPull && !ctx.Repo.CanRead(models.UnitTypePullRequests) || - !issue.IsPull && !ctx.Repo.CanRead(models.UnitTypeIssues) { + if issue.IsPull && !ctx.Repo.CanRead(unit.TypePullRequests) || + !issue.IsPull && !ctx.Repo.CanRead(unit.TypeIssues) { ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil) } } @@ -1671,8 +1672,8 @@ func getActionIssues(ctx *context.Context) []*models.Issue { return nil } // Check access rights for all issues - issueUnitEnabled := ctx.Repo.CanRead(models.UnitTypeIssues) - prUnitEnabled := ctx.Repo.CanRead(models.UnitTypePullRequests) + issueUnitEnabled := ctx.Repo.CanRead(unit.TypeIssues) + prUnitEnabled := ctx.Repo.CanRead(unit.TypePullRequests) for _, issue := range issues { if issue.IsPull && !prUnitEnabled || !issue.IsPull && !issueUnitEnabled { ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil) diff --git a/routers/web/repo/issue_content_history.go b/routers/web/repo/issue_content_history.go index dc647b8809..08eb98acb8 100644 --- a/routers/web/repo/issue_content_history.go +++ b/routers/web/repo/issue_content_history.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" issuesModel "code.gitea.io/gitea/models/issues" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" @@ -87,7 +88,7 @@ func canSoftDeleteContentHistory(ctx *context.Context, issue *models.Issue, comm canSoftDelete := false if ctx.Repo.IsOwner() { canSoftDelete = true - } else if ctx.Repo.CanWrite(models.UnitTypeIssues) { + } else if ctx.Repo.CanWrite(unit.TypeIssues) { if comment == nil { // the issue poster or the history poster can soft-delete canSoftDelete = ctx.User.ID == issue.PosterID || ctx.User.ID == history.PosterID diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index e98d189c1a..08b285df0a 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -10,6 +10,7 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/markup" @@ -29,13 +30,13 @@ const ( // MustEnableProjects check if projects are enabled in settings func MustEnableProjects(ctx *context.Context) { - if models.UnitTypeProjects.UnitGlobalDisabled() { + if unit.TypeProjects.UnitGlobalDisabled() { ctx.NotFound("EnableKanbanBoard", nil) return } if ctx.Repo.Repository != nil { - if !ctx.Repo.CanRead(models.UnitTypeProjects) { + if !ctx.Repo.CanRead(unit.TypeProjects) { ctx.NotFound("MustEnableProjects", nil) return } @@ -107,7 +108,7 @@ func Projects(ctx *context.Context) { pager.AddParam(ctx, "state", "State") ctx.Data["Page"] = pager - ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects) + ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) ctx.Data["IsShowClosed"] = isShowClosed ctx.Data["IsProjectsPage"] = true ctx.Data["SortType"] = sortType @@ -119,7 +120,7 @@ func Projects(ctx *context.Context) { func NewProject(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.projects.new") ctx.Data["ProjectTypes"] = models.GetProjectsConfig() - ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects) + ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) ctx.HTML(http.StatusOK, tplProjectsNew) } @@ -129,7 +130,7 @@ func NewProjectPost(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.projects.new") if ctx.HasError() { - ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects) + ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) ctx.Data["ProjectTypes"] = models.GetProjectsConfig() ctx.HTML(http.StatusOK, tplProjectsNew) return @@ -206,7 +207,7 @@ func DeleteProject(ctx *context.Context) { func EditProject(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.projects.edit") ctx.Data["PageIsEditProjects"] = true - ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects) + ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) p, err := models.GetProjectByID(ctx.ParamsInt64(":id")) if err != nil { @@ -233,7 +234,7 @@ func EditProjectPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.CreateProjectForm) ctx.Data["Title"] = ctx.Tr("repo.projects.edit") ctx.Data["PageIsEditProjects"] = true - ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects) + ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) if ctx.HasError() { ctx.HTML(http.StatusOK, tplProjectsNew) @@ -330,7 +331,7 @@ func ViewProject(ctx *context.Context) { return } - ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects) + ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) ctx.Data["Project"] = project ctx.Data["Boards"] = boards @@ -371,7 +372,7 @@ func DeleteProjectBoard(ctx *context.Context) { return } - if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(models.AccessModeWrite, models.UnitTypeProjects) { + if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(models.AccessModeWrite, unit.TypeProjects) { ctx.JSON(http.StatusForbidden, map[string]string{ "message": "Only authorized users are allowed to perform this action.", }) @@ -420,7 +421,7 @@ func DeleteProjectBoard(ctx *context.Context) { // AddBoardToProjectPost allows a new board to be added to a project. func AddBoardToProjectPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.EditProjectBoardForm) - if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(models.AccessModeWrite, models.UnitTypeProjects) { + if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(models.AccessModeWrite, unit.TypeProjects) { ctx.JSON(http.StatusForbidden, map[string]string{ "message": "Only authorized users are allowed to perform this action.", }) @@ -460,7 +461,7 @@ func checkProjectBoardChangePermissions(ctx *context.Context) (*models.Project, return nil, nil } - if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(models.AccessModeWrite, models.UnitTypeProjects) { + if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(models.AccessModeWrite, unit.TypeProjects) { ctx.JSON(http.StatusForbidden, map[string]string{ "message": "Only authorized users are allowed to perform this action.", }) @@ -554,7 +555,7 @@ func MoveIssueAcrossBoards(ctx *context.Context) { return } - if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(models.AccessModeWrite, models.UnitTypeProjects) { + if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(models.AccessModeWrite, unit.TypeProjects) { ctx.JSON(http.StatusForbidden, map[string]string{ "message": "Only authorized users are allowed to perform this action.", }) @@ -626,7 +627,7 @@ func MoveIssueAcrossBoards(ctx *context.Context) { func CreateProject(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.projects.new") ctx.Data["ProjectTypes"] = models.GetProjectsConfig() - ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects) + ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) ctx.HTML(http.StatusOK, tplGenericProjectsNew) } @@ -642,7 +643,7 @@ func CreateProjectPost(ctx *context.Context, form forms.UserCreateProjectForm) { ctx.Data["ContextUser"] = user if ctx.HasError() { - ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects) + ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) ctx.HTML(http.StatusOK, tplGenericProjectsNew) return } diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 153ebc306f..0ac05a7609 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" @@ -73,11 +74,11 @@ func getRepository(ctx *context.Context, repoID int64) *models.Repository { return nil } - if !perm.CanRead(models.UnitTypeCode) { + if !perm.CanRead(unit.TypeCode) { log.Trace("Permission Denied: User %-v cannot read %-v of repo %-v\n"+ "User in repo has Permissions: %-+v", ctx.User, - models.UnitTypeCode, + unit.TypeCode, ctx.Repo, perm) ctx.NotFound("getRepository", nil) @@ -1034,7 +1035,7 @@ func CompareAndPullRequestPost(ctx *context.Context) { ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "comment") - ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypePullRequests) + ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(unit.TypePullRequests) var ( repo = ctx.Repo.Repository @@ -1221,7 +1222,7 @@ func CleanUpPullRequest(ctx *context.Context) { ctx.ServerError("GetUserRepoPermission", err) return } - if !perm.CanWrite(models.UnitTypeCode) { + if !perm.CanWrite(unit.TypeCode) { ctx.NotFound("CleanUpPullRequest", nil) return } diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index df1fd745d8..20f6ddd2a5 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" @@ -102,7 +103,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) { } ctx.Data["Tags"] = tags - writeAccess := ctx.Repo.CanWrite(models.UnitTypeReleases) + writeAccess := ctx.Repo.CanWrite(unit.TypeReleases) ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived opts := models.FindReleasesOptions{ @@ -186,7 +187,7 @@ func SingleRelease(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.releases") ctx.Data["PageIsReleaseList"] = true - writeAccess := ctx.Repo.CanWrite(models.UnitTypeReleases) + writeAccess := ctx.Repo.CanWrite(unit.TypeReleases) ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived release, err := models.GetRelease(ctx.Repo.Repository.ID, ctx.Params("*")) diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 735bf4fe9f..c70dec6481 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.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/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/graceful" @@ -144,7 +145,7 @@ func Create(ctx *context.Context) { templateID := ctx.FormInt64("template_id") if templateID > 0 { templateRepo, err := models.GetRepositoryByID(templateID) - if err == nil && templateRepo.CheckUnitUser(ctxUser, models.UnitTypeCode) { + if err == nil && templateRepo.CheckUnitUser(ctxUser, unit.TypeCode) { ctx.Data["repo_template"] = templateID ctx.Data["repo_template_name"] = templateRepo.Name } diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index e71a5bf482..b104ede005 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + unit_model "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" @@ -337,7 +338,7 @@ func SettingsPost(ctx *context.Context) { case "advanced": var repoChanged bool var units []models.RepoUnit - var deleteUnitTypes []models.UnitType + var deleteUnitTypes []unit_model.Type // This section doesn't require repo_name/RepoName to be set in the form, don't show it // as an error on the UI for this action @@ -348,7 +349,7 @@ func SettingsPost(ctx *context.Context) { repoChanged = true } - if form.EnableWiki && form.EnableExternalWiki && !models.UnitTypeExternalWiki.UnitGlobalDisabled() { + if form.EnableWiki && form.EnableExternalWiki && !unit_model.TypeExternalWiki.UnitGlobalDisabled() { if !validation.IsValidExternalURL(form.ExternalWikiURL) { ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error")) ctx.Redirect(repo.Link() + "/settings") @@ -357,29 +358,29 @@ func SettingsPost(ctx *context.Context) { units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeExternalWiki, + Type: unit_model.TypeExternalWiki, Config: &models.ExternalWikiConfig{ ExternalWikiURL: form.ExternalWikiURL, }, }) - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeWiki) - } else if form.EnableWiki && !form.EnableExternalWiki && !models.UnitTypeWiki.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeWiki) + } else if form.EnableWiki && !form.EnableExternalWiki && !unit_model.TypeWiki.UnitGlobalDisabled() { units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeWiki, + Type: unit_model.TypeWiki, Config: new(models.UnitConfig), }) - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalWiki) + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki) } else { - 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 form.EnableIssues && form.EnableExternalTracker && !models.UnitTypeExternalTracker.UnitGlobalDisabled() { + if form.EnableIssues && form.EnableExternalTracker && !unit_model.TypeExternalTracker.UnitGlobalDisabled() { if !validation.IsValidExternalURL(form.ExternalTrackerURL) { ctx.Flash.Error(ctx.Tr("repo.settings.external_tracker_url_error")) ctx.Redirect(repo.Link() + "/settings") @@ -392,47 +393,47 @@ func SettingsPost(ctx *context.Context) { } units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeExternalTracker, + Type: unit_model.TypeExternalTracker, Config: &models.ExternalTrackerConfig{ ExternalTrackerURL: form.ExternalTrackerURL, ExternalTrackerFormat: form.TrackerURLFormat, ExternalTrackerStyle: form.TrackerIssueStyle, }, }) - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeIssues) - } else if form.EnableIssues && !form.EnableExternalTracker && !models.UnitTypeIssues.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues) + } else if form.EnableIssues && !form.EnableExternalTracker && !unit_model.TypeIssues.UnitGlobalDisabled() { units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeIssues, + Type: unit_model.TypeIssues, Config: &models.IssuesConfig{ EnableTimetracker: form.EnableTimetracker, AllowOnlyContributorsToTrackTime: form.AllowOnlyContributorsToTrackTime, EnableDependencies: form.EnableIssueDependencies, }, }) - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalTracker) + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalTracker) } else { - 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 form.EnableProjects && !models.UnitTypeProjects.UnitGlobalDisabled() { + if form.EnableProjects && !unit_model.TypeProjects.UnitGlobalDisabled() { units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeProjects, + Type: unit_model.TypeProjects, }) - } else if !models.UnitTypeProjects.UnitGlobalDisabled() { - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeProjects) + } else if !unit_model.TypeProjects.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeProjects) } - if form.EnablePulls && !models.UnitTypePullRequests.UnitGlobalDisabled() { + if form.EnablePulls && !unit_model.TypePullRequests.UnitGlobalDisabled() { units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypePullRequests, + Type: unit_model.TypePullRequests, Config: &models.PullRequestsConfig{ IgnoreWhitespaceConflicts: form.PullsIgnoreWhitespace, AllowMerge: form.PullsAllowMerge, @@ -445,8 +446,8 @@ func SettingsPost(ctx *context.Context) { DefaultMergeStyle: models.MergeStyle(form.PullsDefaultMergeStyle), }, }) - } else if !models.UnitTypePullRequests.UnitGlobalDisabled() { - deleteUnitTypes = append(deleteUnitTypes, models.UnitTypePullRequests) + } else if !unit_model.TypePullRequests.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePullRequests) } if err := models.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil { @@ -786,7 +787,7 @@ func Collaboration(ctx *context.Context) { ctx.Data["OrgID"] = ctx.Repo.Repository.OwnerID ctx.Data["OrgName"] = ctx.Repo.Repository.OwnerName ctx.Data["Org"] = ctx.Repo.Repository.Owner - ctx.Data["Units"] = models.Units + ctx.Data["Units"] = unit_model.Units ctx.HTML(http.StatusOK, tplCollaboration) } diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 90be631c73..72f12e9bf2 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + unit_model "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/charset" @@ -353,7 +354,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { } // Check permission to add or upload new file. - if ctx.Repo.CanWrite(models.UnitTypeCode) && ctx.Repo.IsViewBranch { + if ctx.Repo.CanWrite(unit_model.TypeCode) && ctx.Repo.IsViewBranch { ctx.Data["CanAddFile"] = !ctx.Repo.Repository.IsArchived ctx.Data["CanUploadFile"] = setting.Repository.Upload.Enabled && !ctx.Repo.Repository.IsArchived } @@ -514,7 +515,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st } } else if !ctx.Repo.IsViewBranch { ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch") - } else if !ctx.Repo.CanWrite(models.UnitTypeCode) { + } else if !ctx.Repo.CanWrite(unit_model.TypeCode) { ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit") } } @@ -563,7 +564,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st } } else if !ctx.Repo.IsViewBranch { ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch") - } else if !ctx.Repo.CanWrite(models.UnitTypeCode) { + } else if !ctx.Repo.CanWrite(unit_model.TypeCode) { ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_have_write_access") } } @@ -607,13 +608,13 @@ func checkHomeCodeViewable(ctx *context.Context) { } } - var firstUnit *models.Unit + var firstUnit *unit_model.Unit for _, repoUnit := range ctx.Repo.Units { - if repoUnit.Type == models.UnitTypeCode { + if repoUnit.Type == unit_model.TypeCode { return } - unit, ok := models.Units[repoUnit.Type] + unit, ok := unit_model.Units[repoUnit.Type] if ok && (firstUnit == nil || !firstUnit.IsLessThan(unit)) { firstUnit = &unit } diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index a571c46fd7..16927de2e9 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -15,6 +15,7 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" @@ -40,14 +41,14 @@ const ( // MustEnableWiki check if wiki is enabled, if external then redirect func MustEnableWiki(ctx *context.Context) { - if !ctx.Repo.CanRead(models.UnitTypeWiki) && - !ctx.Repo.CanRead(models.UnitTypeExternalWiki) { + if !ctx.Repo.CanRead(unit.TypeWiki) && + !ctx.Repo.CanRead(unit.TypeExternalWiki) { if log.IsTrace() { log.Trace("Permission Denied: User %-v cannot read %-v or %-v of repo %-v\n"+ "User in repo has Permissions: %-+v", ctx.User, - models.UnitTypeWiki, - models.UnitTypeExternalWiki, + unit.TypeWiki, + unit.TypeExternalWiki, ctx.Repo.Repository, ctx.Repo.Permission) } @@ -55,7 +56,7 @@ func MustEnableWiki(ctx *context.Context) { return } - unit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalWiki) + unit, err := ctx.Repo.Repository.GetUnit(unit.TypeExternalWiki) if err == nil { ctx.Redirect(unit.ExternalWikiConfig().ExternalWikiURL) return @@ -380,7 +381,7 @@ func renderEditPage(ctx *context.Context) { // Wiki renders single wiki page func Wiki(ctx *context.Context) { ctx.Data["PageIsWiki"] = true - ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(models.UnitTypeWiki) && !ctx.Repo.Repository.IsArchived + ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(unit.TypeWiki) && !ctx.Repo.Repository.IsArchived if !ctx.Repo.Repository.HasWiki() { ctx.Data["Title"] = ctx.Tr("repo.wiki") @@ -422,7 +423,7 @@ func Wiki(ctx *context.Context) { // WikiRevision renders file revision list of wiki page func WikiRevision(ctx *context.Context) { ctx.Data["PageIsWiki"] = true - ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(models.UnitTypeWiki) && !ctx.Repo.Repository.IsArchived + ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(unit.TypeWiki) && !ctx.Repo.Repository.IsArchived if !ctx.Repo.Repository.HasWiki() { ctx.Data["Title"] = ctx.Tr("repo.wiki") @@ -467,7 +468,7 @@ func WikiPages(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.wiki.pages") ctx.Data["PageIsWiki"] = true - ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(models.UnitTypeWiki) && !ctx.Repo.Repository.IsArchived + ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(unit.TypeWiki) && !ctx.Repo.Repository.IsArchived wikiRepo, commit, err := findWikiRepoCommit(ctx) if err != nil { diff --git a/routers/web/user/home.go b/routers/web/user/home.go index af5750e616..1305b0095a 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" @@ -144,7 +145,7 @@ func Dashboard(ctx *context.Context) { // Milestones render the user milestones page func Milestones(ctx *context.Context) { - if models.UnitTypeIssues.UnitGlobalDisabled() && models.UnitTypePullRequests.UnitGlobalDisabled() { + if unit.TypeIssues.UnitGlobalDisabled() && unit.TypePullRequests.UnitGlobalDisabled() { log.Debug("Milestones overview page not available as both issues and pull requests are globally disabled") ctx.Status(404) return @@ -316,7 +317,7 @@ func Milestones(ctx *context.Context) { // Pulls renders the user's pull request overview page func Pulls(ctx *context.Context) { - if models.UnitTypePullRequests.UnitGlobalDisabled() { + if unit.TypePullRequests.UnitGlobalDisabled() { log.Debug("Pull request overview page not available as it is globally disabled.") ctx.Status(404) return @@ -324,12 +325,12 @@ func Pulls(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("pull_requests") ctx.Data["PageIsPulls"] = true - buildIssueOverview(ctx, models.UnitTypePullRequests) + buildIssueOverview(ctx, unit.TypePullRequests) } // Issues renders the user's issues overview page func Issues(ctx *context.Context) { - if models.UnitTypeIssues.UnitGlobalDisabled() { + if unit.TypeIssues.UnitGlobalDisabled() { log.Debug("Issues overview page not available as it is globally disabled.") ctx.Status(404) return @@ -337,13 +338,13 @@ func Issues(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("issues") ctx.Data["PageIsIssues"] = true - buildIssueOverview(ctx, models.UnitTypeIssues) + buildIssueOverview(ctx, unit.TypeIssues) } // Regexp for repos query var issueReposQueryPattern = regexp.MustCompile(`^\[\d+(,\d+)*,?\]$`) -func buildIssueOverview(ctx *context.Context, unitType models.UnitType) { +func buildIssueOverview(ctx *context.Context, unitType unit.Type) { // ---------------------------------------------------- // Determine user; can be either user or organization. @@ -397,7 +398,7 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) { // - Count Issues by repo // -------------------------------------------------------------------------- - isPullList := unitType == models.UnitTypePullRequests + isPullList := unitType == unit.TypePullRequests opts := &models.IssuesOptions{ IsPull: util.OptionalBoolOf(isPullList), SortType: sortType, @@ -724,7 +725,7 @@ func getRepoIDs(reposQuery string) []int64 { return repoIDs } -func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType models.UnitType) ([]int64, error) { +func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType unit.Type) ([]int64, error) { var userRepoIDs []int64 var err error @@ -749,7 +750,7 @@ func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType mode // getActiveTeamOrOrgRepoIds gets RepoIDs for ctxUser as Organization. // Should be called if and only if ctxUser.IsOrganization == true. -func getActiveTeamOrOrgRepoIds(ctxUser *models.User, team *models.Team, unitType models.UnitType) ([]int64, error) { +func getActiveTeamOrOrgRepoIds(ctxUser *models.User, team *models.Team, unitType unit.Type) ([]int64, error) { var orgRepoIDs []int64 var err error var env models.AccessibleReposEnvironment @@ -791,7 +792,7 @@ func issueIDsFromSearch(ctxUser *models.User, keyword string, opts *models.Issue return issueIDsFromSearch, nil } -func repoIDMap(ctxUser *models.User, issueCountByRepo map[int64]int64, unitType models.UnitType) (map[int64]*models.Repository, error) { +func repoIDMap(ctxUser *models.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*models.Repository, error) { repoByID := make(map[int64]*models.Repository, len(issueCountByRepo)) for id := range issueCountByRepo { if id <= 0 { diff --git a/routers/web/web.go b/routers/web/web.go index c0bb74da2e..69f737c3e1 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -10,7 +10,7 @@ import ( "os" "path" - "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/httpcache" @@ -486,18 +486,18 @@ func RegisterRoutes(m *web.Route) { } reqRepoAdmin := context.RequireRepoAdmin() - reqRepoCodeWriter := context.RequireRepoWriter(models.UnitTypeCode) - reqRepoCodeReader := context.RequireRepoReader(models.UnitTypeCode) - reqRepoReleaseWriter := context.RequireRepoWriter(models.UnitTypeReleases) - reqRepoReleaseReader := context.RequireRepoReader(models.UnitTypeReleases) - reqRepoWikiWriter := context.RequireRepoWriter(models.UnitTypeWiki) - reqRepoIssueWriter := context.RequireRepoWriter(models.UnitTypeIssues) - reqRepoIssueReader := context.RequireRepoReader(models.UnitTypeIssues) - reqRepoPullsReader := context.RequireRepoReader(models.UnitTypePullRequests) - reqRepoIssuesOrPullsWriter := context.RequireRepoWriterOr(models.UnitTypeIssues, models.UnitTypePullRequests) - reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(models.UnitTypeIssues, models.UnitTypePullRequests) - reqRepoProjectsReader := context.RequireRepoReader(models.UnitTypeProjects) - reqRepoProjectsWriter := context.RequireRepoWriter(models.UnitTypeProjects) + reqRepoCodeWriter := context.RequireRepoWriter(unit.TypeCode) + reqRepoCodeReader := context.RequireRepoReader(unit.TypeCode) + reqRepoReleaseWriter := context.RequireRepoWriter(unit.TypeReleases) + reqRepoReleaseReader := context.RequireRepoReader(unit.TypeReleases) + reqRepoWikiWriter := context.RequireRepoWriter(unit.TypeWiki) + reqRepoIssueWriter := context.RequireRepoWriter(unit.TypeIssues) + reqRepoIssueReader := context.RequireRepoReader(unit.TypeIssues) + reqRepoPullsReader := context.RequireRepoReader(unit.TypePullRequests) + reqRepoIssuesOrPullsWriter := context.RequireRepoWriterOr(unit.TypeIssues, unit.TypePullRequests) + reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(unit.TypeIssues, unit.TypePullRequests) + reqRepoProjectsReader := context.RequireRepoReader(unit.TypeProjects) + reqRepoProjectsWriter := context.RequireRepoWriter(unit.TypeProjects) // ***** START: Organization ***** m.Group("/org", func() { @@ -920,12 +920,12 @@ func RegisterRoutes(m *web.Route) { m.Group("/activity", func() { m.Get("", repo.Activity) m.Get("/{period}", repo.Activity) - }, context.RepoRef(), repo.MustBeNotEmpty, context.RequireRepoReaderOr(models.UnitTypePullRequests, models.UnitTypeIssues, models.UnitTypeReleases)) + }, context.RepoRef(), repo.MustBeNotEmpty, context.RequireRepoReaderOr(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases)) m.Group("/activity_author_data", func() { m.Get("", repo.ActivityAuthors) m.Get("/{period}", repo.ActivityAuthors) - }, context.RepoRef(), repo.MustBeNotEmpty, context.RequireRepoReaderOr(models.UnitTypeCode)) + }, context.RepoRef(), repo.MustBeNotEmpty, context.RequireRepoReaderOr(unit.TypeCode)) m.Group("/archive", func() { m.Get("/*", repo.Download) |