Browse Source

Fix #285

for-closed-social
Unknown 10 years ago
parent
commit
0f907301b7
9 changed files with 48 additions and 15 deletions
  1. +10
    -2
      cmd/fix.go
  2. +6
    -1
      cmd/web.go
  3. +1
    -1
      gogs.go
  4. +10
    -3
      models/repo.go
  5. +1
    -1
      models/user.go
  6. +2
    -2
      routers/admin/admin.go
  7. +13
    -0
      routers/api/v1/repositories.go
  8. +1
    -1
      routers/api/v1/users.go
  9. +4
    -4
      routers/user/setting.go

+ 10
- 2
cmd/fix.go View File

@ -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

+ 6
- 1
cmd/web.go View File

@ -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)

+ 1
- 1
gogs.go View File

@ -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())

+ 10
- 3
models/repo.go View File

@ -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
}

+ 1
- 1
models/user.go View File

@ -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
}

+ 2
- 2
routers/admin/admin.go View File

@ -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 {

+ 13
- 0
routers/api/v1/repositories.go View File

@ -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) {
}

+ 1
- 1
routers/api/v1/users.go View File

@ -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 {

+ 4
- 4
routers/user/setting.go View File

@ -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)

Loading…
Cancel
Save