aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web
diff options
context:
space:
mode:
Diffstat (limited to 'routers/web')
-rw-r--r--routers/web/admin/auths.go82
-rw-r--r--routers/web/admin/emails.go3
-rw-r--r--routers/web/admin/orgs.go3
-rw-r--r--routers/web/admin/repos.go3
-rw-r--r--routers/web/admin/users.go30
-rw-r--r--routers/web/events/events.go3
-rw-r--r--routers/web/explore/org.go3
-rw-r--r--routers/web/explore/repo.go3
-rw-r--r--routers/web/explore/user.go3
-rw-r--r--routers/web/org/home.go5
-rw-r--r--routers/web/org/org_labels.go2
-rw-r--r--routers/web/org/setting.go3
-rw-r--r--routers/web/repo/commit.go3
-rw-r--r--routers/web/repo/issue.go19
-rw-r--r--routers/web/repo/issue_label.go4
-rw-r--r--routers/web/repo/milestone.go3
-rw-r--r--routers/web/repo/pull.go7
-rw-r--r--routers/web/repo/release.go3
-rw-r--r--routers/web/repo/setting.go3
-rw-r--r--routers/web/repo/view.go9
-rw-r--r--routers/web/user/auth.go21
-rw-r--r--routers/web/user/home.go5
-rw-r--r--routers/web/user/oauth.go29
-rw-r--r--routers/web/user/oauth_test.go7
-rw-r--r--routers/web/user/profile.go11
-rw-r--r--routers/web/user/setting/applications.go5
-rw-r--r--routers/web/user/setting/keys.go7
-rw-r--r--routers/web/user/setting/oauth2.go18
-rw-r--r--routers/web/user/setting/profile.go5
-rw-r--r--routers/web/user/setting/security.go5
30 files changed, 169 insertions, 138 deletions
diff --git a/routers/web/admin/auths.go b/routers/web/admin/auths.go
index 2937190a1f..1b005e5c7b 100644
--- a/routers/web/admin/auths.go
+++ b/routers/web/admin/auths.go
@@ -11,6 +11,7 @@ import (
"regexp"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/modules/auth/pam"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -18,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
+ auth_service "code.gitea.io/gitea/services/auth"
"code.gitea.io/gitea/services/auth/source/ldap"
"code.gitea.io/gitea/services/auth/source/oauth2"
pamService "code.gitea.io/gitea/services/auth/source/pam"
@@ -46,13 +48,13 @@ func Authentications(ctx *context.Context) {
ctx.Data["PageIsAdminAuthentications"] = true
var err error
- ctx.Data["Sources"], err = models.LoginSources()
+ ctx.Data["Sources"], err = login.Sources()
if err != nil {
- ctx.ServerError("LoginSources", err)
+ ctx.ServerError("login.Sources", err)
return
}
- ctx.Data["Total"] = models.CountLoginSources()
+ ctx.Data["Total"] = login.CountSources()
ctx.HTML(http.StatusOK, tplAuths)
}
@@ -64,14 +66,14 @@ type dropdownItem struct {
var (
authSources = func() []dropdownItem {
items := []dropdownItem{
- {models.LoginNames[models.LoginLDAP], models.LoginLDAP},
- {models.LoginNames[models.LoginDLDAP], models.LoginDLDAP},
- {models.LoginNames[models.LoginSMTP], models.LoginSMTP},
- {models.LoginNames[models.LoginOAuth2], models.LoginOAuth2},
- {models.LoginNames[models.LoginSSPI], models.LoginSSPI},
+ {login.LDAP.String(), login.LDAP},
+ {login.DLDAP.String(), login.DLDAP},
+ {login.SMTP.String(), login.SMTP},
+ {login.OAuth2.String(), login.OAuth2},
+ {login.SSPI.String(), login.SSPI},
}
if pam.Supported {
- items = append(items, dropdownItem{models.LoginNames[models.LoginPAM], models.LoginPAM})
+ items = append(items, dropdownItem{login.Names[login.PAM], login.PAM})
}
return items
}()
@@ -89,8 +91,8 @@ func NewAuthSource(ctx *context.Context) {
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
- ctx.Data["type"] = models.LoginLDAP
- ctx.Data["CurrentTypeName"] = models.LoginNames[models.LoginLDAP]
+ ctx.Data["type"] = login.LDAP
+ ctx.Data["CurrentTypeName"] = login.Names[login.LDAP]
ctx.Data["CurrentSecurityProtocol"] = ldap.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted]
ctx.Data["smtp_auth"] = "PLAIN"
ctx.Data["is_active"] = true
@@ -217,7 +219,7 @@ func NewAuthSourcePost(ctx *context.Context) {
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
- ctx.Data["CurrentTypeName"] = models.LoginNames[models.LoginType(form.Type)]
+ ctx.Data["CurrentTypeName"] = login.Type(form.Type).String()
ctx.Data["CurrentSecurityProtocol"] = ldap.SecurityProtocolNames[ldap.SecurityProtocol(form.SecurityProtocol)]
ctx.Data["AuthSources"] = authSources
ctx.Data["SecurityProtocols"] = securityProtocols
@@ -233,28 +235,28 @@ func NewAuthSourcePost(ctx *context.Context) {
hasTLS := false
var config convert.Conversion
- switch models.LoginType(form.Type) {
- case models.LoginLDAP, models.LoginDLDAP:
+ switch login.Type(form.Type) {
+ case login.LDAP, login.DLDAP:
config = parseLDAPConfig(form)
hasTLS = ldap.SecurityProtocol(form.SecurityProtocol) > ldap.SecurityProtocolUnencrypted
- case models.LoginSMTP:
+ case login.SMTP:
config = parseSMTPConfig(form)
hasTLS = true
- case models.LoginPAM:
+ case login.PAM:
config = &pamService.Source{
ServiceName: form.PAMServiceName,
EmailDomain: form.PAMEmailDomain,
}
- case models.LoginOAuth2:
+ case login.OAuth2:
config = parseOAuth2Config(form)
- case models.LoginSSPI:
+ case login.SSPI:
var err error
config, err = parseSSPIConfig(ctx, form)
if err != nil {
ctx.RenderWithErr(err.Error(), tplAuthNew, form)
return
}
- existing, err := models.LoginSourcesByType(models.LoginSSPI)
+ existing, err := login.SourcesByType(login.SSPI)
if err != nil || len(existing) > 0 {
ctx.Data["Err_Type"] = true
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_of_type_exist"), tplAuthNew, form)
@@ -271,18 +273,18 @@ func NewAuthSourcePost(ctx *context.Context) {
return
}
- if err := models.CreateLoginSource(&models.LoginSource{
- Type: models.LoginType(form.Type),
+ if err := login.CreateSource(&login.Source{
+ Type: login.Type(form.Type),
Name: form.Name,
IsActive: form.IsActive,
IsSyncEnabled: form.IsSyncEnabled,
Cfg: config,
}); err != nil {
- if models.IsErrLoginSourceAlreadyExist(err) {
+ if login.IsErrSourceAlreadyExist(err) {
ctx.Data["Err_Name"] = true
- ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), tplAuthNew, form)
+ ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(login.ErrSourceAlreadyExist).Name), tplAuthNew, form)
} else {
- ctx.ServerError("CreateSource", err)
+ ctx.ServerError("login.CreateSource", err)
}
return
}
@@ -304,9 +306,9 @@ func EditAuthSource(ctx *context.Context) {
oauth2providers := oauth2.GetOAuth2Providers()
ctx.Data["OAuth2Providers"] = oauth2providers
- source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
+ source, err := login.GetSourceByID(ctx.ParamsInt64(":authid"))
if err != nil {
- ctx.ServerError("GetLoginSourceByID", err)
+ ctx.ServerError("login.GetSourceByID", err)
return
}
ctx.Data["Source"] = source
@@ -339,9 +341,9 @@ func EditAuthSourcePost(ctx *context.Context) {
oauth2providers := oauth2.GetOAuth2Providers()
ctx.Data["OAuth2Providers"] = oauth2providers
- source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
+ source, err := login.GetSourceByID(ctx.ParamsInt64(":authid"))
if err != nil {
- ctx.ServerError("GetLoginSourceByID", err)
+ ctx.ServerError("login.GetSourceByID", err)
return
}
ctx.Data["Source"] = source
@@ -353,19 +355,19 @@ func EditAuthSourcePost(ctx *context.Context) {
}
var config convert.Conversion
- switch models.LoginType(form.Type) {
- case models.LoginLDAP, models.LoginDLDAP:
+ switch login.Type(form.Type) {
+ case login.LDAP, login.DLDAP:
config = parseLDAPConfig(form)
- case models.LoginSMTP:
+ case login.SMTP:
config = parseSMTPConfig(form)
- case models.LoginPAM:
+ case login.PAM:
config = &pamService.Source{
ServiceName: form.PAMServiceName,
EmailDomain: form.PAMEmailDomain,
}
- case models.LoginOAuth2:
+ case login.OAuth2:
config = parseOAuth2Config(form)
- case models.LoginSSPI:
+ case login.SSPI:
config, err = parseSSPIConfig(ctx, form)
if err != nil {
ctx.RenderWithErr(err.Error(), tplAuthEdit, form)
@@ -380,7 +382,7 @@ func EditAuthSourcePost(ctx *context.Context) {
source.IsActive = form.IsActive
source.IsSyncEnabled = form.IsSyncEnabled
source.Cfg = config
- if err := models.UpdateSource(source); err != nil {
+ if err := login.UpdateSource(source); err != nil {
if models.IsErrOpenIDConnectInitialize(err) {
ctx.Flash.Error(err.Error(), true)
ctx.HTML(http.StatusOK, tplAuthEdit)
@@ -397,17 +399,17 @@ func EditAuthSourcePost(ctx *context.Context) {
// DeleteAuthSource response for deleting an auth source
func DeleteAuthSource(ctx *context.Context) {
- source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
+ source, err := login.GetSourceByID(ctx.ParamsInt64(":authid"))
if err != nil {
- ctx.ServerError("GetLoginSourceByID", err)
+ ctx.ServerError("login.GetSourceByID", err)
return
}
- if err = models.DeleteSource(source); err != nil {
- if models.IsErrLoginSourceInUse(err) {
+ if err = auth_service.DeleteLoginSource(source); err != nil {
+ if login.IsErrSourceInUse(err) {
ctx.Flash.Error(ctx.Tr("admin.auths.still_in_used"))
} else {
- ctx.Flash.Error(fmt.Sprintf("DeleteSource: %v", err))
+ ctx.Flash.Error(fmt.Sprintf("DeleteLoginSource: %v", err))
}
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": setting.AppSubURL + "/admin/auths/" + ctx.Params(":authid"),
diff --git a/routers/web/admin/emails.go b/routers/web/admin/emails.go
index 017d696e20..5cbe70020b 100644
--- a/routers/web/admin/emails.go
+++ b/routers/web/admin/emails.go
@@ -10,6 +10,7 @@ import (
"net/url"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -28,7 +29,7 @@ func Emails(ctx *context.Context) {
ctx.Data["PageIsAdminEmails"] = true
opts := &models.SearchEmailOptions{
- ListOptions: models.ListOptions{
+ ListOptions: db.ListOptions{
PageSize: setting.UI.Admin.UserPagingNum,
Page: ctx.FormInt("page"),
},
diff --git a/routers/web/admin/orgs.go b/routers/web/admin/orgs.go
index a2b3ed1bcc..df3118b60f 100644
--- a/routers/web/admin/orgs.go
+++ b/routers/web/admin/orgs.go
@@ -7,6 +7,7 @@ package admin
import (
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
@@ -27,7 +28,7 @@ func Organizations(ctx *context.Context) {
explore.RenderUserSearch(ctx, &models.SearchUserOptions{
Actor: ctx.User,
Type: models.UserTypeOrganization,
- ListOptions: models.ListOptions{
+ ListOptions: db.ListOptions{
PageSize: setting.UI.Admin.OrgPagingNum,
},
Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate},
diff --git a/routers/web/admin/repos.go b/routers/web/admin/repos.go
index 4c3f2ad614..2f4d182af8 100644
--- a/routers/web/admin/repos.go
+++ b/routers/web/admin/repos.go
@@ -10,6 +10,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -68,7 +69,7 @@ func UnadoptedRepos(ctx *context.Context) {
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminRepositories"] = true
- opts := models.ListOptions{
+ opts := db.ListOptions{
PageSize: setting.UI.Admin.UserPagingNum,
Page: ctx.FormInt("page"),
}
diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go
index acccc516bb..2556cae3a8 100644
--- a/routers/web/admin/users.go
+++ b/routers/web/admin/users.go
@@ -12,6 +12,8 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -39,7 +41,7 @@ func Users(ctx *context.Context) {
explore.RenderUserSearch(ctx, &models.SearchUserOptions{
Actor: ctx.User,
Type: models.UserTypeIndividual,
- ListOptions: models.ListOptions{
+ ListOptions: db.ListOptions{
PageSize: setting.UI.Admin.UserPagingNum,
},
SearchByEmail: true,
@@ -56,9 +58,9 @@ func NewUser(ctx *context.Context) {
ctx.Data["login_type"] = "0-0"
- sources, err := models.LoginSources()
+ sources, err := login.Sources()
if err != nil {
- ctx.ServerError("LoginSources", err)
+ ctx.ServerError("login.Sources", err)
return
}
ctx.Data["Sources"] = sources
@@ -75,9 +77,9 @@ func NewUserPost(ctx *context.Context) {
ctx.Data["PageIsAdminUsers"] = true
ctx.Data["DefaultUserVisibilityMode"] = setting.Service.DefaultUserVisibilityMode
- sources, err := models.LoginSources()
+ sources, err := login.Sources()
if err != nil {
- ctx.ServerError("LoginSources", err)
+ ctx.ServerError("login.Sources", err)
return
}
ctx.Data["Sources"] = sources
@@ -94,19 +96,19 @@ func NewUserPost(ctx *context.Context) {
Email: form.Email,
Passwd: form.Password,
IsActive: true,
- LoginType: models.LoginPlain,
+ LoginType: login.Plain,
}
if len(form.LoginType) > 0 {
fields := strings.Split(form.LoginType, "-")
if len(fields) == 2 {
lType, _ := strconv.ParseInt(fields[0], 10, 0)
- u.LoginType = models.LoginType(lType)
+ u.LoginType = login.Type(lType)
u.LoginSource, _ = strconv.ParseInt(fields[1], 10, 64)
u.LoginName = form.LoginName
}
}
- if u.LoginType == models.LoginNoType || u.LoginType == models.LoginPlain {
+ if u.LoginType == login.NoType || u.LoginType == login.Plain {
if len(form.Password) < setting.MinPasswordLength {
ctx.Data["Err_Password"] = true
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplUserNew, &form)
@@ -176,18 +178,18 @@ func prepareUserInfo(ctx *context.Context) *models.User {
ctx.Data["User"] = u
if u.LoginSource > 0 {
- ctx.Data["LoginSource"], err = models.GetLoginSourceByID(u.LoginSource)
+ ctx.Data["LoginSource"], err = login.GetSourceByID(u.LoginSource)
if err != nil {
- ctx.ServerError("GetLoginSourceByID", err)
+ ctx.ServerError("login.GetSourceByID", err)
return nil
}
} else {
- ctx.Data["LoginSource"] = &models.LoginSource{}
+ ctx.Data["LoginSource"] = &login.Source{}
}
- sources, err := models.LoginSources()
+ sources, err := login.Sources()
if err != nil {
- ctx.ServerError("LoginSources", err)
+ ctx.ServerError("login.Sources", err)
return nil
}
ctx.Data["Sources"] = sources
@@ -247,7 +249,7 @@ func EditUserPost(ctx *context.Context) {
if u.LoginSource != loginSource {
u.LoginSource = loginSource
- u.LoginType = models.LoginType(loginType)
+ u.LoginType = login.Type(loginType)
}
}
diff --git a/routers/web/events/events.go b/routers/web/events/events.go
index a630d9c224..974aa755d1 100644
--- a/routers/web/events/events.go
+++ b/routers/web/events/events.go
@@ -9,6 +9,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/eventsource"
@@ -93,7 +94,7 @@ loop:
go unregister()
break loop
case <-stopwatchTimer.C:
- sws, err := models.GetUserStopwatches(ctx.User.ID, models.ListOptions{})
+ sws, err := models.GetUserStopwatches(ctx.User.ID, db.ListOptions{})
if err != nil {
log.Error("Unable to GetUserStopwatches: %v", err)
continue
diff --git a/routers/web/explore/org.go b/routers/web/explore/org.go
index 470e0eb853..d005cfa503 100644
--- a/routers/web/explore/org.go
+++ b/routers/web/explore/org.go
@@ -6,6 +6,7 @@ package explore
import (
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
@@ -33,7 +34,7 @@ func Organizations(ctx *context.Context) {
RenderUserSearch(ctx, &models.SearchUserOptions{
Actor: ctx.User,
Type: models.UserTypeOrganization,
- ListOptions: models.ListOptions{PageSize: setting.UI.ExplorePagingNum},
+ ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
Visible: visibleTypes,
}, tplExploreOrganizations)
}
diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go
index dfc6261b33..78035037e5 100644
--- a/routers/web/explore/repo.go
+++ b/routers/web/explore/repo.go
@@ -8,6 +8,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
@@ -77,7 +78,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
ctx.Data["TopicOnly"] = topicOnly
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
- ListOptions: models.ListOptions{
+ ListOptions: db.ListOptions{
Page: page,
PageSize: opts.PageSize,
},
diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go
index aeaaf92c12..4ddb90132d 100644
--- a/routers/web/explore/user.go
+++ b/routers/web/explore/user.go
@@ -9,6 +9,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
@@ -99,7 +100,7 @@ func Users(ctx *context.Context) {
RenderUserSearch(ctx, &models.SearchUserOptions{
Actor: ctx.User,
Type: models.UserTypeIndividual,
- ListOptions: models.ListOptions{PageSize: setting.UI.ExplorePagingNum},
+ ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
IsActive: util.OptionalBoolTrue,
Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate},
}, tplExploreUsers)
diff --git a/routers/web/org/home.go b/routers/web/org/home.go
index f682dc5cb6..89bd12a18f 100644
--- a/routers/web/org/home.go
+++ b/routers/web/org/home.go
@@ -8,6 +8,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/markup"
@@ -91,7 +92,7 @@ func Home(ctx *context.Context) {
err error
)
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
- ListOptions: models.ListOptions{
+ ListOptions: db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Page: page,
},
@@ -110,7 +111,7 @@ func Home(ctx *context.Context) {
var opts = &models.FindOrgMembersOpts{
OrgID: org.ID,
PublicOnly: true,
- ListOptions: models.ListOptions{Page: 1, PageSize: 25},
+ ListOptions: db.ListOptions{Page: 1, PageSize: 25},
}
if ctx.User != nil {
diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go
index 13728a31b3..5079d9baa7 100644
--- a/routers/web/org/org_labels.go
+++ b/routers/web/org/org_labels.go
@@ -16,7 +16,7 @@ import (
// RetrieveLabels find all the labels of an organization
func RetrieveLabels(ctx *context.Context) {
- labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.FormString("sort"), models.ListOptions{})
+ labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("RetrieveLabels.GetLabels", err)
return
diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go
index 7e6fc5bf4c..277ff9d973 100644
--- a/routers/web/org/setting.go
+++ b/routers/web/org/setting.go
@@ -10,6 +10,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -103,7 +104,7 @@ func SettingsPost(ctx *context.Context) {
// update forks visibility
if visibilityChanged {
- if err := org.GetRepositories(models.ListOptions{Page: 1, PageSize: org.NumRepos}); err != nil {
+ if err := org.GetRepositories(db.ListOptions{Page: 1, PageSize: org.NumRepos}); err != nil {
ctx.ServerError("GetRepositories", err)
return
}
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go
index 810581640c..61435527da 100644
--- a/routers/web/repo/commit.go
+++ b/routers/web/repo/commit.go
@@ -12,6 +12,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/context"
@@ -287,7 +288,7 @@ func Diff(ctx *context.Context) {
commitID = commit.ID.String()
}
- statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, commitID, models.ListOptions{})
+ statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, commitID, db.ListOptions{})
if err != nil {
log.Error("GetLatestCommitStatus: %v", err)
}
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index 013286f2de..7498830d94 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -16,6 +16,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@@ -216,7 +217,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
issues = []*models.Issue{}
} else {
issues, err = models.Issues(&models.IssuesOptions{
- ListOptions: models.ListOptions{
+ ListOptions: db.ListOptions{
Page: pager.Paginater.Current(),
PageSize: setting.UI.IssuePagingNum,
},
@@ -278,14 +279,14 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
return
}
- labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
+ labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
return
}
if repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), models.ListOptions{})
+ orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByOrgID", err)
return
@@ -645,14 +646,14 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository, isPull boo
return nil
}
- labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
+ labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
return nil
}
ctx.Data["Labels"] = labels
if repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), models.ListOptions{})
+ orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
return nil
}
@@ -735,10 +736,10 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs [
ctx.Data[issueTemplateTitleKey] = meta.Title
ctx.Data[ctxDataKey] = templateBody
labelIDs := make([]string, 0, len(meta.Labels))
- if repoLabels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, "", models.ListOptions{}); err == nil {
+ if repoLabels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, "", db.ListOptions{}); err == nil {
ctx.Data["Labels"] = repoLabels
if ctx.Repo.Owner.IsOrganization() {
- if orgLabels, err := models.GetLabelsByOrgID(ctx.Repo.Owner.ID, ctx.FormString("sort"), models.ListOptions{}); err == nil {
+ if orgLabels, err := models.GetLabelsByOrgID(ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{}); err == nil {
ctx.Data["OrgLabels"] = orgLabels
repoLabels = append(repoLabels, orgLabels...)
}
@@ -1164,7 +1165,7 @@ func ViewIssue(ctx *context.Context) {
for i := range issue.Labels {
labelIDMark[issue.Labels[i].ID] = true
}
- labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
+ labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
return
@@ -1172,7 +1173,7 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["Labels"] = labels
if repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), models.ListOptions{})
+ orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByOrgID", err)
return
diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go
index 0ce5114485..b97f57175b 100644
--- a/routers/web/repo/issue_label.go
+++ b/routers/web/repo/issue_label.go
@@ -54,7 +54,7 @@ func InitializeLabels(ctx *context.Context) {
// RetrieveLabels find all the labels of a repository and organization
func RetrieveLabels(ctx *context.Context) {
- labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.FormString("sort"), models.ListOptions{})
+ labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("RetrieveLabels.GetLabels", err)
return
@@ -67,7 +67,7 @@ func RetrieveLabels(ctx *context.Context) {
ctx.Data["Labels"] = labels
if ctx.Repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(ctx.Repo.Owner.ID, ctx.FormString("sort"), models.ListOptions{})
+ orgLabels, err := models.GetLabelsByOrgID(ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByOrgID", err)
return
diff --git a/routers/web/repo/milestone.go b/routers/web/repo/milestone.go
index 80f1eb5231..21e1fb2eab 100644
--- a/routers/web/repo/milestone.go
+++ b/routers/web/repo/milestone.go
@@ -9,6 +9,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/markup"
@@ -59,7 +60,7 @@ func Milestones(ctx *context.Context) {
}
miles, total, err := models.GetMilestones(models.GetMilestonesOption{
- ListOptions: models.ListOptions{
+ ListOptions: db.ListOptions{
Page: page,
PageSize: setting.UI.IssuePagingNum,
},
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 6b369195de..c370e7f04d 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -16,6 +16,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
@@ -335,7 +336,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
if len(compareInfo.Commits) != 0 {
sha := compareInfo.Commits[0].ID.String()
- commitStatuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, sha, models.ListOptions{})
+ commitStatuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, sha, db.ListOptions{})
if err != nil {
ctx.ServerError("GetLatestCommitStatus", err)
return nil
@@ -389,7 +390,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err)
return nil
}
- commitStatuses, err := models.GetLatestCommitStatus(repo.ID, sha, models.ListOptions{})
+ commitStatuses, err := models.GetLatestCommitStatus(repo.ID, sha, db.ListOptions{})
if err != nil {
ctx.ServerError("GetLatestCommitStatus", err)
return nil
@@ -478,7 +479,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
return nil
}
- commitStatuses, err := models.GetLatestCommitStatus(repo.ID, sha, models.ListOptions{})
+ commitStatuses, err := models.GetLatestCommitStatus(repo.ID, sha, db.ListOptions{})
if err != nil {
ctx.ServerError("GetLatestCommitStatus", err)
return nil
diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go
index 0603f0ee97..df1fd745d8 100644
--- a/routers/web/repo/release.go
+++ b/routers/web/repo/release.go
@@ -11,6 +11,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -83,7 +84,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
ctx.Data["PageIsTagList"] = false
}
- listOptions := models.ListOptions{
+ listOptions := db.ListOptions{
Page: ctx.FormInt("page"),
PageSize: ctx.FormInt("limit"),
}
diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go
index ed82c2eeb5..e71a5bf482 100644
--- a/routers/web/repo/setting.go
+++ b/routers/web/repo/setting.go
@@ -15,6 +15,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
@@ -768,7 +769,7 @@ func Collaboration(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsCollaboration"] = true
- users, err := ctx.Repo.Repository.GetCollaborators(models.ListOptions{})
+ users, err := ctx.Repo.Repository.GetCollaborators(db.ListOptions{})
if err != nil {
ctx.ServerError("GetCollaborators", err)
return
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index addde15de1..c0a35bcb4f 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -18,6 +18,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/charset"
@@ -377,7 +378,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
ctx.Data["LatestCommitUser"] = models.ValidateCommitWithEmail(latestCommit)
- statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), models.ListOptions{})
+ statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{})
if err != nil {
log.Error("GetLatestCommitStatus: %v", err)
}
@@ -758,7 +759,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 models.ListOptions) ([]*models.User, error), tpl base.TplName) {
+func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*models.User, error), tpl base.TplName) {
page := ctx.FormInt("page")
if page <= 0 {
page = 1
@@ -766,7 +767,7 @@ func RenderUserCards(ctx *context.Context, total int, getter func(opts models.Li
pager := context.NewPagination(total, models.ItemsPerPage, page, 5)
ctx.Data["Page"] = pager
- items, err := getter(models.ListOptions{
+ items, err := getter(db.ListOptions{
Page: pager.Paginater.Current(),
PageSize: models.ItemsPerPage,
})
@@ -801,7 +802,7 @@ func Forks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repos.forks")
// TODO: need pagination
- forks, err := ctx.Repo.Repository.GetForks(models.ListOptions{})
+ forks, err := ctx.Repo.Repository.GetForks(db.ListOptions{})
if err != nil {
ctx.ServerError("GetForks", err)
return
diff --git a/routers/web/user/auth.go b/routers/web/user/auth.go
index 9785ca68d5..733ace81b0 100644
--- a/routers/web/user/auth.go
+++ b/routers/web/user/auth.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/eventsource"
@@ -147,7 +148,7 @@ func SignIn(ctx *context.Context) {
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
ctx.Data["PageIsSignIn"] = true
ctx.Data["PageIsLogin"] = true
- ctx.Data["EnableSSPI"] = models.IsSSPIEnabled()
+ ctx.Data["EnableSSPI"] = login.IsSSPIEnabled()
ctx.HTML(http.StatusOK, tplSignIn)
}
@@ -167,7 +168,7 @@ func SignInPost(ctx *context.Context) {
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
ctx.Data["PageIsSignIn"] = true
ctx.Data["PageIsLogin"] = true
- ctx.Data["EnableSSPI"] = models.IsSSPIEnabled()
+ ctx.Data["EnableSSPI"] = login.IsSSPIEnabled()
if ctx.HasError() {
ctx.HTML(http.StatusOK, tplSignIn)
@@ -573,7 +574,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
func SignInOAuth(ctx *context.Context) {
provider := ctx.Params(":provider")
- loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
+ loginSource, err := login.GetActiveOAuth2LoginSourceByName(provider)
if err != nil {
ctx.ServerError("SignIn", err)
return
@@ -608,7 +609,7 @@ func SignInOAuthCallback(ctx *context.Context) {
provider := ctx.Params(":provider")
// first look if the provider is still active
- loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
+ loginSource, err := login.GetActiveOAuth2LoginSourceByName(provider)
if err != nil {
ctx.ServerError("SignIn", err)
return
@@ -653,7 +654,7 @@ func SignInOAuthCallback(ctx *context.Context) {
FullName: gothUser.Name,
Email: gothUser.Email,
IsActive: !setting.OAuth2Client.RegisterEmailConfirm,
- LoginType: models.LoginOAuth2,
+ LoginType: login.OAuth2,
LoginSource: loginSource.ID,
LoginName: gothUser.UserID,
}
@@ -711,7 +712,7 @@ func updateAvatarIfNeed(url string, u *models.User) {
}
}
-func handleOAuth2SignIn(ctx *context.Context, source *models.LoginSource, u *models.User, gothUser goth.User) {
+func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.User, gothUser goth.User) {
updateAvatarIfNeed(gothUser.AvatarURL, u)
needs2FA := false
@@ -785,7 +786,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *models.LoginSource, u *mod
// OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful
// login the user
-func oAuth2UserLoginCallback(loginSource *models.LoginSource, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) {
+func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) {
gothUser, err := loginSource.Cfg.(*oauth2.Source).Callback(request, response)
if err != nil {
if err.Error() == "securecookie: the value is too long" {
@@ -797,7 +798,7 @@ func oAuth2UserLoginCallback(loginSource *models.LoginSource, request *http.Requ
user := &models.User{
LoginName: gothUser.UserID,
- LoginType: models.LoginOAuth2,
+ LoginType: login.OAuth2,
LoginSource: loginSource.ID,
}
@@ -1068,7 +1069,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
}
}
- loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.Provider)
+ loginSource, err := login.GetActiveOAuth2LoginSourceByName(gothUser.Provider)
if err != nil {
ctx.ServerError("CreateUser", err)
}
@@ -1078,7 +1079,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
Email: form.Email,
Passwd: form.Password,
IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm),
- LoginType: models.LoginOAuth2,
+ LoginType: login.OAuth2,
LoginSource: loginSource.ID,
LoginName: gothUser.UserID,
}
diff --git a/routers/web/user/home.go b/routers/web/user/home.go
index bb75558dc8..2f1fca4527 100644
--- a/routers/web/user/home.go
+++ b/routers/web/user/home.go
@@ -15,6 +15,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
@@ -846,7 +847,7 @@ func repoIDMap(ctxUser *models.User, issueCountByRepo map[int64]int64, unitType
// ShowSSHKeys output all the ssh keys of user by uid
func ShowSSHKeys(ctx *context.Context, uid int64) {
- keys, err := models.ListPublicKeys(uid, models.ListOptions{})
+ keys, err := models.ListPublicKeys(uid, db.ListOptions{})
if err != nil {
ctx.ServerError("ListPublicKeys", err)
return
@@ -862,7 +863,7 @@ func ShowSSHKeys(ctx *context.Context, uid int64) {
// ShowGPGKeys output all the public GPG keys of user by uid
func ShowGPGKeys(ctx *context.Context, uid int64) {
- keys, err := models.ListGPGKeys(uid, models.ListOptions{})
+ keys, err := models.ListGPGKeys(uid, db.ListOptions{})
if err != nil {
ctx.ServerError("ListGPGKeys", err)
return
diff --git a/routers/web/user/oauth.go b/routers/web/user/oauth.go
index cec6a92bbe..d9fc5eeaf9 100644
--- a/routers/web/user/oauth.go
+++ b/routers/web/user/oauth.go
@@ -13,6 +13,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/json"
@@ -115,7 +116,7 @@ type AccessTokenResponse struct {
IDToken string `json:"id_token,omitempty"`
}
-func newAccessTokenResponse(grant *models.OAuth2Grant, serverKey, clientKey oauth2.JWTSigningKey) (*AccessTokenResponse, *AccessTokenError) {
+func newAccessTokenResponse(grant *login.OAuth2Grant, serverKey, clientKey oauth2.JWTSigningKey) (*AccessTokenResponse, *AccessTokenError) {
if setting.OAuth2.InvalidateRefreshTokens {
if err := grant.IncreaseCounter(); err != nil {
return nil, &AccessTokenError{
@@ -162,7 +163,7 @@ func newAccessTokenResponse(grant *models.OAuth2Grant, serverKey, clientKey oaut
// generate OpenID Connect id_token
signedIDToken := ""
if grant.ScopeContains("openid") {
- app, err := models.GetOAuth2ApplicationByID(grant.ApplicationID)
+ app, err := login.GetOAuth2ApplicationByID(grant.ApplicationID)
if err != nil {
return nil, &AccessTokenError{
ErrorCode: AccessTokenErrorCodeInvalidRequest,
@@ -268,9 +269,9 @@ func IntrospectOAuth(ctx *context.Context) {
token, err := oauth2.ParseToken(form.Token, oauth2.DefaultSigningKey)
if err == nil {
if token.Valid() == nil {
- grant, err := models.GetOAuth2GrantByID(token.GrantID)
+ grant, err := login.GetOAuth2GrantByID(token.GrantID)
if err == nil && grant != nil {
- app, err := models.GetOAuth2ApplicationByID(grant.ApplicationID)
+ app, err := login.GetOAuth2ApplicationByID(grant.ApplicationID)
if err == nil && app != nil {
response.Active = true
response.Scope = grant.Scope
@@ -299,9 +300,9 @@ func AuthorizeOAuth(ctx *context.Context) {
return
}
- app, err := models.GetOAuth2ApplicationByClientID(form.ClientID)
+ app, err := login.GetOAuth2ApplicationByClientID(form.ClientID)
if err != nil {
- if models.IsErrOauthClientIDInvalid(err) {
+ if login.IsErrOauthClientIDInvalid(err) {
handleAuthorizeError(ctx, AuthorizeError{
ErrorCode: ErrorCodeUnauthorizedClient,
ErrorDescription: "Client ID not registered",
@@ -312,8 +313,10 @@ func AuthorizeOAuth(ctx *context.Context) {
ctx.ServerError("GetOAuth2ApplicationByClientID", err)
return
}
- if err := app.LoadUser(); err != nil {
- ctx.ServerError("LoadUser", err)
+
+ user, err := models.GetUserByID(app.UID)
+ if err != nil {
+ ctx.ServerError("GetUserByID", err)
return
}
@@ -406,7 +409,7 @@ func AuthorizeOAuth(ctx *context.Context) {
ctx.Data["State"] = form.State
ctx.Data["Scope"] = form.Scope
ctx.Data["Nonce"] = form.Nonce
- ctx.Data["ApplicationUserLink"] = "<a href=\"" + html.EscapeString(setting.AppURL) + html.EscapeString(url.PathEscape(app.User.LowerName)) + "\">@" + html.EscapeString(app.User.Name) + "</a>"
+ ctx.Data["ApplicationUserLink"] = "<a href=\"" + html.EscapeString(setting.AppURL) + html.EscapeString(url.PathEscape(user.LowerName)) + "\">@" + html.EscapeString(user.Name) + "</a>"
ctx.Data["ApplicationRedirectDomainHTML"] = "<strong>" + html.EscapeString(form.RedirectURI) + "</strong>"
// TODO document SESSION <=> FORM
err = ctx.Session.Set("client_id", app.ClientID)
@@ -443,7 +446,7 @@ func GrantApplicationOAuth(ctx *context.Context) {
ctx.Error(http.StatusBadRequest)
return
}
- app, err := models.GetOAuth2ApplicationByClientID(form.ClientID)
+ app, err := login.GetOAuth2ApplicationByClientID(form.ClientID)
if err != nil {
ctx.ServerError("GetOAuth2ApplicationByClientID", err)
return
@@ -581,7 +584,7 @@ func handleRefreshToken(ctx *context.Context, form forms.AccessTokenForm, server
return
}
// get grant before increasing counter
- grant, err := models.GetOAuth2GrantByID(token.GrantID)
+ grant, err := login.GetOAuth2GrantByID(token.GrantID)
if err != nil || grant == nil {
handleAccessTokenError(ctx, AccessTokenError{
ErrorCode: AccessTokenErrorCodeInvalidGrant,
@@ -608,7 +611,7 @@ func handleRefreshToken(ctx *context.Context, form forms.AccessTokenForm, server
}
func handleAuthorizationCode(ctx *context.Context, form forms.AccessTokenForm, serverKey, clientKey oauth2.JWTSigningKey) {
- app, err := models.GetOAuth2ApplicationByClientID(form.ClientID)
+ app, err := login.GetOAuth2ApplicationByClientID(form.ClientID)
if err != nil {
handleAccessTokenError(ctx, AccessTokenError{
ErrorCode: AccessTokenErrorCodeInvalidClient,
@@ -630,7 +633,7 @@ func handleAuthorizationCode(ctx *context.Context, form forms.AccessTokenForm, s
})
return
}
- authorizationCode, err := models.GetOAuth2AuthorizationByCode(form.Code)
+ authorizationCode, err := login.GetOAuth2AuthorizationByCode(form.Code)
if err != nil || authorizationCode == nil {
handleAccessTokenError(ctx, AccessTokenError{
ErrorCode: AccessTokenErrorCodeUnauthorizedClient,
diff --git a/routers/web/user/oauth_test.go b/routers/web/user/oauth_test.go
index 09abf1ee2a..27d339b778 100644
--- a/routers/web/user/oauth_test.go
+++ b/routers/web/user/oauth_test.go
@@ -9,13 +9,14 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/services/auth/source/oauth2"
"github.com/golang-jwt/jwt"
"github.com/stretchr/testify/assert"
)
-func createAndParseToken(t *testing.T, grant *models.OAuth2Grant) *oauth2.OIDCToken {
+func createAndParseToken(t *testing.T, grant *login.OAuth2Grant) *oauth2.OIDCToken {
signingKey, err := oauth2.CreateJWTSigningKey("HS256", make([]byte, 32))
assert.NoError(t, err)
assert.NotNil(t, signingKey)
@@ -42,7 +43,7 @@ func createAndParseToken(t *testing.T, grant *models.OAuth2Grant) *oauth2.OIDCTo
func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
assert.NoError(t, db.PrepareTestDatabase())
- grants, err := models.GetOAuth2GrantsByUserID(3)
+ grants, err := login.GetOAuth2GrantsByUserID(3)
assert.NoError(t, err)
assert.Len(t, grants, 1)
@@ -58,7 +59,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
assert.False(t, oidcToken.EmailVerified)
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
- grants, err = models.GetOAuth2GrantsByUserID(user.ID)
+ grants, err = login.GetOAuth2GrantsByUserID(user.ID)
assert.NoError(t, err)
assert.Len(t, grants, 1)
diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go
index 9ecdc2345c..d64d5621de 100644
--- a/routers/web/user/profile.go
+++ b/routers/web/user/profile.go
@@ -12,6 +12,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
@@ -192,7 +193,7 @@ func Profile(ctx *context.Context) {
ctx.Data["Keyword"] = keyword
switch tab {
case "followers":
- items, err := ctxUser.GetFollowers(models.ListOptions{
+ items, err := ctxUser.GetFollowers(db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Page: page,
})
@@ -204,7 +205,7 @@ func Profile(ctx *context.Context) {
total = ctxUser.NumFollowers
case "following":
- items, err := ctxUser.GetFollowing(models.ListOptions{
+ items, err := ctxUser.GetFollowing(db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Page: page,
})
@@ -229,7 +230,7 @@ func Profile(ctx *context.Context) {
case "stars":
ctx.Data["PageIsProfileStarList"] = true
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
- ListOptions: models.ListOptions{
+ ListOptions: db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Page: page,
},
@@ -260,7 +261,7 @@ func Profile(ctx *context.Context) {
}
case "watching":
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
- ListOptions: models.ListOptions{
+ ListOptions: db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Page: page,
},
@@ -281,7 +282,7 @@ func Profile(ctx *context.Context) {
total = int(count)
default:
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
- ListOptions: models.ListOptions{
+ ListOptions: db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Page: page,
},
diff --git a/routers/web/user/setting/applications.go b/routers/web/user/setting/applications.go
index 5e208afafe..9976337bfa 100644
--- a/routers/web/user/setting/applications.go
+++ b/routers/web/user/setting/applications.go
@@ -9,6 +9,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
@@ -92,12 +93,12 @@ func loadApplicationsData(ctx *context.Context) {
ctx.Data["Tokens"] = tokens
ctx.Data["EnableOAuth2"] = setting.OAuth2.Enable
if setting.OAuth2.Enable {
- ctx.Data["Applications"], err = models.GetOAuth2ApplicationsByUserID(ctx.User.ID)
+ ctx.Data["Applications"], err = login.GetOAuth2ApplicationsByUserID(ctx.User.ID)
if err != nil {
ctx.ServerError("GetOAuth2ApplicationsByUserID", err)
return
}
- ctx.Data["Grants"], err = models.GetOAuth2GrantsByUserID(ctx.User.ID)
+ ctx.Data["Grants"], err = login.GetOAuth2GrantsByUserID(ctx.User.ID)
if err != nil {
ctx.ServerError("GetOAuth2GrantsByUserID", err)
return
diff --git a/routers/web/user/setting/keys.go b/routers/web/user/setting/keys.go
index 24b9a9e205..bb7a50841b 100644
--- a/routers/web/user/setting/keys.go
+++ b/routers/web/user/setting/keys.go
@@ -9,6 +9,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
@@ -233,7 +234,7 @@ func DeleteKey(ctx *context.Context) {
}
func loadKeysData(ctx *context.Context) {
- keys, err := models.ListPublicKeys(ctx.User.ID, models.ListOptions{})
+ keys, err := models.ListPublicKeys(ctx.User.ID, db.ListOptions{})
if err != nil {
ctx.ServerError("ListPublicKeys", err)
return
@@ -247,7 +248,7 @@ func loadKeysData(ctx *context.Context) {
}
ctx.Data["ExternalKeys"] = externalKeys
- gpgkeys, err := models.ListGPGKeys(ctx.User.ID, models.ListOptions{})
+ gpgkeys, err := models.ListGPGKeys(ctx.User.ID, db.ListOptions{})
if err != nil {
ctx.ServerError("ListGPGKeys", err)
return
@@ -258,7 +259,7 @@ func loadKeysData(ctx *context.Context) {
// generate a new aes cipher using the csrfToken
ctx.Data["TokenToSign"] = tokenToSign
- principals, err := models.ListPrincipalKeys(ctx.User.ID, models.ListOptions{})
+ principals, err := models.ListPrincipalKeys(ctx.User.ID, db.ListOptions{})
if err != nil {
ctx.ServerError("ListPrincipalKeys", err)
return
diff --git a/routers/web/user/setting/oauth2.go b/routers/web/user/setting/oauth2.go
index 8de0720b51..0f338ab5d1 100644
--- a/routers/web/user/setting/oauth2.go
+++ b/routers/web/user/setting/oauth2.go
@@ -8,7 +8,7 @@ import (
"fmt"
"net/http"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -34,7 +34,7 @@ func OAuthApplicationsPost(ctx *context.Context) {
return
}
// TODO validate redirect URI
- app, err := models.CreateOAuth2Application(models.CreateOAuth2ApplicationOptions{
+ app, err := login.CreateOAuth2Application(login.CreateOAuth2ApplicationOptions{
Name: form.Name,
RedirectURIs: []string{form.RedirectURI},
UserID: ctx.User.ID,
@@ -67,7 +67,7 @@ func OAuthApplicationsEdit(ctx *context.Context) {
}
// TODO validate redirect URI
var err error
- if ctx.Data["App"], err = models.UpdateOAuth2Application(models.UpdateOAuth2ApplicationOptions{
+ if ctx.Data["App"], err = login.UpdateOAuth2Application(login.UpdateOAuth2ApplicationOptions{
ID: ctx.ParamsInt64("id"),
Name: form.Name,
RedirectURIs: []string{form.RedirectURI},
@@ -85,9 +85,9 @@ func OAuthApplicationsRegenerateSecret(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsApplications"] = true
- app, err := models.GetOAuth2ApplicationByID(ctx.ParamsInt64("id"))
+ app, err := login.GetOAuth2ApplicationByID(ctx.ParamsInt64("id"))
if err != nil {
- if models.IsErrOAuthApplicationNotFound(err) {
+ if login.IsErrOAuthApplicationNotFound(err) {
ctx.NotFound("Application not found", err)
return
}
@@ -110,9 +110,9 @@ func OAuthApplicationsRegenerateSecret(ctx *context.Context) {
// OAuth2ApplicationShow displays the given application
func OAuth2ApplicationShow(ctx *context.Context) {
- app, err := models.GetOAuth2ApplicationByID(ctx.ParamsInt64("id"))
+ app, err := login.GetOAuth2ApplicationByID(ctx.ParamsInt64("id"))
if err != nil {
- if models.IsErrOAuthApplicationNotFound(err) {
+ if login.IsErrOAuthApplicationNotFound(err) {
ctx.NotFound("Application not found", err)
return
}
@@ -129,7 +129,7 @@ func OAuth2ApplicationShow(ctx *context.Context) {
// DeleteOAuth2Application deletes the given oauth2 application
func DeleteOAuth2Application(ctx *context.Context) {
- if err := models.DeleteOAuth2Application(ctx.FormInt64("id"), ctx.User.ID); err != nil {
+ if err := login.DeleteOAuth2Application(ctx.FormInt64("id"), ctx.User.ID); err != nil {
ctx.ServerError("DeleteOAuth2Application", err)
return
}
@@ -147,7 +147,7 @@ func RevokeOAuth2Grant(ctx *context.Context) {
ctx.ServerError("RevokeOAuth2Grant", fmt.Errorf("user id or grant id is zero"))
return
}
- if err := models.RevokeOAuth2Grant(ctx.FormInt64("id"), ctx.User.ID); err != nil {
+ if err := login.RevokeOAuth2Grant(ctx.FormInt64("id"), ctx.User.ID); err != nil {
ctx.ServerError("RevokeOAuth2Grant", err)
return
}
diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go
index bd967af32b..d75149b8fc 100644
--- a/routers/web/user/setting/profile.go
+++ b/routers/web/user/setting/profile.go
@@ -15,6 +15,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -235,7 +236,7 @@ func Repos(ctx *context.Context) {
ctx.Data["allowAdopt"] = ctx.IsUserSiteAdmin() || setting.Repository.AllowAdoptionOfUnadoptedRepositories
ctx.Data["allowDelete"] = ctx.IsUserSiteAdmin() || setting.Repository.AllowDeleteOfUnadoptedRepositories
- opts := models.ListOptions{
+ opts := db.ListOptions{
PageSize: setting.UI.Admin.UserPagingNum,
Page: ctx.FormInt("page"),
}
@@ -284,7 +285,7 @@ func Repos(ctx *context.Context) {
return
}
- if err := ctxUser.GetRepositories(models.ListOptions{Page: 1, PageSize: setting.UI.Admin.UserPagingNum}, repoNames...); err != nil {
+ if err := ctxUser.GetRepositories(db.ListOptions{Page: 1, PageSize: setting.UI.Admin.UserPagingNum}, repoNames...); err != nil {
ctx.ServerError("GetRepositories", err)
return
}
diff --git a/routers/web/user/setting/security.go b/routers/web/user/setting/security.go
index 3406194015..d4abe84d96 100644
--- a/routers/web/user/setting/security.go
+++ b/routers/web/user/setting/security.go
@@ -9,6 +9,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
@@ -87,9 +88,9 @@ func loadSecurityData(ctx *context.Context) {
}
// map the provider display name with the LoginSource
- sources := make(map[*models.LoginSource]string)
+ sources := make(map[*login.Source]string)
for _, externalAccount := range accountLinks {
- if loginSource, err := models.GetLoginSourceByID(externalAccount.LoginSourceID); err == nil {
+ if loginSource, err := login.GetSourceByID(externalAccount.LoginSourceID); err == nil {
var providerDisplayName string
type DisplayNamed interface {