summaryrefslogtreecommitdiffstats
path: root/models/access.go
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2015-02-11 21:58:37 -0500
committerUnknwon <joe2010xtmf@163.com>2015-02-11 21:58:37 -0500
commit7e7160eefd6524013003d1c9668db4d358df5251 (patch)
tree4ca5963cfb5c0dbe8e806942cdf8d6997580a6f0 /models/access.go
parentc5c467a9cd805c7cd0fb93f467e0205ee082cca3 (diff)
downloadgitea-7e7160eefd6524013003d1c9668db4d358df5251.tar.gz
gitea-7e7160eefd6524013003d1c9668db4d358df5251.zip
first pass work on migration #925
Diffstat (limited to 'models/access.go')
-rw-r--r--models/access.go42
1 files changed, 23 insertions, 19 deletions
diff --git a/models/access.go b/models/access.go
index 64bb921409..6df1da29bc 100644
--- a/models/access.go
+++ b/models/access.go
@@ -7,8 +7,6 @@ package models
import (
"strings"
"time"
-
- "github.com/go-xorm/xorm"
)
type AccessType int
@@ -27,35 +25,40 @@ type Access struct {
Created time.Time `xorm:"CREATED"`
}
-// AddAccess adds new access record.
-func AddAccess(access *Access) error {
+func addAccess(e Engine, access *Access) error {
access.UserName = strings.ToLower(access.UserName)
access.RepoName = strings.ToLower(access.RepoName)
- _, err := x.Insert(access)
+ _, err := e.Insert(access)
return err
}
+// AddAccess adds new access record.
+func AddAccess(access *Access) error {
+ return addAccess(x, access)
+}
+
+func updateAccess(e Engine, access *Access) error {
+ if _, err := e.Id(access.Id).Update(access); err != nil {
+ return err
+ }
+ return nil
+}
+
// UpdateAccess updates access information.
func UpdateAccess(access *Access) error {
access.UserName = strings.ToLower(access.UserName)
access.RepoName = strings.ToLower(access.RepoName)
- _, err := x.Id(access.Id).Update(access)
- return err
+ return updateAccess(x, access)
}
-// DeleteAccess deletes access record.
-func DeleteAccess(access *Access) error {
- _, err := x.Delete(access)
+func deleteAccess(e Engine, access *Access) error {
+ _, err := e.Delete(access)
return err
}
-// UpdateAccess updates access information with session for rolling back.
-func UpdateAccessWithSession(sess *xorm.Session, access *Access) error {
- if _, err := sess.Id(access.Id).Update(access); err != nil {
- sess.Rollback()
- return err
- }
- return nil
+// DeleteAccess deletes access record.
+func DeleteAccess(access *Access) error {
+ return deleteAccess(x, access)
}
// HasAccess returns true if someone can read or write to given repository.
@@ -93,9 +96,10 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessType, error) {
if err != nil {
return nil, err
}
- err = repo.GetOwner()
- if err != nil {
+ if err = repo.GetOwner(); err != nil {
return nil, err
+ } else if repo.OwnerId == u.Id {
+ continue
}
repos[repo] = access.Mode
}