aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r--routers/api/v1/repo/file.go5
-rw-r--r--routers/api/v1/repo/issue.go5
-rw-r--r--routers/api/v1/repo/issue_tracked_time.go5
-rw-r--r--routers/api/v1/repo/mirror.go4
-rw-r--r--routers/api/v1/repo/pull.go13
-rw-r--r--routers/api/v1/repo/release.go3
-rw-r--r--routers/api/v1/repo/repo.go61
7 files changed, 51 insertions, 45 deletions
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)
}
}