aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-03 01:37:49 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-03 01:37:49 -0400
commit7b60756f2c56314af715fa884388a5654bbfb791 (patch)
treeaab291357e23d6010e53dae80a51f66ed3294e20 /models
parente10096ee2e7985cfd73553f52b09994af025cd93 (diff)
downloadgitea-7b60756f2c56314af715fa884388a5654bbfb791.tar.gz
gitea-7b60756f2c56314af715fa884388a5654bbfb791.zip
Fix Collaborators cannot commit
Diffstat (limited to 'models')
-rw-r--r--models/action.go45
-rw-r--r--models/repo.go5
-rw-r--r--models/update.go15
3 files changed, 37 insertions, 28 deletions
diff --git a/models/action.go b/models/action.go
index d9efdc5559..8d8713b8a6 100644
--- a/models/action.go
+++ b/models/action.go
@@ -10,6 +10,7 @@ import (
"time"
"github.com/gogits/git"
+ qlog "github.com/qiniu/log"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
@@ -31,18 +32,19 @@ const (
// 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.
- OpType int // Operations: CREATE DELETE STAR ...
- ActUserId int64 // Action user id.
- ActUserName string // Action user name.
- ActEmail string
- RepoId int64
- RepoName string
- RefName string
- IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
- Content string `xorm:"TEXT"`
- Created time.Time `xorm:"created"`
+ Id int64
+ UserId int64 // Receiver user id.
+ OpType int // Operations: CREATE DELETE STAR ...
+ ActUserId int64 // Action user id.
+ ActUserName string // Action user name.
+ ActEmail string
+ RepoId int64
+ RepoUserName string
+ RepoName string
+ RefName string
+ IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
+ Content string `xorm:"TEXT"`
+ Created time.Time `xorm:"created"`
}
func (a Action) GetOpType() int {
@@ -70,8 +72,8 @@ func (a Action) GetContent() string {
}
// CommitRepoAction adds new action for committing repository.
-func CommitRepoAction(userId int64, userName, actEmail string,
- repoId int64, repoName string, refName string, commit *base.PushCommits) error {
+func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
+ repoId int64, repoUserName, repoName string, refName string, commit *base.PushCommits) error {
// log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName)
opType := OP_COMMIT_REPO
@@ -85,30 +87,31 @@ func CommitRepoAction(userId int64, userName, actEmail string,
bs, err := json.Marshal(commit)
if err != nil {
- log.Error("action.CommitRepoAction(json): %d/%s", userId, repoName)
+ qlog.Error("action.CommitRepoAction(json): %d/%s", repoUserId, repoName)
return err
}
// Change repository bare status and update last updated time.
- repo, err := GetRepositoryByName(userId, repoName)
+ repo, err := GetRepositoryByName(repoUserId, repoName)
if err != nil {
- log.Error("action.CommitRepoAction(GetRepositoryByName): %d/%s", userId, repoName)
+ qlog.Error("action.CommitRepoAction(GetRepositoryByName): %d/%s", repoUserId, repoName)
return err
}
repo.IsBare = false
if err = UpdateRepository(repo); err != nil {
- log.Error("action.CommitRepoAction(UpdateRepository): %d/%s", userId, repoName)
+ qlog.Error("action.CommitRepoAction(UpdateRepository): %d/%s", repoUserId, repoName)
return err
}
if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: actEmail,
- OpType: opType, Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName,
+ OpType: opType, Content: string(bs), RepoId: repoId, RepoUserName: repoUserName,
+ RepoName: repoName, RefName: refName,
IsPrivate: repo.IsPrivate}); err != nil {
- log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName)
+ qlog.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName)
return err
}
- log.Trace("action.CommitRepoAction(end): %d/%s", userId, repoName)
+ qlog.Info("action.CommitRepoAction(end): %d/%s", repoUserId, repoName)
return nil
}
diff --git a/models/repo.go b/models/repo.go
index 35b3fde155..e8baadf6b0 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -379,10 +379,11 @@ func createHookUpdate(hookPath, content string) error {
}
// SetRepoEnvs sets environment variables for command update.
-func SetRepoEnvs(userId int64, userName, repoName string) {
+func SetRepoEnvs(userId int64, userName, repoName, repoUserName string) {
os.Setenv("userId", base.ToStr(userId))
os.Setenv("userName", userName)
os.Setenv("repoName", repoName)
+ os.Setenv("repoUserName", repoUserName)
}
// InitRepository initializes README and .gitignore if needed.
@@ -459,7 +460,7 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
return nil
}
- SetRepoEnvs(user.Id, user.Name, repo.Name)
+ SetRepoEnvs(user.Id, user.Name, repo.Name, user.Name)
// Apply changes and commit.
return initRepoCommit(tmpDir, user.NewGitSig())
diff --git a/models/update.go b/models/update.go
index 648c45f160..8aca15940e 100644
--- a/models/update.go
+++ b/models/update.go
@@ -16,14 +16,14 @@ import (
"github.com/gogits/gogs/modules/base"
)
-func Update(refName, oldCommitId, newCommitId, userName, repoName string, userId int64) {
+func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName string, userId int64) {
isNew := strings.HasPrefix(oldCommitId, "0000000")
if isNew &&
strings.HasPrefix(newCommitId, "0000000") {
qlog.Fatal("old rev and new rev both 000000")
}
- f := RepoPath(userName, repoName)
+ f := RepoPath(repoUserName, repoName)
gitUpdate := exec.Command("git", "update-server-info")
gitUpdate.Dir = f
@@ -59,7 +59,12 @@ func Update(refName, oldCommitId, newCommitId, userName, repoName string, userId
qlog.Fatalf("runUpdate.Commit repoId: %v", err)
}
- repos, err := GetRepositoryByName(userId, repoName)
+ ru, err := GetUserByName(repoUserName)
+ if err != nil {
+ qlog.Fatalf("runUpdate.GetUserByName: %v", err)
+ }
+
+ repos, err := GetRepositoryByName(ru.Id, repoName)
if err != nil {
qlog.Fatalf("runUpdate.GetRepositoryByName userId: %v", err)
}
@@ -83,8 +88,8 @@ func Update(refName, oldCommitId, newCommitId, userName, repoName string, userId
}
//commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
- if err = CommitRepoAction(userId, userName, actEmail,
- repos.Id, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil {
+ if err = CommitRepoAction(userId, ru.Id, userName, actEmail,
+ repos.Id, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil {
qlog.Fatalf("runUpdate.models.CommitRepoAction: %v", err)
}
}