From 61e29226015fad6451281035948c3d8d1364880c Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Mar 2014 13:50:50 -0400 Subject: Working on issues --- routers/repo/issue.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 routers/repo/issue.go (limited to 'routers/repo/issue.go') diff --git a/routers/repo/issue.go b/routers/repo/issue.go new file mode 100644 index 00000000..c6af8ca0 --- /dev/null +++ b/routers/repo/issue.go @@ -0,0 +1,30 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package repo + +import ( + "github.com/codegangsta/martini" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware" +) + +func Issues(ctx *middleware.Context, params martini.Params) { + ctx.Data["IsRepoToolbarIssues"] = true + + milestoneId, _ := base.StrTo(params["milestone"]).Int() + page, _ := base.StrTo(params["page"]).Int() + + var err error + ctx.Data["Issues"], err = models.GetIssues(0, ctx.Repo.Repository.Id, 0, + int64(milestoneId), page, params["state"] == "closed", false, params["labels"], params["sortType"]) + if err != nil { + ctx.Handle(200, "issue.Issues: %v", err) + return + } + + ctx.HTML(200, "repo/issues") +} -- cgit v1.2.3 From b3cfd9fe0c293ba9d84d38ec140db2c01b1e3109 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Mar 2014 14:27:03 -0400 Subject: Fix SSH key bug in windows --- models/publickey.go | 45 ++++++++++++++++++++++++++----------------- models/repo.go | 2 +- models/user.go | 2 +- modules/middleware/auth.go | 1 + modules/middleware/context.go | 4 ---- routers/repo/issue.go | 10 ++++++++++ 6 files changed, 40 insertions(+), 24 deletions(-) (limited to 'routers/repo/issue.go') diff --git a/models/publickey.go b/models/publickey.go index c69bca68..9e7cc6f7 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -19,6 +19,8 @@ import ( "time" "github.com/Unknwon/com" + + "github.com/gogits/gogs/modules/log" ) const ( @@ -99,8 +101,8 @@ func AddPublicKey(key *PublicKey) (err error) { } // Calculate fingerprint. - tmpPath := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()), - "id_rsa.pub") + tmpPath := strings.Replace(filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()), + "id_rsa.pub"), "\\", "/", -1) os.MkdirAll(path.Dir(tmpPath), os.ModePerm) if err = ioutil.WriteFile(tmpPath, []byte(key.Content), os.ModePerm); err != nil { return err @@ -127,25 +129,11 @@ func AddPublicKey(key *PublicKey) (err error) { return nil } -// DeletePublicKey deletes SSH key information both in database and authorized_keys file. -func DeletePublicKey(key *PublicKey) (err error) { - // Delete SSH key in database. - has, err := orm.Id(key.Id).Get(key) - if err != nil { - return err - } else if !has { - return errors.New("Public key does not exist") - } - if _, err = orm.Delete(key); err != nil { - return err - } - +func rewriteAuthorizedKeys(key *PublicKey, p, tmpP string) error { // Delete SSH key in SSH key file. sshOpLocker.Lock() defer sshOpLocker.Unlock() - p := filepath.Join(sshPath, "authorized_keys") - tmpP := filepath.Join(sshPath, "authorized_keys.tmp") fr, err := os.Open(p) if err != nil { return err @@ -188,8 +176,29 @@ func DeletePublicKey(key *PublicKey) (err error) { break } } + return nil +} - if err = os.Remove(p); err != nil { +// DeletePublicKey deletes SSH key information both in database and authorized_keys file. +func DeletePublicKey(key *PublicKey) (err error) { + // Delete SSH key in database. + has, err := orm.Id(key.Id).Get(key) + if err != nil { + return err + } else if !has { + return errors.New("Public key does not exist") + } + if _, err = orm.Delete(key); err != nil { + return err + } + + p := filepath.Join(sshPath, "authorized_keys") + tmpP := filepath.Join(sshPath, "authorized_keys.tmp") + log.Trace("ssh.DeletePublicKey(authorized_keys): %s", p) + + if err = rewriteAuthorizedKeys(key, p, tmpP); err != nil { + return err + } else if err = os.Remove(p); err != nil { return err } return os.Rename(tmpP, p) diff --git a/models/repo.go b/models/repo.go index fb115de5..317f936e 100644 --- a/models/repo.go +++ b/models/repo.go @@ -372,7 +372,7 @@ func RepoPath(userName, repoName string) string { } func UpdateRepository(repo *Repository) error { - _, err := orm.Id(repo.Id).UseBool().Update(repo) + _, err := orm.Id(repo.Id).UseBool().Cols("description", "website").Update(repo) return err } diff --git a/models/user.go b/models/user.go index d6dc0414..88c29ae4 100644 --- a/models/user.go +++ b/models/user.go @@ -201,7 +201,7 @@ func VerifyUserActiveCode(code string) (user *User) { // UpdateUser updates user's information. func UpdateUser(user *User) (err error) { - _, err = orm.Id(user.Id).UseBool().Update(user) + _, err = orm.Id(user.Id).UseBool().Cols("website", "location").Update(user) return err } diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index b557188e..3224b3df 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -49,6 +49,7 @@ func Toggle(options *ToggleOptions) martini.Handler { ctx.Error(403) return } + ctx.Data["PageIsAdmin"] = true } } } diff --git a/modules/middleware/context.go b/modules/middleware/context.go index b28953fc..5727b4f0 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -216,10 +216,6 @@ func InitContext() martini.Handler { ctx.Data["SignedUserId"] = user.Id ctx.Data["SignedUserName"] = user.LowerName ctx.Data["IsAdmin"] = ctx.User.IsAdmin - - if ctx.User.IsAdmin { - ctx.Data["PageIsAdmin"] = true - } } // get or create csrf token diff --git a/routers/repo/issue.go b/routers/repo/issue.go index c6af8ca0..eee55c6f 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -28,3 +28,13 @@ func Issues(ctx *middleware.Context, params martini.Params) { ctx.HTML(200, "repo/issues") } + +func CreateIssue(ctx *middleware.Context, params martini.Params) { + if !ctx.Repo.IsOwner { + ctx.Error(404) + return + } + // else if err = models.CreateIssue(userId, repoId, milestoneId, assigneeId, name, labels, mentions, content, isPull); err != nil { + + // } +} -- cgit v1.2.3 From 59ffdbf6f80328f9b9074930444dedd936aeae51 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Mar 2014 16:00:46 -0400 Subject: Add create, list, view issue --- README.md | 2 +- models/action.go | 2 +- models/issue.go | 46 +++++++++++++++++----- models/publickey.go | 2 +- models/repo.go | 7 ++++ models/user.go | 7 ++++ modules/auth/issue.go | 54 +++++++++++++++++++++++++ routers/repo/issue.go | 51 ++++++++++++++++++++++-- routers/repo/repo.go | 5 +++ templates/admin/repos.tmpl | 2 +- web.go | 98 ++++++++++++++++++++++++++++------------------ 11 files changed, 221 insertions(+), 55 deletions(-) create mode 100644 modules/auth/issue.go (limited to 'routers/repo/issue.go') diff --git a/README.md b/README.md index 35044927..89a346d6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language. Since we choose to use pure Go implementation of Git manipulation, Gogs certainly supports **ALL platforms** that Go supports, including Linux, Max OS X, and Windows with **ZERO** dependency. -##### Current version: 0.1.5 Alpha +##### Current version: 0.1.6 Alpha ## Purpose diff --git a/models/action.go b/models/action.go index a996e16a..cfb12436 100644 --- a/models/action.go +++ b/models/action.go @@ -30,7 +30,7 @@ type Action struct { ActUserName string // Action user name. RepoId int64 RepoName string - Content string + Content string `xorm:"TEXT"` Created time.Time `xorm:"created"` } diff --git a/models/issue.go b/models/issue.go index 0b6ca4c3..f78c240c 100644 --- a/models/issue.go +++ b/models/issue.go @@ -5,12 +5,17 @@ package models import ( + "errors" "strings" "time" "github.com/gogits/gogs/modules/base" ) +var ( + ErrIssueNotExist = errors.New("Issue does not exist") +) + // Issue represents an issue or pull request of repository. type Issue struct { Id int64 @@ -22,22 +27,25 @@ type Issue struct { AssigneeId int64 IsPull bool // Indicates whether is a pull request or not. IsClosed bool - Labels string - Mentions string - Content string + Labels string `xorm:"TEXT"` + Mentions string `xorm:"TEXT"` + Content string `xorm:"TEXT"` NumComments int Created time.Time `xorm:"created"` Updated time.Time `xorm:"updated"` } // CreateIssue creates new issue for repository. -func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, mentions, content string, isPull bool) error { +func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, content string, isPull bool) (*Issue, error) { count, err := GetIssueCount(repoId) if err != nil { - return err + return nil, err } - _, err = orm.Insert(&Issue{ + // TODO: find out mentions + mentions := "" + + issue := &Issue{ Index: count + 1, Name: name, RepoId: repoId, @@ -48,8 +56,9 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, me Labels: labels, Mentions: mentions, Content: content, - }) - return err + } + _, err = orm.Insert(issue) + return issue, err } // GetIssueCount returns count of issues in the repository. @@ -57,9 +66,28 @@ func GetIssueCount(repoId int64) (int64, error) { return orm.Count(&Issue{RepoId: repoId}) } +// GetIssueById returns issue object by given id. +func GetIssueById(id int64) (*Issue, error) { + issue := new(Issue) + has, err := orm.Id(id).Get(issue) + if err != nil { + return nil, err + } else if !has { + return nil, ErrIssueNotExist + } + return issue, nil +} + // GetIssues returns a list of issues by given conditions. func GetIssues(userId, repoId, posterId, milestoneId int64, page int, isClosed, isMention bool, labels, sortType string) ([]Issue, error) { - sess := orm.Limit(20, (page-1)*20).Where("repo_id=?", repoId).And("is_closed=?", isClosed) + sess := orm.Limit(20, (page-1)*20) + + if repoId > 0 { + sess = sess.Where("repo_id=?", repoId).And("is_closed=?", isClosed) + } else { + sess = sess.Where("is_closed=?", isClosed) + } + if userId > 0 { sess = sess.And("assignee_id=?", userId) } else if posterId > 0 { diff --git a/models/publickey.go b/models/publickey.go index 9e7cc6f7..3f2fcabd 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -80,7 +80,7 @@ type PublicKey struct { OwnerId int64 `xorm:"index"` Name string `xorm:"unique not null"` Fingerprint string - Content string `xorm:"text not null"` + Content string `xorm:"TEXT not null"` Created time.Time `xorm:"created"` Updated time.Time `xorm:"updated"` } diff --git a/models/repo.go b/models/repo.go index 317f936e..a37923c8 100644 --- a/models/repo.go +++ b/models/repo.go @@ -372,6 +372,13 @@ func RepoPath(userName, repoName string) string { } func UpdateRepository(repo *Repository) error { + if len(repo.Description) > 255 { + repo.Description = repo.Description[:255] + } + if len(repo.Website) > 255 { + repo.Website = repo.Website[:255] + } + _, err := orm.Id(repo.Id).UseBool().Cols("description", "website").Update(repo) return err } diff --git a/models/user.go b/models/user.go index 88c29ae4..9333d1ee 100644 --- a/models/user.go +++ b/models/user.go @@ -201,6 +201,13 @@ func VerifyUserActiveCode(code string) (user *User) { // UpdateUser updates user's information. func UpdateUser(user *User) (err error) { + if len(user.Location) > 255 { + user.Location = user.Location[:255] + } + if len(user.Website) > 255 { + user.Website = user.Website[:255] + } + _, err = orm.Id(user.Id).UseBool().Cols("website", "location").Update(user) return err } diff --git a/modules/auth/issue.go b/modules/auth/issue.go new file mode 100644 index 00000000..e2b1f9f2 --- /dev/null +++ b/modules/auth/issue.go @@ -0,0 +1,54 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package auth + +import ( + "net/http" + "reflect" + + "github.com/codegangsta/martini" + + "github.com/gogits/binding" + + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" +) + +type CreateIssueForm struct { + IssueName string `form:"name" binding:"Required;MaxSize(50)"` + RepoId int64 `form:"repoid" binding:"Required"` + MilestoneId int64 `form:"milestoneid" binding:"Required"` + AssigneeId int64 `form:"assigneeid"` + Labels string `form:"labels"` + Content string `form:"content"` +} + +func (f *CreateIssueForm) Name(field string) string { + names := map[string]string{ + "IssueName": "Issue name", + "RepoId": "Repository ID", + "MilestoneId": "Milestone ID", + } + return names[field] +} + +func (f *CreateIssueForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { + if req.Method == "GET" || errors.Count() == 0 { + return + } + + data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + data["HasError"] = true + AssignForm(f, data) + + if len(errors.Overall) > 0 { + for _, err := range errors.Overall { + log.Error("CreateIssueForm.Validate: %v", err) + } + return + } + + validate(errors, data, f) +} diff --git a/routers/repo/issue.go b/routers/repo/issue.go index eee55c6f..154e8308 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -5,14 +5,19 @@ package repo import ( + "fmt" + "github.com/codegangsta/martini" "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" ) func Issues(ctx *middleware.Context, params martini.Params) { + ctx.Data["Title"] = "Issues" ctx.Data["IsRepoToolbarIssues"] = true milestoneId, _ := base.StrTo(params["milestone"]).Int() @@ -29,12 +34,52 @@ func Issues(ctx *middleware.Context, params martini.Params) { ctx.HTML(200, "repo/issues") } -func CreateIssue(ctx *middleware.Context, params martini.Params) { +func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { if !ctx.Repo.IsOwner { ctx.Error(404) return } - // else if err = models.CreateIssue(userId, repoId, milestoneId, assigneeId, name, labels, mentions, content, isPull); err != nil { - // } + ctx.Data["Title"] = "Create issue" + + if ctx.Req.Method == "GET" { + ctx.HTML(200, "issue/create") + return + } + + if ctx.HasError() { + ctx.HTML(200, "issue/create") + return + } + + issue, err := models.CreateIssue(ctx.User.Id, form.RepoId, form.MilestoneId, form.AssigneeId, + form.IssueName, form.Labels, form.Content, false) + if err == nil { + log.Trace("%s Issue created: %d", form.RepoId, issue.Id) + ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index), 302) + return + } + ctx.Handle(200, "issue.CreateIssue", err) +} + +func ViewIssue(ctx *middleware.Context, params martini.Params) { + issueid, err := base.StrTo(params["issueid"]).Int() + if err != nil { + ctx.Error(404) + return + } + + issue, err := models.GetIssueById(int64(issueid)) + if err != nil { + if err == models.ErrIssueNotExist { + ctx.Error(404) + } else { + ctx.Handle(200, "issue.ViewIssue", err) + } + return + } + + ctx.Data["Title"] = issue.Name + ctx.Data["Issue"] = issue + ctx.HTML(200, "issue/view") } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index ff0fa85d..c436d387 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -31,6 +31,11 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { return } + if ctx.HasError() { + ctx.HTML(200, "repo/create") + return + } + _, err := models.CreateRepository(ctx.User, form.RepoName, form.Description, form.Language, form.License, form.Visibility == "private", form.InitReadme == "on") if err == nil { diff --git a/templates/admin/repos.tmpl b/templates/admin/repos.tmpl index a1f41d83..2c91ccc0 100644 --- a/templates/admin/repos.tmpl +++ b/templates/admin/repos.tmpl @@ -27,7 +27,7 @@ {{.Id}} {{.UserName}} {{.Name}} - + {{.NumWatches}} {{.NumForks}} {{DateFormat .Created "M d, Y"}} diff --git a/web.go b/web.go index 0da2d129..bf654aac 100644 --- a/web.go +++ b/web.go @@ -91,53 +91,73 @@ func runWeb(*cli.Context) { m.Get("/issues", reqSignIn, user.Issues) m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) - m.Any("/user/login", reqSignOut, binding.BindIgnErr(auth.LogInForm{}), user.SignIn) - m.Any("/user/logout", reqSignIn, user.SignOut) - m.Any("/user/sign_up", reqSignOut, binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) - m.Any("/user/delete", reqSignIn, user.Delete) - m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) - m.Get("/user/activate", user.Activate) - - m.Any("/user/setting", reqSignIn, binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting) - m.Any("/user/setting/password", reqSignIn, binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword) - m.Any("/user/setting/ssh", reqSignIn, binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys) - m.Any("/user/setting/notification", reqSignIn, user.SettingNotification) - m.Any("/user/setting/security", reqSignIn, user.SettingSecurity) + m.Get("/help", routers.Help) + + m.Group("/user", func(r martini.Router) { + r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn) + r.Any("/sign_up", reqSignOut, binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) + }, reqSignOut) + m.Group("/user", func(r martini.Router) { + r.Any("/logout", user.SignOut) + r.Any("/delete", user.Delete) + r.Any("/setting", binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting) + }, reqSignIn) + m.Group("/user", func(r martini.Router) { + r.Get("/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) + r.Get("/activate", user.Activate) + }) + + m.Group("/user/setting", func(r martini.Router) { + r.Any("/password", binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword) + r.Any("/ssh", binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys) + r.Any("/notification", user.SettingNotification) + r.Any("/security", user.SettingSecurity) + }, reqSignIn) m.Get("/user/:username", ignSignIn, user.Profile) m.Any("/repo/create", reqSignIn, binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create) - m.Get("/help", routers.Help) - adminReq := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true, AdminRequire: true}) m.Get("/admin", adminReq, admin.Dashboard) - m.Get("/admin/users", adminReq, admin.Users) - m.Any("/admin/users/new", adminReq, binding.BindIgnErr(auth.RegisterForm{}), admin.NewUser) - m.Any("/admin/users/:userid", adminReq, binding.BindIgnErr(auth.AdminEditUserForm{}), admin.EditUser) - m.Any("/admin/users/:userid/delete", adminReq, admin.DeleteUser) - m.Get("/admin/repos", adminReq, admin.Repositories) - m.Get("/admin/config", adminReq, admin.Config) - - m.Post("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.SettingPost) - m.Get("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.Setting) - - m.Get("/:username/:reponame/commits/:branchname", ignSignIn, middleware.RepoAssignment(true), repo.Commits) - m.Get("/:username/:reponame/issues", ignSignIn, middleware.RepoAssignment(true), repo.Issues) - m.Get("/:username/:reponame/pulls", ignSignIn, middleware.RepoAssignment(true), repo.Pulls) - m.Get("/:username/:reponame/branches", ignSignIn, middleware.RepoAssignment(true), repo.Branches) - m.Get("/:username/:reponame/action/:action", reqSignIn, middleware.RepoAssignment(true), repo.Action) - m.Get("/:username/:reponame/src/:branchname/**", - ignSignIn, middleware.RepoAssignment(true), repo.Single) - m.Get("/:username/:reponame/src/:branchname", - ignSignIn, middleware.RepoAssignment(true), repo.Single) - m.Get("/:username/:reponame/commit/:commitid/**", ignSignIn, middleware.RepoAssignment(true), repo.Single) - m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Single) - - m.Get("/:username/:reponame", ignSignIn, middleware.RepoAssignment(true), repo.Single) - - m.Any("/:username/:reponame/**", ignSignIn, repo.Http) + m.Group("/admin", func(r martini.Router) { + r.Get("/users", admin.Users) + r.Get("/repos", admin.Repositories) + r.Get("/config", admin.Config) + }, adminReq) + m.Group("/admin/users", func(r martini.Router) { + r.Any("/new", binding.BindIgnErr(auth.RegisterForm{}), admin.NewUser) + r.Any("/:userid", binding.BindIgnErr(auth.AdminEditUserForm{}), admin.EditUser) + r.Any("/:userid/delete", admin.DeleteUser) + }, adminReq) + + m.Group("/:username/:reponame", func(r martini.Router) { + r.Post("/settings", repo.SettingPost) + r.Get("/settings", repo.Setting) + r.Get("/action/:action", repo.Action) + }, reqSignIn, middleware.RepoAssignment(true)) + m.Group("/:username/:reponame", func(r martini.Router) { + r.Get("/commits/:branchname", repo.Commits) + r.Get("/issues", repo.Issues) + r.Any("/issues/new", binding.BindIgnErr(auth.CreateIssueForm{}), repo.CreateIssue) + r.Get("/issues/:issueid", repo.ViewIssue) + r.Get("/pulls", repo.Pulls) + r.Get("/branches", repo.Branches) + r.Get("/src/:branchname", repo.Single) + r.Get("/src/:branchname/**", repo.Single) + r.Get("/commits/:branchname", repo.Commits) + r.Get("/commits/:branchname", repo.Commits) + }, ignSignIn, middleware.RepoAssignment(true)) + + // TODO: implement single commit page + // m.Get("/:username/:reponame/commit/:commitid/**", ignSignIn, middleware.RepoAssignment(true), repo.Single) + // m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Single) + + m.Group("/:username", func(r martini.Router) { + r.Get("/:reponame", middleware.RepoAssignment(true), repo.Single) + r.Any("/:reponame/**", repo.Http) + }, ignSignIn) if martini.Env == martini.Dev { m.Get("/template/**", dev.TemplatePreview) -- cgit v1.2.3 From 7356153ba3c19ff49f3ecfa28bac0b8bb38eccb9 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Mar 2014 17:59:22 -0400 Subject: Batch updates --- README.md | 4 ++-- conf/app.ini | 10 ++++++++-- modules/base/conf.go | 4 ++++ modules/middleware/auth.go | 3 +++ routers/admin/user.go | 2 +- routers/repo/issue.go | 2 +- routers/repo/repo.go | 8 ++++---- routers/user/user.go | 21 ++++++++++++++++++--- 8 files changed, 41 insertions(+), 13 deletions(-) (limited to 'routers/repo/issue.go') diff --git a/README.md b/README.md index 89a346d6..325c3a97 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,8 @@ There are two ways to install Gogs: ## Acknowledgments - Logo is inspired by [martini](https://github.com/martini-contrib). -- Mail Service is based on [WeTalk](https://github.com/beego/wetalk). -- System Monitor Status is based on [GoBlog](https://github.com/fuxiaohei/goblog). +- Mail Service, modules design is inspired by [WeTalk](https://github.com/beego/wetalk). +- System Monitor Status is inspired by [GoBlog](https://github.com/fuxiaohei/goblog). ## Contributors diff --git a/conf/app.ini b/conf/app.ini index 7f283012..b051557f 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -107,7 +107,7 @@ SERVICE = server PATH = data/pictures [log] -; Either "console", "file", "conn" or "smtp", default is "console" +; Either "console", "file", "conn", "smtp" or "database", default is "console" MODE = console ; Buffer length of channel, keep it as it is if you don't know what it is. BUFFER_LEN = 10000 @@ -156,4 +156,10 @@ HOST = USER = PASSWD = ; Receivers, can be one or more, e.g. ["1@example.com","2@example.com"] -RECEIVERS = \ No newline at end of file +RECEIVERS = + +; For "database" mode only +[log.database] +LEVEL = +Driver = +CONN = \ No newline at end of file diff --git a/modules/base/conf.go b/modules/base/conf.go index cdbe2b36..19f58707 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -143,6 +143,10 @@ func newLogService() { Cfg.MustValue(modeSec, "HOST", "127.0.0.1:25"), Cfg.MustValue(modeSec, "RECEIVERS", "[]"), Cfg.MustValue(modeSec, "SUBJECT", "Diagnostic message from serve")) + case "database": + LogConfig = fmt.Sprintf(`{"level":%s,"driver":%s,"conn":%s}`, level, + Cfg.MustValue(modeSec, "Driver"), + Cfg.MustValue(modeSec, "CONN")) } log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), LogMode, LogConfig) diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index 3224b3df..82c3367c 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -5,6 +5,8 @@ package middleware import ( + "net/url" + "github.com/codegangsta/martini" "github.com/gogits/gogs/modules/base" @@ -35,6 +37,7 @@ func Toggle(options *ToggleOptions) martini.Handler { if options.SignInRequire { if !ctx.IsSigned { + ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI)) ctx.Redirect("/user/login") return } else if !ctx.User.IsActive && base.Service.RegisterEmailConfirm { diff --git a/routers/admin/user.go b/routers/admin/user.go index fa27d116..7f66c552 100644 --- a/routers/admin/user.go +++ b/routers/admin/user.go @@ -140,5 +140,5 @@ func DeleteUser(ctx *middleware.Context, params martini.Params) { log.Trace("%s User deleted by admin(%s): %s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.User.LowerName) - ctx.Redirect("/admin/users", 302) + ctx.Redirect("/admin/users") } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 154e8308..4cc007e9 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -56,7 +56,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat form.IssueName, form.Labels, form.Content, false) if err == nil { log.Trace("%s Issue created: %d", form.RepoId, issue.Id) - ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index), 302) + ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index)) return } ctx.Handle(200, "issue.CreateIssue", err) diff --git a/routers/repo/repo.go b/routers/repo/repo.go index c436d387..4782d64f 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -40,7 +40,7 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { form.Language, form.License, form.Visibility == "private", form.InitReadme == "on") if err == nil { log.Trace("%s Repository created: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName) - ctx.Redirect("/"+ctx.User.Name+"/"+form.RepoName, 302) + ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { ctx.RenderWithErr("Repository name has already been used", "repo/create", &form) @@ -73,7 +73,7 @@ func SettingPost(ctx *middleware.Context) { } log.Trace("%s Repository deleted: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.Repo.Repository.LowerName) - ctx.Redirect("/", 302) + ctx.Redirect("/") } func Branches(ctx *middleware.Context, params martini.Params) { @@ -113,8 +113,8 @@ func Single(ctx *middleware.Context, params martini.Params) { treename := params["_1"] if len(treename) > 0 && treename[len(treename)-1] == '/' { - ctx.Redirect("/"+ctx.Repo.Owner.LowerName+"/"+ - ctx.Repo.Repository.Name+"/src/"+params["branchname"]+"/"+treename[:len(treename)-1], 302) + ctx.Redirect("/" + ctx.Repo.Owner.LowerName + "/" + + ctx.Repo.Repository.Name + "/src/" + params["branchname"] + "/" + treename[:len(treename)-1]) return } diff --git a/routers/user/user.go b/routers/user/user.go index 56bc5f8e..c34b529e 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -6,6 +6,7 @@ package user import ( "fmt" + "net/url" "strings" "github.com/codegangsta/martini" @@ -109,7 +110,13 @@ func SignIn(ctx *middleware.Context, form auth.LogInForm) { isSucceed = true ctx.Session.Set("userId", user.Id) ctx.Session.Set("userName", user.Name) - ctx.Redirect("/") + redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")) + if len(redirectTo) > 0 { + ctx.SetCookie("redirect_to", "", -1) + ctx.Redirect(redirectTo) + } else { + ctx.Redirect("/") + } return } @@ -139,12 +146,20 @@ func SignIn(ctx *middleware.Context, form auth.LogInForm) { ctx.Session.Set("userId", user.Id) ctx.Session.Set("userName", user.Name) - ctx.Redirect("/") + redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")) + if len(redirectTo) > 0 { + ctx.SetCookie("redirect_to", "", -1) + ctx.Redirect(redirectTo) + } else { + ctx.Redirect("/") + } } func SignOut(ctx *middleware.Context) { ctx.Session.Delete("userId") ctx.Session.Delete("userName") + ctx.SetCookie(base.CookieUserName, "", -1) + ctx.SetCookie(base.CookieRememberName, "", -1) ctx.Redirect("/") } @@ -314,7 +329,7 @@ func Activate(ctx *middleware.Context) { ctx.Session.Set("userId", user.Id) ctx.Session.Set("userName", user.Name) - ctx.Redirect("/", 302) + ctx.Redirect("/") return } -- cgit v1.2.3 From 47493a0191f3de8aa4e80bce1911f14623cfa46a Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sun, 23 Mar 2014 13:12:55 +0800 Subject: use ctx.Handle to handle 404 page --- routers/repo/issue.go | 6 +++--- routers/repo/repo.go | 32 ++++++++++++++++---------------- routers/user/user.go | 2 +- templates/status/404.tmpl | 7 +++++++ templates/status/500.tmpl | 7 +++++++ 5 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 templates/status/404.tmpl create mode 100644 templates/status/500.tmpl (limited to 'routers/repo/issue.go') diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 4cc007e9..78fe4b25 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -36,7 +36,7 @@ func Issues(ctx *middleware.Context, params martini.Params) { func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { if !ctx.Repo.IsOwner { - ctx.Error(404) + ctx.Handle(404, "issue.CreateIssue", nil) return } @@ -65,14 +65,14 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat func ViewIssue(ctx *middleware.Context, params martini.Params) { issueid, err := base.StrTo(params["issueid"]).Int() if err != nil { - ctx.Error(404) + ctx.Handle(404, "issue.ViewIssue", err) return } issue, err := models.GetIssueById(int64(issueid)) if err != nil { if err == models.ErrIssueNotExist { - ctx.Error(404) + ctx.Handle(404, "issue.ViewIssue", err) } else { ctx.Handle(200, "issue.ViewIssue", err) } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 4782d64f..0f1ea312 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -86,7 +86,7 @@ func Branches(ctx *middleware.Context, params martini.Params) { ctx.Handle(200, "repo.Branches", err) return } else if len(brs) == 0 { - ctx.Error(404) + ctx.Handle(404, "repo.Branches", nil) return } @@ -123,8 +123,8 @@ func Single(ctx *middleware.Context, params martini.Params) { // Branches. brs, err := models.GetBranches(params["username"], params["reponame"]) if err != nil { - log.Error("repo.Single(GetBranches): %v", err) - ctx.Error(404) + //log.Error("repo.Single(GetBranches): %v", err) + ctx.Handle(404, "repo.Single(GetBranches)", err) return } else if ctx.Repo.Repository.IsBare { ctx.Data["IsBareRepo"] = true @@ -138,15 +138,15 @@ func Single(ctx *middleware.Context, params martini.Params) { params["branchname"], params["commitid"], treename) if err != nil && err != models.ErrRepoFileNotExist { - log.Error("repo.Single(GetTargetFile): %v", err) - ctx.Error(404) + //log.Error("repo.Single(GetTargetFile): %v", err) + ctx.Handle(404, "repo.Single(GetTargetFile)", err) return } branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + params["branchname"] if len(treename) != 0 && repoFile == nil { - ctx.Error(404) + ctx.Handle(404, "repo.Single", nil) return } @@ -154,8 +154,8 @@ func Single(ctx *middleware.Context, params martini.Params) { if repoFile.Size > 1024*1024 || repoFile.Filemode != git.FileModeBlob { ctx.Data["FileIsLarge"] = true } else if blob, err := repoFile.LookupBlob(); err != nil { - log.Error("repo.Single(repoFile.LookupBlob): %v", err) - ctx.Error(404) + //log.Error("repo.Single(repoFile.LookupBlob): %v", err) + ctx.Handle(404, "repo.Single(repoFile.LookupBlob)", err) } else { ctx.Data["IsFile"] = true ctx.Data["FileName"] = repoFile.Name @@ -179,8 +179,8 @@ func Single(ctx *middleware.Context, params martini.Params) { files, err := models.GetReposFiles(params["username"], params["reponame"], params["branchname"], params["commitid"], treename) if err != nil { - log.Error("repo.Single(GetReposFiles): %v", err) - ctx.Error(404) + //log.Error("repo.Single(GetReposFiles): %v", err) + ctx.Handle(404, "repo.Single(GetReposFiles)", err) return } @@ -203,8 +203,8 @@ func Single(ctx *middleware.Context, params martini.Params) { if readmeFile.Size > 1024*1024 || readmeFile.Filemode != git.FileModeBlob { ctx.Data["FileIsLarge"] = true } else if blob, err := readmeFile.LookupBlob(); err != nil { - log.Error("repo.Single(readmeFile.LookupBlob): %v", err) - ctx.Error(404) + //log.Error("repo.Single(readmeFile.LookupBlob): %v", err) + ctx.Handle(404, "repo.Single(readmeFile.LookupBlob)", err) return } else { // current repo branch link @@ -239,7 +239,7 @@ func Single(ctx *middleware.Context, params martini.Params) { params["branchname"], params["commitid"]) if err != nil { log.Error("repo.Single(GetCommit): %v", err) - ctx.Error(404) + ctx.Handle(404, "repo.Single(GetCommit)", err) return } ctx.Data["LastCommit"] = commit @@ -275,7 +275,7 @@ func Http(ctx *middleware.Context, params martini.Params) { func Setting(ctx *middleware.Context, params martini.Params) { if !ctx.Repo.IsOwner { - ctx.Error(404) + ctx.Handle(404, "repo.Setting", nil) return } @@ -307,7 +307,7 @@ func Commits(ctx *middleware.Context, params martini.Params) { ctx.Handle(200, "repo.Commits", err) return } else if len(brs) == 0 { - ctx.Error(404) + ctx.Handle(404, "repo.Commits", nil) return } @@ -315,7 +315,7 @@ func Commits(ctx *middleware.Context, params martini.Params) { commits, err := models.GetCommits(params["username"], params["reponame"], params["branchname"]) if err != nil { - ctx.Error(404) + ctx.Handle(404, "repo.Commits", nil) return } ctx.Data["Username"] = params["username"] diff --git a/routers/user/user.go b/routers/user/user.go index c34b529e..a0321f18 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -301,7 +301,7 @@ func Activate(ctx *middleware.Context) { if len(code) == 0 { ctx.Data["IsActivatePage"] = true if ctx.User.IsActive { - ctx.Error(404) + ctx.Handle(404, "user.Activate", nil) return } // Resend confirmation e-mail. diff --git a/templates/status/404.tmpl b/templates/status/404.tmpl new file mode 100644 index 00000000..4e836b22 --- /dev/null +++ b/templates/status/404.tmpl @@ -0,0 +1,7 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+

This page is not found !

+

Application Version: {{AppVer}}

+
+{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/status/500.tmpl b/templates/status/500.tmpl new file mode 100644 index 00000000..9a00eb1f --- /dev/null +++ b/templates/status/500.tmpl @@ -0,0 +1,7 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+

An error is occurred : {{.ErrorMsg}}

+

Application Version: {{AppVer}}

+
+{{template "base/footer" .}} \ No newline at end of file -- cgit v1.2.3