diff options
Diffstat (limited to 'modules/context')
-rw-r--r-- | modules/context/context.go | 11 | ||||
-rw-r--r-- | modules/context/repo.go | 13 |
2 files changed, 15 insertions, 9 deletions
diff --git a/modules/context/context.go b/modules/context/context.go index 971d075d..ac46bb38 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -105,13 +105,12 @@ func (ctx *Context) Handle(status int, title string, err error) { ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) } -// HandleError use error check function to determine if server should -// response as client input error or server internal error. -// It responses with given status code for client error, -// or error context description for logging purpose of server error. -func (ctx *Context) HandleError(title string, errck func(error) bool, err error, status int) { +// NotFoundOrServerError use error check function to determine if the error +// is about not found. It responses with 404 status code for not found error, +// or error context description for logging purpose of 500 server error. +func (ctx *Context) NotFoundOrServerError(title string, errck func(error) bool, err error) { if errck(err) { - ctx.Error(status, err.Error()) + ctx.Handle(404, title, err) return } diff --git a/modules/context/repo.go b/modules/context/repo.go index f5f26b1e..d72e64e4 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -48,7 +48,7 @@ type Repository struct { CommitsCount int64 Mirror *models.Mirror - PullRequest *PullRequest + PullRequest *PullRequest } // IsOwner returns true if current user is the owner of repository. @@ -71,6 +71,11 @@ func (r *Repository) HasAccess() bool { return r.AccessMode >= models.ACCESS_MODE_READ } +// CanEnableEditor returns true if repository is editable and user has proper access level. +func (r *Repository) CanEnableEditor() bool { + return r.Repository.CanEnableEditor() && r.IsViewBranch && r.IsWriter() +} + // GetEditorconfig returns the .editorconfig definition if found in the // HEAD of the default repo branch. func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) { @@ -167,6 +172,7 @@ func RepoAssignment(args ...bool) macaron.Handler { } } ctx.Repo.Owner = owner + ctx.Data["Username"] = ctx.Repo.Owner.Name // Get repository. repo, err := models.GetRepositoryByName(owner.ID, repoName) @@ -221,6 +227,7 @@ func RepoAssignment(args ...bool) macaron.Handler { } ctx.Repo.Repository = repo + ctx.Data["RepoName"] = ctx.Repo.Repository.Name ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName)) @@ -348,12 +355,11 @@ func RepoRef() macaron.Handler { // For API calls. if ctx.Repo.GitRepo == nil { repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) - gitRepo, err := git.OpenRepository(repoPath) + ctx.Repo.GitRepo, err = git.OpenRepository(repoPath) if err != nil { ctx.Handle(500, "RepoRef Invalid repo "+repoPath, err) return } - ctx.Repo.GitRepo = gitRepo } // Get default branch. @@ -431,6 +437,7 @@ func RepoRef() macaron.Handler { ctx.Repo.BranchName = refName ctx.Data["BranchName"] = ctx.Repo.BranchName ctx.Data["CommitID"] = ctx.Repo.CommitID + ctx.Data["TreePath"] = ctx.Repo.TreePath ctx.Data["IsViewBranch"] = ctx.Repo.IsViewBranch ctx.Data["IsViewTag"] = ctx.Repo.IsViewTag ctx.Data["IsViewCommit"] = ctx.Repo.IsViewCommit |