mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-30 23:53:52 +03:00
bug fixed
This commit is contained in:
parent
ec1b801732
commit
50391f434e
2 changed files with 28 additions and 26 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -162,7 +163,7 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv
|
||||||
|
|
||||||
access := Access{
|
access := Access{
|
||||||
UserName: user.Name,
|
UserName: user.Name,
|
||||||
RepoName: repo.Name,
|
RepoName: strings.ToLower(path.Join(user.Name, repo.Name)),
|
||||||
Mode: AU_WRITABLE,
|
Mode: AU_WRITABLE,
|
||||||
}
|
}
|
||||||
if _, err = session.Insert(&access); err != nil {
|
if _, err = session.Insert(&access); err != nil {
|
||||||
|
@ -510,7 +511,6 @@ func NotifyWatchers(act *Action) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
act.Id = 0
|
|
||||||
act.UserId = watches[i].UserId
|
act.UserId = watches[i].UserId
|
||||||
if _, err = orm.InsertOne(act); err != nil {
|
if _, err = orm.InsertOne(act); err != nil {
|
||||||
return errors.New("repo.NotifyWatchers(create action): " + err.Error())
|
return errors.New("repo.NotifyWatchers(create action): " + err.Error())
|
||||||
|
|
46
serve.go
46
serve.go
|
@ -90,13 +90,13 @@ func runServ(k *cli.Context) {
|
||||||
keyId, err := strconv.ParseInt(keys[1], 10, 64)
|
keyId, err := strconv.ParseInt(keys[1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("auth file format error")
|
fmt.Println("auth file format error")
|
||||||
log.Error("auth file format error")
|
log.Error("auth file format error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user, err := models.GetUserByKeyId(keyId)
|
user, err := models.GetUserByKeyId(keyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("You have no right to access")
|
fmt.Println("You have no right to access")
|
||||||
log.Error("You have no right to access")
|
log.Error("SSH visit error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,13 +107,14 @@ func runServ(k *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
verb, args := parseCmd(cmd)
|
verb, args := parseCmd(cmd)
|
||||||
rRepo := strings.Trim(args, "'")
|
repoPath := strings.Trim(args, "'")
|
||||||
rr := strings.SplitN(rRepo, "/", 2)
|
rr := strings.SplitN(repoPath, "/", 2)
|
||||||
if len(rr) != 2 {
|
if len(rr) != 2 {
|
||||||
println("Unavilable repository", args)
|
println("Unavilable repository", args)
|
||||||
log.Error("Unavilable repository %v", args)
|
log.Error("Unavilable repository %v", args)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
repoUserName := rr[0]
|
||||||
repoName := rr[1]
|
repoName := rr[1]
|
||||||
if strings.HasSuffix(repoName, ".git") {
|
if strings.HasSuffix(repoName, ".git") {
|
||||||
repoName = repoName[:len(repoName)-4]
|
repoName = repoName[:len(repoName)-4]
|
||||||
|
@ -122,27 +123,17 @@ func runServ(k *cli.Context) {
|
||||||
isWrite := In(verb, COMMANDS_WRITE)
|
isWrite := In(verb, COMMANDS_WRITE)
|
||||||
isRead := In(verb, COMMANDS_READONLY)
|
isRead := In(verb, COMMANDS_READONLY)
|
||||||
|
|
||||||
/*//repo, err := models.GetRepositoryByName(user.Id, repoName)
|
repoUser, err := models.GetUserByName(repoUserName)
|
||||||
//var isExist bool = true
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrRepoNotExist {
|
fmt.Println("You have no right to access")
|
||||||
//isExist = false
|
log.Error("Get user failed", err)
|
||||||
if isRead {
|
|
||||||
println("Repository", user.Name+"/"+repoName, "is not exist")
|
|
||||||
log.Error("Repository " + user.Name + "/" + repoName + " is not exist")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
println("Get repository error:", err)
|
|
||||||
log.Error("Get repository error: " + err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// access check
|
// access check
|
||||||
switch {
|
switch {
|
||||||
case isWrite:
|
case isWrite:
|
||||||
has, err := models.HasAccess(user.Name, repoName, models.AU_WRITABLE)
|
has, err := models.HasAccess(user.Name, strings.ToLower(path.Join(repoUserName, repoName)), models.AU_WRITABLE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println("Inernel error:", err)
|
println("Inernel error:", err)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
|
@ -150,18 +141,29 @@ func runServ(k *cli.Context) {
|
||||||
}
|
}
|
||||||
if !has {
|
if !has {
|
||||||
println("You have no right to write this repository")
|
println("You have no right to write this repository")
|
||||||
log.Error("You have no right to access this repository")
|
log.Error("User %s has no right to write repository %s", user.Name, repoPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case isRead:
|
case isRead:
|
||||||
has, err := models.HasAccess(user.Name, repoName, models.AU_READABLE)
|
repo, err := models.GetRepositoryByName(repoUser.Id, repoName)
|
||||||
|
if err != nil {
|
||||||
|
println("Get repository error:", err)
|
||||||
|
log.Error("Get repository error: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !repo.IsPrivate {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
has, err := models.HasAccess(user.Name, repoPath, models.AU_READABLE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println("Inernel error")
|
println("Inernel error")
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !has {
|
if !has {
|
||||||
has, err = models.HasAccess(user.Name, repoName, models.AU_WRITABLE)
|
has, err = models.HasAccess(user.Name, repoPath, models.AU_WRITABLE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println("Inernel error")
|
println("Inernel error")
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
|
@ -184,7 +186,7 @@ func runServ(k *cli.Context) {
|
||||||
os.Setenv("userId", strconv.Itoa(int(user.Id)))
|
os.Setenv("userId", strconv.Itoa(int(user.Id)))
|
||||||
os.Setenv("repoName", repoName)
|
os.Setenv("repoName", repoName)
|
||||||
|
|
||||||
gitcmd := exec.Command(verb, rRepo)
|
gitcmd := exec.Command(verb, repoPath)
|
||||||
gitcmd.Dir = base.RepoRootPath
|
gitcmd.Dir = base.RepoRootPath
|
||||||
gitcmd.Stdout = os.Stdout
|
gitcmd.Stdout = os.Stdout
|
||||||
gitcmd.Stdin = os.Stdin
|
gitcmd.Stdin = os.Stdin
|
||||||
|
|
Loading…
Reference in a new issue