#1040: dashboard no longer accessible when repo is missing
This commit is contained in:
parent
471b8a18ab
commit
588f3215c6
11 changed files with 51 additions and 15 deletions
|
@ -128,7 +128,7 @@ func runServ(c *cli.Context) {
|
||||||
|
|
||||||
repo, err := models.GetRepositoryByName(repoUser.Id, repoName)
|
repo, err := models.GetRepositoryByName(repoUser.Id, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrRepoNotExist {
|
if models.IsErrRepoNotExist(err) {
|
||||||
if user.Id == repoUser.Id || repoUser.IsOwnedBy(user.Id) {
|
if user.Id == repoUser.Id || repoUser.IsOwnedBy(user.Id) {
|
||||||
fail("Repository does not exist", "Repository does not exist: %s/%s", repoUser.Name, repoName)
|
fail("Repository does not exist", "Repository does not exist: %s/%s", repoUser.Name, repoName)
|
||||||
} else {
|
} else {
|
||||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.5.16.0312 Beta"
|
const APP_VER = "0.5.16.0316 Beta"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -6,6 +6,8 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/modules/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccessMode int
|
type AccessMode int
|
||||||
|
@ -77,6 +79,10 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
|
||||||
for _, access := range accesses {
|
for _, access := range accesses {
|
||||||
repo, err := GetRepositoryById(access.RepoID)
|
repo, err := GetRepositoryById(access.RepoID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if IsErrRepoNotExist(err) {
|
||||||
|
log.Error(4, "%v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = repo.GetOwner(); err != nil {
|
if err = repo.GetOwner(); err != nil {
|
||||||
|
|
31
models/error.go
Normal file
31
models/error.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// __________ .__ __
|
||||||
|
// \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
|
||||||
|
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
|
||||||
|
// | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
|
||||||
|
// |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
|
||||||
|
// \/ \/|__| \/ \/
|
||||||
|
|
||||||
|
type ErrRepoNotExist struct {
|
||||||
|
ID int64
|
||||||
|
UID int64
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsErrRepoNotExist(err error) bool {
|
||||||
|
_, ok := err.(ErrRepoNotExist)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err ErrRepoNotExist) Error() string {
|
||||||
|
return fmt.Sprintf("repository does not exist [id: %d, uid: %d, name: %s]", err.ID, err.UID, err.Name)
|
||||||
|
}
|
|
@ -35,7 +35,6 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrRepoAlreadyExist = errors.New("Repository already exist")
|
ErrRepoAlreadyExist = errors.New("Repository already exist")
|
||||||
ErrRepoNotExist = errors.New("Repository does not exist")
|
|
||||||
ErrRepoFileNotExist = errors.New("Repository file does not exist")
|
ErrRepoFileNotExist = errors.New("Repository file does not exist")
|
||||||
ErrRepoNameIllegal = errors.New("Repository name contains illegal characters")
|
ErrRepoNameIllegal = errors.New("Repository name contains illegal characters")
|
||||||
ErrRepoFileNotLoaded = errors.New("Repository file not loaded")
|
ErrRepoFileNotLoaded = errors.New("Repository file not loaded")
|
||||||
|
@ -758,7 +757,7 @@ func DeleteRepository(uid, repoID int64, userName string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if !has {
|
} else if !has {
|
||||||
return ErrRepoNotExist
|
return ErrRepoNotExist{repoID, uid, ""}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case is a organization.
|
// In case is a organization.
|
||||||
|
@ -875,18 +874,18 @@ func GetRepositoryByName(uid int64, repoName string) (*Repository, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !has {
|
} else if !has {
|
||||||
return nil, ErrRepoNotExist
|
return nil, ErrRepoNotExist{0, uid, repoName}
|
||||||
}
|
}
|
||||||
return repo, err
|
return repo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRepositoryById(e Engine, id int64) (*Repository, error) {
|
func getRepositoryById(e Engine, id int64) (*Repository, error) {
|
||||||
repo := &Repository{}
|
repo := new(Repository)
|
||||||
has, err := e.Id(id).Get(repo)
|
has, err := e.Id(id).Get(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !has {
|
} else if !has {
|
||||||
return nil, ErrRepoNotExist
|
return nil, ErrRepoNotExist{id, 0, ""}
|
||||||
}
|
}
|
||||||
return repo, nil
|
return repo, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ func ApiRepoAssignment() macaron.Handler {
|
||||||
// Get repository.
|
// Get repository.
|
||||||
repo, err := models.GetRepositoryByName(u.Id, repoName)
|
repo, err := models.GetRepositoryByName(u.Id, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrRepoNotExist {
|
if models.IsErrRepoNotExist(err) {
|
||||||
ctx.Error(404)
|
ctx.Error(404)
|
||||||
} else {
|
} else {
|
||||||
ctx.JSON(500, &base.ApiJsonErr{"GetRepositoryByName: " + err.Error(), base.DOC_URL})
|
ctx.JSON(500, &base.ApiJsonErr{"GetRepositoryByName: " + err.Error(), base.DOC_URL})
|
||||||
|
@ -223,7 +223,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
|
||||||
// Get repository.
|
// Get repository.
|
||||||
repo, err := models.GetRepositoryByName(u.Id, repoName)
|
repo, err := models.GetRepositoryByName(u.Id, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrRepoNotExist {
|
if models.IsErrRepoNotExist(err) {
|
||||||
ctx.Handle(404, "GetRepositoryByName", err)
|
ctx.Handle(404, "GetRepositoryByName", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "GetRepositoryByName", err)
|
ctx.Handle(500, "GetRepositoryByName", err)
|
||||||
|
|
|
@ -124,7 +124,7 @@ func TeamsRepoAction(ctx *middleware.Context) {
|
||||||
var repo *models.Repository
|
var repo *models.Repository
|
||||||
repo, err = models.GetRepositoryByName(ctx.Org.Organization.Id, repoName)
|
repo, err = models.GetRepositoryByName(ctx.Org.Organization.Id, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrRepoNotExist {
|
if models.IsErrRepoNotExist(err) {
|
||||||
ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo"))
|
ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo"))
|
||||||
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
|
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
|
||||||
return
|
return
|
||||||
|
|
|
@ -65,7 +65,7 @@ func Http(ctx *middleware.Context) {
|
||||||
|
|
||||||
repo, err := models.GetRepositoryByName(repoUser.Id, reponame)
|
repo, err := models.GetRepositoryByName(repoUser.Id, reponame)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrRepoNotExist {
|
if models.IsErrRepoNotExist(err) {
|
||||||
ctx.Handle(404, "GetRepositoryByName", nil)
|
ctx.Handle(404, "GetRepositoryByName", nil)
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "GetRepositoryByName", err)
|
ctx.Handle(500, "GetRepositoryByName", err)
|
||||||
|
|
|
@ -251,7 +251,7 @@ func Fork(ctx *middleware.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("new_fork")
|
ctx.Data["Title"] = ctx.Tr("new_fork")
|
||||||
|
|
||||||
if _, err := getForkRepository(ctx); err != nil {
|
if _, err := getForkRepository(ctx); err != nil {
|
||||||
if err == models.ErrRepoNotExist {
|
if models.IsErrRepoNotExist(err) {
|
||||||
ctx.Redirect(setting.AppSubUrl + "/")
|
ctx.Redirect(setting.AppSubUrl + "/")
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "getForkRepository", err)
|
ctx.Handle(500, "getForkRepository", err)
|
||||||
|
@ -275,7 +275,7 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) {
|
||||||
|
|
||||||
forkRepo, err := getForkRepository(ctx)
|
forkRepo, err := getForkRepository(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrRepoNotExist {
|
if models.IsErrRepoNotExist(err) {
|
||||||
ctx.Redirect(setting.AppSubUrl + "/")
|
ctx.Redirect(setting.AppSubUrl + "/")
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "getForkRepository", err)
|
ctx.Handle(500, "getForkRepository", err)
|
||||||
|
|
|
@ -354,7 +354,7 @@ func Issues(ctx *middleware.Context) {
|
||||||
|
|
||||||
issues[i].Repo, err = models.GetRepositoryById(issues[i].RepoId)
|
issues[i].Repo, err = models.GetRepositoryById(issues[i].RepoId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrRepoNotExist {
|
if models.IsErrRepoNotExist(err) {
|
||||||
log.Warn("user.Issues(GetRepositoryById #%d): repository not exist", issues[i].RepoId)
|
log.Warn("user.Issues(GetRepositoryById #%d): repository not exist", issues[i].RepoId)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.5.16.0312 Beta
|
0.5.16.0316 Beta
|
Reference in a new issue