Move repository model into models/repo (#17933)
* Some refactors related repository model * Move more methods out of repository * Move repository into models/repo * Fix test * Fix test * some improvements * Remove unnecessary function
This commit is contained in:
parent
fb8166c6c6
commit
719bddcd76
301 changed files with 3193 additions and 2919 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
|
@ -19,7 +20,7 @@ import (
|
|||
api "code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
|
||||
func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *models.LFSLock, err error) {
|
||||
func handleLockListOut(ctx *context.Context, repo *repo_model.Repository, lock *models.LFSLock, err error) {
|
||||
if err != nil {
|
||||
if models.IsErrLFSLockNotExist(err) {
|
||||
ctx.JSON(http.StatusOK, api.LFSLockList{
|
||||
|
@ -47,7 +48,7 @@ func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *mode
|
|||
func GetListLockHandler(ctx *context.Context) {
|
||||
rv := getRequestContext(ctx)
|
||||
|
||||
repository, err := models.GetRepositoryByOwnerAndName(rv.User, rv.Repo)
|
||||
repository, err := repo_model.GetRepositoryByOwnerAndName(rv.User, rv.Repo)
|
||||
if err != nil {
|
||||
log.Debug("Could not find repository: %s/%s - %s", rv.User, rv.Repo, err)
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
|
@ -134,7 +135,7 @@ func PostLockHandler(ctx *context.Context) {
|
|||
repoName := strings.TrimSuffix(ctx.Params("reponame"), ".git")
|
||||
authorization := ctx.Req.Header.Get("Authorization")
|
||||
|
||||
repository, err := models.GetRepositoryByOwnerAndName(userName, repoName)
|
||||
repository, err := repo_model.GetRepositoryByOwnerAndName(userName, repoName)
|
||||
if err != nil {
|
||||
log.Error("Unable to get repository: %s/%s Error: %v", userName, repoName, err)
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
|
@ -167,8 +168,7 @@ func PostLockHandler(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
lock, err := models.CreateLFSLock(&models.LFSLock{
|
||||
Repo: repository,
|
||||
lock, err := models.CreateLFSLock(repository, &models.LFSLock{
|
||||
Path: req.Path,
|
||||
OwnerID: ctx.User.ID,
|
||||
})
|
||||
|
@ -202,7 +202,7 @@ func VerifyLockHandler(ctx *context.Context) {
|
|||
repoName := strings.TrimSuffix(ctx.Params("reponame"), ".git")
|
||||
authorization := ctx.Req.Header.Get("Authorization")
|
||||
|
||||
repository, err := models.GetRepositoryByOwnerAndName(userName, repoName)
|
||||
repository, err := repo_model.GetRepositoryByOwnerAndName(userName, repoName)
|
||||
if err != nil {
|
||||
log.Error("Unable to get repository: %s/%s Error: %v", userName, repoName, err)
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
|
@ -268,7 +268,7 @@ func UnLockHandler(ctx *context.Context) {
|
|||
repoName := strings.TrimSuffix(ctx.Params("reponame"), ".git")
|
||||
authorization := ctx.Req.Header.Get("Authorization")
|
||||
|
||||
repository, err := models.GetRepositoryByOwnerAndName(userName, repoName)
|
||||
repository, err := repo_model.GetRepositoryByOwnerAndName(userName, repoName)
|
||||
if err != nil {
|
||||
log.Error("Unable to get repository: %s/%s Error: %v", userName, repoName, err)
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
|
@ -301,7 +301,7 @@ func UnLockHandler(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
lock, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.User, req.Force)
|
||||
lock, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), repository, ctx.User, req.Force)
|
||||
if err != nil {
|
||||
if models.IsErrLFSUnauthorizedAction(err) {
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
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/context"
|
||||
|
@ -195,7 +196,7 @@ func BatchHandler(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
meta, err := repository.GetLFSMetaObjectByOid(p.Oid)
|
||||
meta, err := models.GetLFSMetaObjectByOid(repository.ID, p.Oid)
|
||||
if err != nil && err != models.ErrLFSObjectNotExist {
|
||||
log.Error("Unable to get LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err)
|
||||
writeStatus(ctx, http.StatusInternalServerError)
|
||||
|
@ -333,7 +334,7 @@ func UploadHandler(ctx *context.Context) {
|
|||
} else {
|
||||
writeStatus(ctx, http.StatusInternalServerError)
|
||||
}
|
||||
if _, err = repository.RemoveLFSMetaObjectByOid(p.Oid); err != nil {
|
||||
if _, err = models.RemoveLFSMetaObjectByOid(repository.ID, p.Oid); err != nil {
|
||||
log.Error("Error whilst removing metaobject for LFS OID[%s]: %v", p.Oid, err)
|
||||
}
|
||||
return
|
||||
|
@ -396,7 +397,7 @@ func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module
|
|||
return nil
|
||||
}
|
||||
|
||||
meta, err := repository.GetLFSMetaObjectByOid(p.Oid)
|
||||
meta, err := models.GetLFSMetaObjectByOid(repository.ID, p.Oid)
|
||||
if err != nil {
|
||||
log.Error("Unable to get LFS OID[%s] Error: %v", p.Oid, err)
|
||||
writeStatus(ctx, http.StatusNotFound)
|
||||
|
@ -406,8 +407,8 @@ func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module
|
|||
return meta
|
||||
}
|
||||
|
||||
func getAuthenticatedRepository(ctx *context.Context, rc *requestContext, requireWrite bool) *models.Repository {
|
||||
repository, err := models.GetRepositoryByOwnerAndName(rc.User, rc.Repo)
|
||||
func getAuthenticatedRepository(ctx *context.Context, rc *requestContext, requireWrite bool) *repo_model.Repository {
|
||||
repository, err := repo_model.GetRepositoryByOwnerAndName(rc.User, rc.Repo)
|
||||
if err != nil {
|
||||
log.Error("Unable to get repository: %s/%s Error: %v", rc.User, rc.Repo, err)
|
||||
writeStatus(ctx, http.StatusNotFound)
|
||||
|
@ -480,7 +481,7 @@ func writeStatusMessage(ctx *context.Context, status int, message string) {
|
|||
|
||||
// authenticate uses the authorization string to determine whether
|
||||
// or not to proceed. This server assumes an HTTP Basic auth format.
|
||||
func authenticate(ctx *context.Context, repository *models.Repository, authorization string, requireSigned, requireWrite bool) bool {
|
||||
func authenticate(ctx *context.Context, repository *repo_model.Repository, authorization string, requireSigned, requireWrite bool) bool {
|
||||
accessMode := perm.AccessModeRead
|
||||
if requireWrite {
|
||||
accessMode = perm.AccessModeWrite
|
||||
|
@ -508,7 +509,7 @@ func authenticate(ctx *context.Context, repository *models.Repository, authoriza
|
|||
return true
|
||||
}
|
||||
|
||||
func handleLFSToken(tokenSHA string, target *models.Repository, mode perm.AccessMode) (*user_model.User, error) {
|
||||
func handleLFSToken(tokenSHA string, target *repo_model.Repository, mode perm.AccessMode) (*user_model.User, error) {
|
||||
if !strings.Contains(tokenSHA, ".") {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -543,7 +544,7 @@ func handleLFSToken(tokenSHA string, target *models.Repository, mode perm.Access
|
|||
return u, nil
|
||||
}
|
||||
|
||||
func parseToken(authorization string, target *models.Repository, mode perm.AccessMode) (*user_model.User, error) {
|
||||
func parseToken(authorization string, target *repo_model.Repository, mode perm.AccessMode) (*user_model.User, error) {
|
||||
if authorization == "" {
|
||||
return nil, fmt.Errorf("no token")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue