aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo
diff options
context:
space:
mode:
Diffstat (limited to 'routers/web/repo')
-rw-r--r--routers/web/repo/blame.go9
-rw-r--r--routers/web/repo/commit.go5
-rw-r--r--routers/web/repo/compare.go9
-rw-r--r--routers/web/repo/http.go4
-rw-r--r--routers/web/repo/issue.go27
-rw-r--r--routers/web/repo/lfs.go6
-rw-r--r--routers/web/repo/middlewares.go4
-rw-r--r--routers/web/repo/migrate.go12
-rw-r--r--routers/web/repo/pull.go15
-rw-r--r--routers/web/repo/release.go15
-rw-r--r--routers/web/repo/repo.go17
-rw-r--r--routers/web/repo/setting.go25
-rw-r--r--routers/web/repo/settings_test.go43
-rw-r--r--routers/web/repo/view.go14
-rw-r--r--routers/web/repo/webhook.go3
15 files changed, 113 insertions, 95 deletions
diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go
index 2fd72d81ab..5786aa1eb2 100644
--- a/routers/web/repo/blame.go
+++ b/routers/web/repo/blame.go
@@ -12,6 +12,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
@@ -139,9 +140,9 @@ func RefBlame(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplBlame)
}
-func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[string]*models.UserCommit, map[string]string) {
+func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[string]*user_model.UserCommit, map[string]string) {
// store commit data by SHA to look up avatar info etc
- commitNames := make(map[string]*models.UserCommit)
+ commitNames := make(map[string]*user_model.UserCommit)
// previousCommits contains links from SHA to parent SHA,
// if parent also contains the current TreePath.
previousCommits := make(map[string]string)
@@ -195,14 +196,14 @@ func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[st
}
// populate commit email addresses to later look up avatars.
- for _, c := range models.ValidateCommitsWithEmails(commits) {
+ for _, c := range user_model.ValidateCommitsWithEmails(commits) {
commitNames[c.ID.String()] = c
}
return commitNames, previousCommits
}
-func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames map[string]*models.UserCommit, previousCommits map[string]string) {
+func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames map[string]*user_model.UserCommit, previousCommits map[string]string) {
repoLink := ctx.Repo.RepoLink
language := ""
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go
index ecb5107a3d..48386f7935 100644
--- a/routers/web/repo/commit.go
+++ b/routers/web/repo/commit.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/context"
@@ -344,7 +345,7 @@ func Diff(ctx *context.Context) {
verification := models.ParseCommitWithSignature(commit)
ctx.Data["Verification"] = verification
- ctx.Data["Author"] = models.ValidateCommitWithEmail(commit)
+ ctx.Data["Author"] = user_model.ValidateCommitWithEmail(commit)
ctx.Data["Parents"] = parents
ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0
@@ -358,7 +359,7 @@ func Diff(ctx *context.Context) {
if err == nil {
ctx.Data["Note"] = string(charset.ToUTF8WithFallback(note.Message))
ctx.Data["NoteCommit"] = note.Commit
- ctx.Data["NoteAuthor"] = models.ValidateCommitWithEmail(note.Commit)
+ ctx.Data["NoteAuthor"] = user_model.ValidateCommitWithEmail(note.Commit)
}
ctx.Data["BranchName"], err = commit.GetBranchName()
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 706009820a..865a734caf 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/context"
@@ -163,7 +164,7 @@ func setCsvCompareContext(ctx *context.Context) {
// CompareInfo represents the collected results from ParseCompareInfo
type CompareInfo struct {
- HeadUser *models.User
+ HeadUser *user_model.User
HeadRepo *models.Repository
HeadGitRepo *git.Repository
CompareInfo *git.CompareInfo
@@ -237,9 +238,9 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
} else if len(headInfos) == 2 {
headInfosSplit := strings.Split(headInfos[0], "/")
if len(headInfosSplit) == 1 {
- ci.HeadUser, err = models.GetUserByName(headInfos[0])
+ ci.HeadUser, err = user_model.GetUserByName(headInfos[0])
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound("GetUserByName", nil)
} else {
ctx.ServerError("GetUserByName", err)
@@ -262,7 +263,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
return nil
}
if err := ci.HeadRepo.GetOwner(); err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound("GetUserByName", nil)
} else {
ctx.ServerError("GetUserByName", err)
diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go
index 0626d08a7c..ce2d977518 100644
--- a/routers/web/repo/http.go
+++ b/routers/web/repo/http.go
@@ -110,9 +110,9 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
reponame = reponame[:len(reponame)-5]
}
- owner, err := models.GetUserByName(username)
+ owner, err := user_model.GetUserByName(username)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
if redirectUserID, err := user_model.LookupUserRedirect(username); err == nil {
context.RedirectToUser(ctx, username, redirectUserID)
} else {
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index ac6240e282..1ff126c7d1 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@@ -470,7 +471,7 @@ func retrieveProjects(ctx *context.Context, repo *models.Repository) {
type repoReviewerSelection struct {
IsTeam bool
Team *models.Team
- User *models.User
+ User *user_model.User
Review *models.Review
CanChange bool
Checked bool
@@ -503,7 +504,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issue
reviewersResult []*repoReviewerSelection
teamReviewersResult []*repoReviewerSelection
teamReviewers []*models.Team
- reviewers []*models.User
+ reviewers []*user_model.User
)
if canChooseReviewer {
@@ -575,7 +576,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issue
for _, item := range pullReviews {
if item.Review.ReviewerID > 0 {
if err = item.Review.LoadReviewer(); err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
continue
}
ctx.ServerError("LoadReviewer", err)
@@ -919,7 +920,7 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull
// Check if the passed assignees actually exists and is assignable
for _, aID := range assigneeIDs {
- assignee, err := models.GetUserByID(aID)
+ assignee, err := user_model.GetUserByID(aID)
if err != nil {
ctx.ServerError("GetUserByID", err)
return nil, nil, 0, 0
@@ -1019,7 +1020,7 @@ func NewIssuePost(ctx *context.Context) {
}
// roleDescriptor returns the Role Decriptor for a comment in/with the given repo, poster and issue
-func roleDescriptor(repo *models.Repository, poster *models.User, issue *models.Issue) (models.RoleDescriptor, error) {
+func roleDescriptor(repo *models.Repository, poster *user_model.User, issue *models.Issue) (models.RoleDescriptor, error) {
perm, err := models.GetUserRepoPermission(repo, poster)
if err != nil {
return models.RoleDescriptorNone, err
@@ -1267,7 +1268,7 @@ func ViewIssue(ctx *context.Context) {
ok bool
marked = make(map[int64]models.RoleDescriptor)
comment *models.Comment
- participants = make([]*models.User, 1, 10)
+ participants = make([]*user_model.User, 1, 10)
)
if ctx.Repo.Repository.IsTimetrackerEnabled() {
if ctx.IsSigned {
@@ -1430,11 +1431,11 @@ func ViewIssue(ctx *context.Context) {
continue
}
if err = comment.Review.LoadAttributes(); err != nil {
- if !models.IsErrUserNotExist(err) {
+ if !user_model.IsErrUserNotExist(err) {
ctx.ServerError("Review.LoadAttributes", err)
return
}
- comment.Review.Reviewer = models.NewGhostUser()
+ comment.Review.Reviewer = user_model.NewGhostUser()
}
if err = comment.Review.LoadCodeComments(); err != nil {
ctx.ServerError("Review.LoadCodeComments", err)
@@ -1833,12 +1834,12 @@ func UpdateIssueAssignee(ctx *context.Context) {
for _, issue := range issues {
switch action {
case "clear":
- if err := issue_service.DeleteNotPassedAssignee(issue, ctx.User, []*models.User{}); err != nil {
+ if err := issue_service.DeleteNotPassedAssignee(issue, ctx.User, []*user_model.User{}); err != nil {
ctx.ServerError("ClearAssignees", err)
return
}
default:
- assignee, err := models.GetUserByID(assigneeID)
+ assignee, err := user_model.GetUserByID(assigneeID)
if err != nil {
ctx.ServerError("GetUserByID", err)
return
@@ -1949,9 +1950,9 @@ func UpdatePullReviewRequest(ctx *context.Context) {
continue
}
- reviewer, err := models.GetUserByID(reviewID)
+ reviewer, err := user_model.GetUserByID(reviewID)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
log.Warn(
"UpdatePullReviewRequest: requested reviewer [%d] for %-v to %-v#%d is not exist: Error: %v",
reviewID, issue.Repo, issue.Index,
@@ -2452,7 +2453,7 @@ func ChangeCommentReaction(ctx *context.Context) {
})
}
-func addParticipant(poster *models.User, participants []*models.User) []*models.User {
+func addParticipant(poster *user_model.User, participants []*user_model.User) []*user_model.User {
for _, part := range participants {
if poster.ID == part.ID {
return participants
diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go
index b15c7628db..b1bc06f08b 100644
--- a/routers/web/repo/lfs.go
+++ b/routers/web/repo/lfs.go
@@ -216,9 +216,9 @@ func LFSLockFile(ctx *context.Context) {
}
_, err := models.CreateLFSLock(&models.LFSLock{
- Repo: ctx.Repo.Repository,
- Path: lockPath,
- Owner: ctx.User,
+ Repo: ctx.Repo.Repository,
+ Path: lockPath,
+ OwnerID: ctx.User.ID,
})
if err != nil {
if models.IsErrLFSLockAlreadyExist(err) {
diff --git a/routers/web/repo/middlewares.go b/routers/web/repo/middlewares.go
index 0dc6e1cb72..3ee9d1a3e9 100644
--- a/routers/web/repo/middlewares.go
+++ b/routers/web/repo/middlewares.go
@@ -7,8 +7,8 @@ package repo
import (
"fmt"
- "code.gitea.io/gitea/models"
admin_model "code.gitea.io/gitea/models/admin"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
)
@@ -56,7 +56,7 @@ func SetDiffViewStyle(ctx *context.Context) {
}
ctx.Data["IsSplitStyle"] = style == "split"
- if err := models.UpdateUserDiffViewStyle(ctx.User, style); err != nil {
+ if err := user_model.UpdateUserDiffViewStyle(ctx.User, style); err != nil {
ctx.ServerError("ErrUpdateDiffViewStyle", err)
}
}
diff --git a/routers/web/repo/migrate.go b/routers/web/repo/migrate.go
index 1940d89628..5eba4690d0 100644
--- a/routers/web/repo/migrate.go
+++ b/routers/web/repo/migrate.go
@@ -11,6 +11,8 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/lfs"
@@ -66,7 +68,7 @@ func Migrate(ctx *context.Context) {
ctx.HTML(http.StatusOK, base.TplName("repo/migrate/"+serviceType.Name()))
}
-func handleMigrateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form *forms.MigrateRepoForm) {
+func handleMigrateError(ctx *context.Context, owner *user_model.User, err error, name string, tpl base.TplName, form *forms.MigrateRepoForm) {
if setting.Repository.DisableMigrations {
ctx.Error(http.StatusForbidden, "MigrateError: the site administrator has disabled migrations")
return
@@ -94,12 +96,12 @@ func handleMigrateError(ctx *context.Context, owner *models.User, err error, nam
default:
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tpl, form)
}
- case models.IsErrNameReserved(err):
+ case db.IsErrNameReserved(err):
ctx.Data["Err_RepoName"] = true
- ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form)
- case models.IsErrNamePatternNotAllowed(err):
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
+ case db.IsErrNamePatternNotAllowed(err):
ctx.Data["Err_RepoName"] = true
- ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
default:
remoteAddr, _ := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
err = util.NewStringURLSanitizedError(err, remoteAddr, true)
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 83e353833f..06aa86206d 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
@@ -237,10 +238,10 @@ func ForkPost(ctx *context.Context) {
switch {
case models.IsErrRepoAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
- case models.IsErrNameReserved(err):
- ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplFork, &form)
- case models.IsErrNamePatternNotAllowed(err):
- ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form)
+ case db.IsErrNameReserved(err):
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplFork, &form)
+ case db.IsErrNamePatternNotAllowed(err):
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplFork, &form)
default:
ctx.ServerError("ForkPost", err)
}
@@ -1024,7 +1025,7 @@ func MergePullRequest(ctx *context.Context) {
ctx.Redirect(issue.Link())
}
-func stopTimerIfAvailable(user *models.User, issue *models.Issue) error {
+func stopTimerIfAvailable(user *user_model.User, issue *models.Issue) error {
if models.StopwatchExists(user.ID, issue.ID) {
if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil {
@@ -1185,9 +1186,9 @@ func TriggerTask(ctx *context.Context) {
return
}
- pusher, err := models.GetUserByID(pusherID)
+ pusher, err := user_model.GetUserByID(pusherID)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusNotFound)
} else {
ctx.ServerError("GetUserByID", err)
diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go
index 3f12ee72bc..9bca4e6897 100644
--- a/routers/web/repo/release.go
+++ b/routers/web/repo/release.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -132,7 +133,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
// Temporary cache commits count of used branches to speed up.
countCache := make(map[string]int64)
- cacheUsers := make(map[int64]*models.User)
+ cacheUsers := make(map[int64]*user_model.User)
if ctx.User != nil {
cacheUsers[ctx.User.ID] = ctx.User
}
@@ -140,10 +141,10 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
for _, r := range releases {
if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok {
- r.Publisher, err = models.GetUserByID(r.PublisherID)
+ r.Publisher, err = user_model.GetUserByID(r.PublisherID)
if err != nil {
- if models.IsErrUserNotExist(err) {
- r.Publisher = models.NewGhostUser()
+ if user_model.IsErrUserNotExist(err) {
+ r.Publisher = user_model.NewGhostUser()
} else {
ctx.ServerError("GetUserByID", err)
return
@@ -207,10 +208,10 @@ func SingleRelease(ctx *context.Context) {
return
}
- release.Publisher, err = models.GetUserByID(release.PublisherID)
+ release.Publisher, err = user_model.GetUserByID(release.PublisherID)
if err != nil {
- if models.IsErrUserNotExist(err) {
- release.Publisher = models.NewGhostUser()
+ if user_model.IsErrUserNotExist(err) {
+ release.Publisher = user_model.NewGhostUser()
} else {
ctx.ServerError("GetUserByID", err)
return
diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go
index 9463fc4c5f..bacfa549b5 100644
--- a/routers/web/repo/repo.go
+++ b/routers/web/repo/repo.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/graceful"
@@ -55,7 +56,7 @@ func MustBeAbleToUpload(ctx *context.Context) {
}
}
-func checkContextUser(ctx *context.Context, uid int64) *models.User {
+func checkContextUser(ctx *context.Context, uid int64) *user_model.User {
orgs, err := models.GetOrgsCanCreateRepoByUserID(ctx.User.ID)
if err != nil {
ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
@@ -79,8 +80,8 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
return ctx.User
}
- org, err := models.GetUserByID(uid)
- if models.IsErrUserNotExist(err) {
+ org, err := user_model.GetUserByID(uid)
+ if user_model.IsErrUserNotExist(err) {
return ctx.User
}
@@ -158,7 +159,7 @@ func Create(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplCreate)
}
-func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) {
+func handleCreateError(ctx *context.Context, owner *user_model.User, err error, name string, tpl base.TplName, form interface{}) {
switch {
case models.IsErrReachLimitOfRepo(err):
ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.MaxCreationLimit()), tpl, form)
@@ -177,12 +178,12 @@ func handleCreateError(ctx *context.Context, owner *models.User, err error, name
default:
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tpl, form)
}
- case models.IsErrNameReserved(err):
+ case db.IsErrNameReserved(err):
ctx.Data["Err_RepoName"] = true
- ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form)
- case models.IsErrNamePatternNotAllowed(err):
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
+ case db.IsErrNamePatternNotAllowed(err):
ctx.Data["Err_RepoName"] = true
- ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
default:
ctx.ServerError(name, err)
}
diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go
index 6753ce1172..20fa9ea785 100644
--- a/routers/web/repo/setting.go
+++ b/routers/web/repo/setting.go
@@ -17,6 +17,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
unit_model "code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
@@ -94,8 +95,8 @@ func SettingsPost(ctx *context.Context) {
switch {
case models.IsErrRepoAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tplSettingsOptions, &form)
- case models.IsErrNameReserved(err):
- ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplSettingsOptions, &form)
+ case db.IsErrNameReserved(err):
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplSettingsOptions, &form)
case models.IsErrRepoFilesAlreadyExist(err):
ctx.Data["Err_RepoName"] = true
switch {
@@ -108,8 +109,8 @@ func SettingsPost(ctx *context.Context) {
default:
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tplSettingsOptions, form)
}
- case models.IsErrNamePatternNotAllowed(err):
- ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form)
+ case db.IsErrNamePatternNotAllowed(err):
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form)
default:
ctx.ServerError("ChangeRepositoryName", err)
}
@@ -577,9 +578,9 @@ func SettingsPost(ctx *context.Context) {
return
}
- newOwner, err := models.GetUserByName(ctx.FormString("new_owner_name"))
+ newOwner, err := user_model.GetUserByName(ctx.FormString("new_owner_name"))
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
return
}
@@ -587,7 +588,7 @@ func SettingsPost(ctx *context.Context) {
return
}
- if newOwner.Type == models.UserTypeOrganization {
+ if newOwner.Type == user_model.UserTypeOrganization {
if !ctx.User.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) {
// The user shouldn't know about this organization
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
@@ -798,9 +799,9 @@ func CollaborationPost(ctx *context.Context) {
return
}
- u, err := models.GetUserByName(name)
+ u, err := user_model.GetUserByName(name)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath())
} else {
@@ -935,10 +936,10 @@ func DeleteTeam(ctx *context.Context) {
}
// parseOwnerAndRepo get repos by owner
-func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository) {
- owner, err := models.GetUserByName(ctx.Params(":username"))
+func parseOwnerAndRepo(ctx *context.Context) (*user_model.User, *models.Repository) {
+ owner, err := user_model.GetUserByName(ctx.Params(":username"))
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound("GetUserByName", err)
} else {
ctx.ServerError("GetUserByName", err)
diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go
index 3e8ae2b07e..8e53babe7c 100644
--- a/routers/web/repo/settings_test.go
+++ b/routers/web/repo/settings_test.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
@@ -105,9 +106,9 @@ func TestCollaborationPost(t *testing.T) {
ctx.Req.Form.Set("collaborator", "user4")
- u := &models.User{
+ u := &user_model.User{
LowerName: "user2",
- Type: models.UserTypeIndividual,
+ Type: user_model.UserTypeIndividual,
}
re := &models.Repository{
@@ -142,7 +143,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) {
ctx.Req.Form.Set("collaborator", "user9")
repo := &context.Repository{
- Owner: &models.User{
+ Owner: &user_model.User{
LowerName: "user2",
},
}
@@ -165,9 +166,9 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
ctx.Req.Form.Set("collaborator", "user4")
- u := &models.User{
+ u := &user_model.User{
LowerName: "user2",
- Type: models.UserTypeIndividual,
+ Type: user_model.UserTypeIndividual,
}
re := &models.Repository{
@@ -207,7 +208,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) {
ctx.Req.Form.Set("collaborator", "user34")
repo := &context.Repository{
- Owner: &models.User{
+ Owner: &user_model.User{
LowerName: "user2",
},
}
@@ -226,9 +227,9 @@ func TestAddTeamPost(t *testing.T) {
ctx.Req.Form.Set("team", "team11")
- org := &models.User{
+ org := &user_model.User{
LowerName: "org26",
- Type: models.UserTypeOrganization,
+ Type: user_model.UserTypeOrganization,
}
team := &models.Team{
@@ -243,7 +244,7 @@ func TestAddTeamPost(t *testing.T) {
}
repo := &context.Repository{
- Owner: &models.User{
+ Owner: &user_model.User{
ID: 26,
LowerName: "org26",
RepoAdminChangeTeamAccess: true,
@@ -266,9 +267,9 @@ func TestAddTeamPost_NotAllowed(t *testing.T) {
ctx.Req.Form.Set("team", "team11")
- org := &models.User{
+ org := &user_model.User{
LowerName: "org26",
- Type: models.UserTypeOrganization,
+ Type: user_model.UserTypeOrganization,
}
team := &models.Team{
@@ -283,7 +284,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) {
}
repo := &context.Repository{
- Owner: &models.User{
+ Owner: &user_model.User{
ID: 26,
LowerName: "org26",
RepoAdminChangeTeamAccess: false,
@@ -307,9 +308,9 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) {
ctx.Req.Form.Set("team", "team11")
- org := &models.User{
+ org := &user_model.User{
LowerName: "org26",
- Type: models.UserTypeOrganization,
+ Type: user_model.UserTypeOrganization,
}
team := &models.Team{
@@ -324,7 +325,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) {
}
repo := &context.Repository{
- Owner: &models.User{
+ Owner: &user_model.User{
ID: 26,
LowerName: "org26",
RepoAdminChangeTeamAccess: true,
@@ -348,9 +349,9 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) {
ctx.Req.Form.Set("team", "team-non-existent")
- org := &models.User{
+ org := &user_model.User{
LowerName: "org26",
- Type: models.UserTypeOrganization,
+ Type: user_model.UserTypeOrganization,
}
re := &models.Repository{
@@ -360,7 +361,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) {
}
repo := &context.Repository{
- Owner: &models.User{
+ Owner: &user_model.User{
ID: 26,
LowerName: "org26",
RepoAdminChangeTeamAccess: true,
@@ -381,9 +382,9 @@ func TestDeleteTeam(t *testing.T) {
ctx.Req.Form.Set("id", "2")
- org := &models.User{
+ org := &user_model.User{
LowerName: "org3",
- Type: models.UserTypeOrganization,
+ Type: user_model.UserTypeOrganization,
}
team := &models.Team{
@@ -398,7 +399,7 @@ func TestDeleteTeam(t *testing.T) {
}
repo := &context.Repository{
- Owner: &models.User{
+ Owner: &user_model.User{
ID: 3,
LowerName: "org3",
RepoAdminChangeTeamAccess: true,
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index 1293882cc5..33420aab3b 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
unit_model "code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/charset"
@@ -449,7 +450,12 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
return
}
if lfsLock != nil {
- ctx.Data["LFSLockOwner"] = lfsLock.Owner.DisplayName()
+ u, err := user_model.GetUserByID(lfsLock.OwnerID)
+ if err != nil {
+ ctx.ServerError("GetTreePathLock", err)
+ return
+ }
+ ctx.Data["LFSLockOwner"] = u.DisplayName()
ctx.Data["LFSLockHint"] = ctx.Tr("repo.editor.this_file_locked")
}
@@ -777,7 +783,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri
return nil
}
ctx.Data["LatestCommitVerification"] = verification
- ctx.Data["LatestCommitUser"] = models.ValidateCommitWithEmail(latestCommit)
+ ctx.Data["LatestCommitUser"] = user_model.ValidateCommitWithEmail(latestCommit)
}
statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{})
@@ -893,7 +899,7 @@ func renderCode(ctx *context.Context) {
}
// RenderUserCards render a page show users according the input template
-func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*models.User, error), tpl base.TplName) {
+func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) {
page := ctx.FormInt("page")
if page <= 0 {
page = 1
@@ -928,7 +934,7 @@ func Stars(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.stargazers")
ctx.Data["CardsTitle"] = ctx.Tr("repo.stargazers")
ctx.Data["PageIsStargazers"] = true
- RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*models.User, error) {
+ RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*user_model.User, error) {
return models.GetStargazers(ctx.Repo.Repository, opts)
}, tplWatchers)
}
diff --git a/routers/web/repo/webhook.go b/routers/web/repo/webhook.go
index 4f6660926e..28ca3e0de5 100644
--- a/routers/web/repo/webhook.go
+++ b/routers/web/repo/webhook.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -1149,7 +1150,7 @@ func TestWebhook(ctx *context.Context) {
// Grab latest commit or fake one if it's empty repository.
commit := ctx.Repo.Commit
if commit == nil {
- ghost := models.NewGhostUser()
+ ghost := user_model.NewGhostUser()
commit = &git.Commit{
ID: git.MustIDFromString(git.EmptySHA),
Author: ghost.NewGitSig(),