aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/serve.go
diff options
context:
space:
mode:
authorPeter Smit <peter@smitmail.eu>2015-02-05 15:29:08 +0200
committerPeter Smit <peter@smitmail.eu>2015-02-12 14:14:45 +0200
commit0a4cda0dd4d7c906668d9d2e283fbe9ebe2e1608 (patch)
tree7068350836e187523f0bcf741695c84c0eab42a9 /cmd/serve.go
parent2804784df93f392ed76a85d8e7153c66964f1ba5 (diff)
downloadgitea-0a4cda0dd4d7c906668d9d2e283fbe9ebe2e1608.tar.gz
gitea-0a4cda0dd4d7c906668d9d2e283fbe9ebe2e1608.zip
Refactoring of the Access Table
This commit does a lot of the work of refactoring the access table in a table with id's instead of strings. The result does compile, but has not been tested. It may eat your kittens.
Diffstat (limited to 'cmd/serve.go')
-rw-r--r--cmd/serve.go41
1 files changed, 20 insertions, 21 deletions
diff --git a/cmd/serve.go b/cmd/serve.go
index e957d45de7..62e5d14374 100644
--- a/cmd/serve.go
+++ b/cmd/serve.go
@@ -8,7 +8,6 @@ import (
"fmt"
"os"
"os/exec"
- "path"
"path/filepath"
"strings"
"time"
@@ -67,19 +66,19 @@ func parseCmd(cmd string) (string, string) {
}
var (
- COMMANDS_READONLY = map[string]models.AccessType{
- "git-upload-pack": models.WRITABLE,
- "git upload-pack": models.WRITABLE,
- "git-upload-archive": models.WRITABLE,
+ COMMANDS_READONLY = map[string]models.AccessMode{
+ "git-upload-pack": models.WriteAccess,
+ "git upload-pack": models.WriteAccess,
+ "git-upload-archive": models.WriteAccess,
}
- COMMANDS_WRITE = map[string]models.AccessType{
- "git-receive-pack": models.READABLE,
- "git receive-pack": models.READABLE,
+ COMMANDS_WRITE = map[string]models.AccessMode{
+ "git-receive-pack": models.ReadAccess,
+ "git receive-pack": models.ReadAccess,
}
)
-func In(b string, sl map[string]models.AccessType) bool {
+func In(b string, sl map[string]models.AccessMode) bool {
_, e := sl[b]
return e
}
@@ -144,9 +143,19 @@ func runServ(k *cli.Context) {
}
// Access check.
+ repo, err := models.GetRepositoryByName(repoUser.Id, repoName)
+ if err != nil {
+ if err == models.ErrRepoNotExist {
+ println("Gogs: given repository does not exist")
+ log.GitLogger.Fatal(2, "Repository does not exist: %s/%s", repoUser.Name, repoName)
+ }
+ println("Gogs: internal error:", err.Error())
+ log.GitLogger.Fatal(2, "Fail to get repository: %v", err)
+ }
+
switch {
case isWrite:
- has, err := models.HasAccess(user.Name, path.Join(repoUserName, repoName), models.WRITABLE)
+ has, err := models.HasAccess(user, repo, models.WriteAccess)
if err != nil {
println("Gogs: internal error:", err.Error())
log.GitLogger.Fatal(2, "Fail to check write access:", err)
@@ -155,21 +164,11 @@ func runServ(k *cli.Context) {
log.GitLogger.Fatal(2, "User %s has no right to write repository %s", user.Name, repoPath)
}
case isRead:
- repo, err := models.GetRepositoryByName(repoUser.Id, repoName)
- if err != nil {
- if err == models.ErrRepoNotExist {
- println("Gogs: given repository does not exist")
- log.GitLogger.Fatal(2, "Repository does not exist: %s/%s", repoUser.Name, repoName)
- }
- println("Gogs: internal error:", err.Error())
- log.GitLogger.Fatal(2, "Fail to get repository: %v", err)
- }
-
if !repo.IsPrivate {
break
}
- has, err := models.HasAccess(user.Name, path.Join(repoUserName, repoName), models.READABLE)
+ has, err := models.HasAccess(user, repo, models.ReadAccess)
if err != nil {
println("Gogs: internal error:", err.Error())
log.GitLogger.Fatal(2, "Fail to check read access:", err)