aboutsummaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/commit.go4
-rw-r--r--routers/repo/http.go54
-rw-r--r--routers/repo/issue.go8
-rw-r--r--routers/repo/view.go12
4 files changed, 45 insertions, 33 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index e92ec8c88c..5d354c4b56 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -253,6 +253,9 @@ func Diff(ctx *middleware.Context) {
ctx.Data["Parents"] = parents
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", commitId)
+ if (commit.ParentCount() > 0) {
+ ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", parents[0])
+ }
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitId)
ctx.HTML(200, DIFF)
}
@@ -316,6 +319,7 @@ func CompareDiff(ctx *middleware.Context) {
ctx.Data["Diff"] = diff
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", afterCommitId)
+ ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", beforeCommitId)
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", afterCommitId)
ctx.HTML(200, DIFF)
}
diff --git a/routers/repo/http.go b/routers/repo/http.go
index 4173c7a91f..a209c2b254 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -73,11 +73,14 @@ func Http(ctx *middleware.Context) {
return
}
- // only public pull don't need auth
+ // Only public pull don't need auth.
isPublicPull := !repo.IsPrivate && isPull
- var askAuth = !isPublicPull || setting.Service.RequireSignInView
- var authUser *models.User
- var authUsername, passwd string
+ var (
+ askAuth = !isPublicPull || setting.Service.RequireSignInView
+ authUser *models.User
+ authUsername string
+ authPasswd string
+ )
// check access
if askAuth {
@@ -90,12 +93,13 @@ func Http(ctx *middleware.Context) {
auths := strings.Fields(baHead)
// currently check basic auth
// TODO: support digit auth
- // FIXME: middlewares/context.go did basic auth check already
+ // FIXME: middlewares/context.go did basic auth check already,
+ // maybe could use that one.
if len(auths) != 2 || auths[0] != "Basic" {
ctx.Handle(401, "no basic auth and digit auth", nil)
return
}
- authUsername, passwd, err = base.BasicAuthDecode(auths[1])
+ authUsername, authPasswd, err = base.BasicAuthDecode(auths[1])
if err != nil {
ctx.Handle(401, "no basic auth and digit auth", nil)
return
@@ -103,15 +107,33 @@ func Http(ctx *middleware.Context) {
authUser, err = models.GetUserByName(authUsername)
if err != nil {
- ctx.Handle(401, "no basic auth and digit auth", nil)
- return
- }
+ if err != models.ErrUserNotExist {
+ ctx.Handle(500, "GetUserByName", err)
+ return
+ }
- newUser := &models.User{Passwd: passwd, Salt: authUser.Salt}
- newUser.EncodePasswd()
- if authUser.Passwd != newUser.Passwd {
- ctx.Handle(401, "no basic auth and digit auth", nil)
- return
+ // Assume username now is a token.
+ token, err := models.GetAccessTokenBySha(authUsername)
+ if err != nil {
+ if err == models.ErrAccessTokenNotExist {
+ ctx.Handle(401, "invalid token", nil)
+ } else {
+ ctx.Handle(500, "GetAccessTokenBySha", err)
+ }
+ return
+ }
+ authUser, err = models.GetUserById(token.Uid)
+ if err != nil {
+ ctx.Handle(500, "GetUserById", err)
+ return
+ }
+ authUsername = authUser.Name
+ } else {
+ // Check user's password when username is correctly presented.
+ if !authUser.ValidtePassword(authPasswd) {
+ ctx.Handle(401, "invalid password", nil)
+ return
+ }
}
if !isPublicPull {
@@ -139,9 +161,7 @@ func Http(ctx *middleware.Context) {
}
}
- var f func(rpc string, input []byte)
-
- f = func(rpc string, input []byte) {
+ var f = func(rpc string, input []byte) {
if rpc == "receive-pack" {
var lastLine int64 = 0
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 921348dbd1..bf39d9aba6 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -424,7 +424,7 @@ func ViewIssue(ctx *middleware.Context) {
}
comments[i].Poster = u
- if comments[i].Type == models.COMMENT {
+ if comments[i].Type == models.COMMENT_TYPE_COMMENT {
comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), ctx.Repo.RepoLink))
}
}
@@ -774,9 +774,9 @@ func Comment(ctx *middleware.Context) {
}
}
- cmtType := models.CLOSE
+ cmtType := models.COMMENT_TYPE_CLOSE
if !issue.IsClosed {
- cmtType = models.REOPEN
+ cmtType = models.COMMENT_TYPE_REOPEN
}
if _, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.Id, 0, 0, cmtType, "", nil); err != nil {
@@ -795,7 +795,7 @@ func Comment(ctx *middleware.Context) {
if len(content) > 0 || len(ctx.Req.MultipartForm.File["attachments"]) > 0 {
switch ctx.Params(":action") {
case "new":
- if comment, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.Id, 0, 0, models.COMMENT, content, nil); err != nil {
+ if comment, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.Id, 0, 0, models.COMMENT_TYPE_COMMENT, content, nil); err != nil {
send(500, nil, err)
return
}
diff --git a/routers/repo/view.go b/routers/repo/view.go
index cb689df6a0..cfe0fa010c 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -127,7 +127,6 @@ func Home(ctx *middleware.Context) {
entries.Sort()
files := make([][]interface{}, 0, len(entries))
-
for _, te := range entries {
if te.Type != git.COMMIT {
c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name()))
@@ -151,16 +150,6 @@ func Home(ctx *middleware.Context) {
files = append(files, []interface{}{te, git.NewSubModuleFile(c, sm.Url, te.Id.String())})
}
}
-
- // Render issue index links.
- for _, f := range files {
- switch c := f[1].(type) {
- case *git.Commit:
- c.CommitMessage = c.CommitMessage
- case *git.SubModuleFile:
- c.CommitMessage = c.CommitMessage
- }
- }
ctx.Data["Files"] = files
var readmeFile *git.Blob
@@ -208,7 +197,6 @@ func Home(ctx *middleware.Context) {
}
lastCommit := ctx.Repo.Commit
- lastCommit.CommitMessage = string(base.RenderIssueIndexPattern([]byte(lastCommit.CommitMessage), ctx.Repo.RepoLink))
if len(treePath) > 0 {
c, err := ctx.Repo.Commit.GetCommitOfRelPath(treePath)
if err != nil {