From 0f907301b7fbd05faf07bc22b3316ae1093c6724 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 12 Jul 2014 00:55:19 -0400 Subject: [PATCH] Fix #285 --- cmd/fix.go | 12 ++++++++++-- cmd/web.go | 7 ++++++- gogs.go | 2 +- models/repo.go | 13 ++++++++++--- models/user.go | 2 +- routers/admin/admin.go | 4 ++-- routers/api/v1/repositories.go | 13 +++++++++++++ routers/api/v1/users.go | 2 +- routers/user/setting.go | 8 ++++---- 9 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 routers/api/v1/repositories.go diff --git a/cmd/fix.go b/cmd/fix.go index 95ab3ae66f..dfcd04aa89 100644 --- a/cmd/fix.go +++ b/cmd/fix.go @@ -11,6 +11,7 @@ import ( "io/ioutil" "os" "path" + "runtime" "strings" "github.com/codegangsta/cli" @@ -93,9 +94,16 @@ func rewriteAuthorizedKeys(sshPath, oldPath, newPath string) error { } func rewriteUpdateHook(path, appPath string) error { - rp := strings.NewReplacer("\\", "/", " ", "\\ ") + if runtime.GOOS == "windows" { + rp := strings.NewReplacer("\\", "/") + appPath = "\"" + rp.Replace(appPath) + "\"" + } else { + rp := strings.NewReplacer("\\", "/", " ", "\\ ") + appPath = rp.Replace(appPath) + } + if err := ioutil.WriteFile(path, []byte(fmt.Sprintf(models.TPL_UPDATE_HOOK, - setting.ScriptType, rp.Replace(appPath))), os.ModePerm); err != nil { + setting.ScriptType, appPath)), os.ModePerm); err != nil { return err } return nil diff --git a/cmd/web.go b/cmd/web.go index 5f9c168d88..bb46536542 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -103,7 +103,10 @@ func runWeb(*cli.Context) { r.Post("/markdown/raw", v1.MarkdownRaw) // Users. - r.Get("/users/search", v1.SearchUser) + r.Get("/users/search", v1.SearchUsers) + + // Repositories. + r.Get("/orgs/:org/repos/search", v1.SearchOrgRepositoreis) r.Any("**", func(ctx *middleware.Context) { ctx.JSON(404, &base.ApiJsonErr{"Not Found", v1.DOC_URL}) @@ -182,6 +185,8 @@ func runWeb(*cli.Context) { r.Get("/:authid/delete", admin.DeleteAuthSource) }, adminReq) + m.Get("/:username", ignSignIn, user.Profile) + if martini.Env == martini.Dev { m.Get("/template/**", dev.TemplatePreview) dev.RegisterDebugRoutes(m) diff --git a/gogs.go b/gogs.go index 0014b76f90..c7c9ca8d00 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.4.5.0707 Alpha" +const APP_VER = "0.4.5.0712 Alpha" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/repo.go b/models/repo.go index 396e536e4b..fb7bbbd036 100644 --- a/models/repo.go +++ b/models/repo.go @@ -11,6 +11,7 @@ import ( "os" "path" "path/filepath" + "runtime" "sort" "strings" "time" @@ -359,11 +360,17 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep return err } - rp := strings.NewReplacer("\\", "/", " ", "\\ ") + if runtime.GOOS == "windows" { + rp := strings.NewReplacer("\\", "/") + appPath = "\"" + rp.Replace(appPath) + "\"" + } else { + rp := strings.NewReplacer("\\", "/", " ", "\\ ") + appPath = rp.Replace(appPath) + } + // hook/post-update if err := createHookUpdate(filepath.Join(repoPath, "hooks", "update"), - fmt.Sprintf(TPL_UPDATE_HOOK, setting.ScriptType, - rp.Replace(appPath))); err != nil { + fmt.Sprintf(TPL_UPDATE_HOOK, setting.ScriptType, appPath)); err != nil { return err } diff --git a/models/user.go b/models/user.go index 47f1d45f0e..13c9148473 100644 --- a/models/user.go +++ b/models/user.go @@ -500,7 +500,7 @@ func SearchUserByName(key string, limit int) (us []*User, err error) { key = strings.ToLower(key) us = make([]*User, 0, limit) - err = x.Limit(limit).Where("lower_name like '%" + key + "%'").Find(&us) + err = x.Limit(limit).Where("type=0").And("lower_name like '%" + key + "%'").Find(&us) return us, err } diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 2a40792a18..eb4123435a 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -163,7 +163,7 @@ func Users(ctx *middleware.Context) { if p < 1 { p = 1 } - pageNum := 100 + pageNum := 50 count := models.CountUsers() curCount := int64((p-1)*pageNum + pageNum) if curCount > count { @@ -192,7 +192,7 @@ func Repositories(ctx *middleware.Context) { if p < 1 { p = 1 } - pageNum := 2 + pageNum := 50 count := models.CountRepositories() curCount := int64((p-1)*pageNum + pageNum) if curCount > count { diff --git a/routers/api/v1/repositories.go b/routers/api/v1/repositories.go new file mode 100644 index 0000000000..11c8b6b2e3 --- /dev/null +++ b/routers/api/v1/repositories.go @@ -0,0 +1,13 @@ +// 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 v1 + +import ( + "github.com/gogits/gogs/modules/middleware" +) + +func SearchOrgRepositoreis(ctx *middleware.Context) { + +} diff --git a/routers/api/v1/users.go b/routers/api/v1/users.go index a5ad8fbca0..e4da60aa7b 100644 --- a/routers/api/v1/users.go +++ b/routers/api/v1/users.go @@ -15,7 +15,7 @@ type user struct { AvatarLink string `json:"avatar"` } -func SearchUser(ctx *middleware.Context) { +func SearchUsers(ctx *middleware.Context) { q := ctx.Query("q") limit, err := base.StrTo(ctx.Query("limit")).Int() if err != nil { diff --git a/routers/user/setting.go b/routers/user/setting.go index 8e4b0840c7..3ff8e21df3 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -47,13 +47,13 @@ func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) { if ctx.User.Name != form.UserName { isExist, err := models.IsUserExist(form.UserName) if err != nil { - ctx.Handle(500, "user.Setting(update: check existence)", err) + ctx.Handle(500, "user.SettingPost(update: check existence)", err) return } else if isExist { - ctx.RenderWithErr("User name has been taken.", "user/setting", &form) + ctx.RenderWithErr("User name has been taken.", SETTING, &form) return } else if err = models.ChangeUserName(ctx.User, form.UserName); err != nil { - ctx.Handle(500, "user.Setting(change user name)", err) + ctx.Handle(500, "user.SettingPost(change user name)", err) return } log.Trace("%s User name changed: %s -> %s", ctx.Req.RequestURI, ctx.User.Name, form.UserName) @@ -68,7 +68,7 @@ func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) { ctx.User.Avatar = base.EncodeMd5(form.Avatar) ctx.User.AvatarEmail = form.Avatar if err := models.UpdateUser(ctx.User); err != nil { - ctx.Handle(500, "setting.Setting(UpdateUser)", err) + ctx.Handle(500, "setting.SettingPost(UpdateUser)", err) return } log.Trace("%s User setting updated: %s", ctx.Req.RequestURI, ctx.User.LowerName)