summaryrefslogtreecommitdiffstats
path: root/modules/context/repo.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-03-13 17:37:44 -0400
committerUnknwon <u@gogs.io>2016-03-13 17:37:44 -0400
commitdb4da7beecd6a8f65bfa264ba18a8cb12303921f (patch)
treee70f4669159a97ee538f305fce623452191b3ddb /modules/context/repo.go
parentb4f47a762338abe6ce3a6e3d6d0896b8a387228d (diff)
downloadgitea-db4da7beecd6a8f65bfa264ba18a8cb12303921f.tar.gz
gitea-db4da7beecd6a8f65bfa264ba18a8cb12303921f.zip
Add APIContext
Diffstat (limited to 'modules/context/repo.go')
-rw-r--r--modules/context/repo.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 547ed4ed85..a330da5c3f 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -18,6 +18,56 @@ import (
"github.com/gogits/gogs/modules/setting"
)
+type PullRequest struct {
+ BaseRepo *models.Repository
+ Allowed bool
+ SameRepo bool
+ HeadInfo string // [<user>:]<branch>
+}
+
+type Repository struct {
+ AccessMode models.AccessMode
+ IsWatching bool
+ IsViewBranch bool
+ IsViewTag bool
+ IsViewCommit bool
+ Repository *models.Repository
+ Owner *models.User
+ Commit *git.Commit
+ Tag *git.Tag
+ GitRepo *git.Repository
+ BranchName string
+ TagName string
+ TreeName string
+ CommitID string
+ RepoLink string
+ CloneLink models.CloneLink
+ CommitsCount int64
+ Mirror *models.Mirror
+
+ PullRequest *PullRequest
+}
+
+// IsOwner returns true if current user is the owner of repository.
+func (r *Repository) IsOwner() bool {
+ return r.AccessMode >= models.ACCESS_MODE_OWNER
+}
+
+// IsAdmin returns true if current user has admin or higher access of repository.
+func (r *Repository) IsAdmin() bool {
+ return r.AccessMode >= models.ACCESS_MODE_ADMIN
+}
+
+// IsWriter returns true if current user has write or higher access of repository.
+func (r *Repository) IsWriter() bool {
+ return r.AccessMode >= models.ACCESS_MODE_WRITE
+}
+
+// HasAccess returns true if the current user has at least read access for this repository
+func (r *Repository) HasAccess() bool {
+ return r.AccessMode >= models.ACCESS_MODE_READ
+}
+
func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
// Non-fork repository will not return error in this method.
if err := repo.GetBaseRepo(); err != nil {