aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/issue.go12
-rw-r--r--models/repo.go4
-rw-r--r--models/user.go19
3 files changed, 33 insertions, 2 deletions
diff --git a/models/issue.go b/models/issue.go
index 174e3102..7f16f936 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -1231,6 +1231,15 @@ const (
COMMENT_TYPE_PULL_REF
)
+type CommentTag int
+
+const (
+ COMMENT_TAG_NONE CommentTag = iota
+ COMMENT_TAG_POSTER
+ COMMENT_TAG_ADMIN
+ COMMENT_TAG_OWNER
+)
+
// Comment represents a comment in commit and issue page.
type Comment struct {
ID int64 `xorm:"pk autoincr"`
@@ -1245,6 +1254,9 @@ type Comment struct {
Created time.Time `xorm:"CREATED"`
Attachments []*Attachment `xorm:"-"`
+
+ // For view issue page.
+ ShowTag CommentTag `xorm:"-"`
}
// HashTag returns unique hash tag for comment.
diff --git a/models/repo.go b/models/repo.go
index 8ae3cfe6..73ae6b54 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -247,8 +247,8 @@ func (repo *Repository) HasAccess(u *User) bool {
return has
}
-func (repo *Repository) IsOwnedBy(u *User) bool {
- return repo.OwnerID == u.Id
+func (repo *Repository) IsOwnedBy(userID int64) bool {
+ return repo.OwnerID == userID
}
// DescriptionHtml does special handles to description and return HTML string.
diff --git a/models/user.go b/models/user.go
index a58bb634..f2151a70 100644
--- a/models/user.go
+++ b/models/user.go
@@ -222,6 +222,25 @@ func (u *User) UploadAvatar(data []byte) error {
return sess.Commit()
}
+// IsAdminOfRepo returns true if user has admin or higher access of repository.
+func (u *User) IsAdminOfRepo(repo *Repository) bool {
+ if err := repo.GetOwner(); err != nil {
+ log.Error(3, "GetOwner: %v", err)
+ return false
+ }
+
+ if repo.Owner.IsOrganization() {
+ has, err := HasAccess(u, repo, ACCESS_MODE_ADMIN)
+ if err != nil {
+ log.Error(3, "HasAccess: %v", err)
+ return false
+ }
+ return has
+ }
+
+ return repo.IsOwnedBy(u.Id)
+}
+
// IsOrganization returns true if user is actually a organization.
func (u *User) IsOrganization() bool {
return u.Type == ORGANIZATION