diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/access.go | 4 | ||||
-rw-r--r-- | models/action.go | 10 | ||||
-rw-r--r-- | models/repo.go | 21 |
3 files changed, 14 insertions, 21 deletions
diff --git a/models/access.go b/models/access.go index 36d9405f52..84cad17a3f 100644 --- a/models/access.go +++ b/models/access.go @@ -15,7 +15,7 @@ const ( AU_WRITABLE ) -// Access represents the accessibility of user and repository. +// Access represents the accessibility of user to repository. type Access struct { Id int64 UserName string `xorm:"unique(s)"` @@ -30,7 +30,7 @@ func AddAccess(access *Access) error { return err } -// HasAccess returns true if someone can read or write given repository. +// HasAccess returns true if someone can read or write to given repository. func HasAccess(userName, repoName string, mode int) (bool, error) { return orm.Get(&Access{ Id: 0, diff --git a/models/action.go b/models/action.go index edf1bf58f9..46704eef07 100644 --- a/models/action.go +++ b/models/action.go @@ -23,7 +23,8 @@ const ( OP_PULL_REQUEST ) -// Action represents user operation type and information to the repository. +// Action represents user operation type and other information to repository., +// it implemented interface base.Actioner so that can be used in template render. type Action struct { Id int64 UserId int64 // Receiver user id. @@ -57,7 +58,7 @@ func (a Action) GetContent() string { return a.Content } -// CommitRepoAction records action for commit repository. +// CommitRepoAction adds new action for committing repository. func CommitRepoAction(userId int64, userName string, repoId int64, repoName string, refName string, commits *base.PushCommits) error { log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName) @@ -68,12 +69,13 @@ func CommitRepoAction(userId int64, userName string, return err } - if err = NotifyWatchers(userId, repoId, OP_COMMIT_REPO, userName, repoName, refName, string(bs)); err != nil { + if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, OpType: OP_COMMIT_REPO, + Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName}); err != nil { log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName) return err } - // Update repository last update time. + // Change repository bare status and update last updated time. repo, err := GetRepositoryByName(userId, repoName) if err != nil { log.Error("action.CommitRepoAction(GetRepositoryByName): %d/%s", userId, repoName) diff --git a/models/repo.go b/models/repo.go index e74643577a..1f638fe14f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -485,30 +485,21 @@ func GetWatches(repoId int64) ([]Watch, error) { } // NotifyWatchers creates batch of actions for every watcher. -func NotifyWatchers(userId, repoId int64, opType int, userName, repoName, refName, content string) error { +func NotifyWatchers(act *Action) error { // Add feeds for user self and all watchers. - watches, err := GetWatches(repoId) + watches, err := GetWatches(act.RepoId) if err != nil { return errors.New("repo.NotifyWatchers(get watches): " + err.Error()) } - watches = append(watches, Watch{UserId: userId}) + watches = append(watches, Watch{UserId: act.ActUserId}) for i := range watches { - if userId == watches[i].UserId && i > 0 { + if act.ActUserId == watches[i].UserId && i > 0 { continue // Do not add twice in case author watches his/her repository. } - _, err = orm.InsertOne(&Action{ - UserId: watches[i].UserId, - ActUserId: userId, - ActUserName: userName, - OpType: opType, - Content: content, - RepoId: repoId, - RepoName: repoName, - RefName: refName, - }) - if err != nil { + act.UserId = watches[i].UserId + if _, err = orm.InsertOne(act); err != nil { return errors.New("repo.NotifyWatchers(create action): " + err.Error()) } } |