Merge branch 'dev' into newcollaboration
This commit is contained in:
commit
03af37554e
47 changed files with 1297 additions and 359 deletions
|
@ -118,6 +118,7 @@ const (
|
|||
CLEAN_INACTIVATE_USER
|
||||
CLEAN_REPO_ARCHIVES
|
||||
GIT_GC_REPOS
|
||||
SYNC_SSH_AUTHORIZED_KEY
|
||||
)
|
||||
|
||||
func Dashboard(ctx *middleware.Context) {
|
||||
|
@ -144,6 +145,9 @@ func Dashboard(ctx *middleware.Context) {
|
|||
case GIT_GC_REPOS:
|
||||
success = ctx.Tr("admin.dashboard.git_gc_repos_success")
|
||||
err = models.GitGcRepos()
|
||||
case SYNC_SSH_AUTHORIZED_KEY:
|
||||
success = ctx.Tr("admin.dashboard.resync_all_sshkeys_success")
|
||||
err = models.RewriteAllPublicKeys()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/Unknwon/com"
|
||||
"github.com/Unknwon/macaron"
|
||||
"github.com/go-xorm/xorm"
|
||||
"gopkg.in/ini.v1"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/auth"
|
||||
|
@ -73,12 +74,7 @@ func GlobalInit() {
|
|||
checkRunMode()
|
||||
}
|
||||
|
||||
func renderDbOption(ctx *middleware.Context) {
|
||||
ctx.Data["DbOptions"] = []string{"MySQL", "PostgreSQL", "SQLite3"}
|
||||
}
|
||||
|
||||
// @router /install [get]
|
||||
func Install(ctx *middleware.Context, form auth.InstallForm) {
|
||||
func InstallInit(ctx *middleware.Context) {
|
||||
if setting.InstallLock {
|
||||
ctx.Handle(404, "Install", errors.New("Installation is prohibited"))
|
||||
return
|
||||
|
@ -87,46 +83,35 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
|||
ctx.Data["Title"] = ctx.Tr("install.install")
|
||||
ctx.Data["PageIsInstall"] = true
|
||||
|
||||
// FIXME: when i'm ckeching length here? should they all be 0 no matter when?
|
||||
// Get and assign values to install form.
|
||||
if len(form.DbHost) == 0 {
|
||||
form.DbHost = models.DbCfg.Host
|
||||
}
|
||||
if len(form.DbUser) == 0 {
|
||||
form.DbUser = models.DbCfg.User
|
||||
}
|
||||
if len(form.DbPasswd) == 0 {
|
||||
form.DbPasswd = models.DbCfg.Pwd
|
||||
}
|
||||
if len(form.DatabaseName) == 0 {
|
||||
form.DatabaseName = models.DbCfg.Name
|
||||
}
|
||||
if len(form.DatabasePath) == 0 {
|
||||
form.DatabasePath = models.DbCfg.Path
|
||||
}
|
||||
ctx.Data["DbOptions"] = []string{"MySQL", "PostgreSQL", "SQLite3"}
|
||||
}
|
||||
|
||||
if len(form.RepoRootPath) == 0 {
|
||||
form.RepoRootPath = setting.RepoRootPath
|
||||
}
|
||||
if len(form.RunUser) == 0 {
|
||||
// Note: it's not normall to use SSH in windows so current user can be first option(not git).
|
||||
if setting.IsWindows && setting.RunUser == "git" {
|
||||
form.RunUser = os.Getenv("USER")
|
||||
if len(form.RunUser) == 0 {
|
||||
form.RunUser = os.Getenv("USERNAME")
|
||||
}
|
||||
} else {
|
||||
form.RunUser = setting.RunUser
|
||||
func Install(ctx *middleware.Context) {
|
||||
form := auth.InstallForm{}
|
||||
|
||||
form.DbHost = models.DbCfg.Host
|
||||
form.DbUser = models.DbCfg.User
|
||||
form.DbPasswd = models.DbCfg.Passwd
|
||||
form.DbName = models.DbCfg.Name
|
||||
form.DbPath = models.DbCfg.Path
|
||||
|
||||
form.RepoRootPath = setting.RepoRootPath
|
||||
|
||||
// Note(unknwon): it's hard for Windows users change a running user,
|
||||
// so just use current one if config says default.
|
||||
if setting.IsWindows && setting.RunUser == "git" {
|
||||
form.RunUser = os.Getenv("USER")
|
||||
if len(form.RunUser) == 0 {
|
||||
form.RunUser = os.Getenv("USERNAME")
|
||||
}
|
||||
}
|
||||
if len(form.Domain) == 0 {
|
||||
form.Domain = setting.Domain
|
||||
}
|
||||
if len(form.AppUrl) == 0 {
|
||||
form.AppUrl = setting.AppUrl
|
||||
} else {
|
||||
form.RunUser = setting.RunUser
|
||||
}
|
||||
|
||||
renderDbOption(ctx)
|
||||
form.Domain = setting.Domain
|
||||
form.HTTPPort = setting.HttpPort
|
||||
form.AppUrl = setting.AppUrl
|
||||
|
||||
curDbOp := ""
|
||||
if models.EnableSQLite3 {
|
||||
curDbOp = "SQLite3" // Default when enabled.
|
||||
|
@ -138,16 +123,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
|||
}
|
||||
|
||||
func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
||||
if setting.InstallLock {
|
||||
ctx.Handle(404, "InstallPost", errors.New("Installation is prohibited"))
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Title"] = ctx.Tr("install.install")
|
||||
ctx.Data["PageIsInstall"] = true
|
||||
|
||||
renderDbOption(ctx)
|
||||
ctx.Data["CurDbOption"] = form.Database
|
||||
ctx.Data["CurDbOption"] = form.DbType
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, INSTALL)
|
||||
|
@ -162,18 +138,17 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
// Pass basic check, now test configuration.
|
||||
// Test database setting.
|
||||
dbTypes := map[string]string{"MySQL": "mysql", "PostgreSQL": "postgres", "SQLite3": "sqlite3"}
|
||||
models.DbCfg.Type = dbTypes[form.Database]
|
||||
models.DbCfg.Type = dbTypes[form.DbType]
|
||||
models.DbCfg.Host = form.DbHost
|
||||
models.DbCfg.User = form.DbUser
|
||||
models.DbCfg.Pwd = form.DbPasswd
|
||||
models.DbCfg.Name = form.DatabaseName
|
||||
models.DbCfg.SslMode = form.SslMode
|
||||
models.DbCfg.Path = form.DatabasePath
|
||||
models.DbCfg.Passwd = form.DbPasswd
|
||||
models.DbCfg.Name = form.DbName
|
||||
models.DbCfg.SSLMode = form.SSLMode
|
||||
models.DbCfg.Path = form.DbPath
|
||||
|
||||
// Set test engine.
|
||||
var x *xorm.Engine
|
||||
if err := models.NewTestEngine(x); err != nil {
|
||||
// FIXME: should use core.QueryDriver (github.com/go-xorm/core)
|
||||
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
|
||||
ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "http://gogs.io/docs/installation/install_from_binary.html"), INSTALL, &form)
|
||||
} else {
|
||||
|
@ -194,7 +169,6 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
if len(curUser) == 0 {
|
||||
curUser = os.Getenv("USERNAME")
|
||||
}
|
||||
// Does not check run user when the install lock is off.
|
||||
if form.RunUser != curUser {
|
||||
ctx.Data["Err_RunUser"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("install.run_user_not_match", form.RunUser, curUser), INSTALL, &form)
|
||||
|
@ -202,47 +176,53 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
}
|
||||
|
||||
// Check admin password.
|
||||
if form.AdminPasswd != form.ConfirmPasswd {
|
||||
if form.AdminPasswd != form.AdminConfirmPasswd {
|
||||
ctx.Data["Err_AdminPasswd"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), INSTALL, form)
|
||||
return
|
||||
}
|
||||
|
||||
// Save settings.
|
||||
setting.Cfg.Section("database").Key("DB_TYPE").SetValue(models.DbCfg.Type)
|
||||
setting.Cfg.Section("database").Key("HOST").SetValue(models.DbCfg.Host)
|
||||
setting.Cfg.Section("database").Key("NAME").SetValue(models.DbCfg.Name)
|
||||
setting.Cfg.Section("database").Key("USER").SetValue(models.DbCfg.User)
|
||||
setting.Cfg.Section("database").Key("PASSWD").SetValue(models.DbCfg.Pwd)
|
||||
setting.Cfg.Section("database").Key("SSL_MODE").SetValue(models.DbCfg.SslMode)
|
||||
setting.Cfg.Section("database").Key("PATH").SetValue(models.DbCfg.Path)
|
||||
|
||||
setting.Cfg.Section("repository").Key("ROOT").SetValue(form.RepoRootPath)
|
||||
setting.Cfg.Section("").Key("RUN_USER").SetValue(form.RunUser)
|
||||
setting.Cfg.Section("server").Key("DOMAIN").SetValue(form.Domain)
|
||||
setting.Cfg.Section("server").Key("ROOT_URL").SetValue(form.AppUrl)
|
||||
|
||||
if len(strings.TrimSpace(form.SmtpHost)) > 0 {
|
||||
setting.Cfg.Section("mailer").Key("ENABLED").SetValue("true")
|
||||
setting.Cfg.Section("mailer").Key("HOST").SetValue(form.SmtpHost)
|
||||
setting.Cfg.Section("mailer").Key("USER").SetValue(form.SmtpEmail)
|
||||
setting.Cfg.Section("mailer").Key("PASSWD").SetValue(form.SmtpPasswd)
|
||||
|
||||
setting.Cfg.Section("service").Key("REGISTER_EMAIL_CONFIRM").SetValue(com.ToStr(form.RegisterConfirm == "on"))
|
||||
setting.Cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").SetValue(com.ToStr(form.MailNotify == "on"))
|
||||
if form.AppUrl[len(form.AppUrl)-1] != '/' {
|
||||
form.AppUrl += "/"
|
||||
}
|
||||
|
||||
setting.Cfg.Section("").Key("RUN_MODE").SetValue("prod")
|
||||
// Save settings.
|
||||
cfg := ini.Empty()
|
||||
cfg.Section("database").Key("DB_TYPE").SetValue(models.DbCfg.Type)
|
||||
cfg.Section("database").Key("HOST").SetValue(models.DbCfg.Host)
|
||||
cfg.Section("database").Key("NAME").SetValue(models.DbCfg.Name)
|
||||
cfg.Section("database").Key("USER").SetValue(models.DbCfg.User)
|
||||
cfg.Section("database").Key("PASSWD").SetValue(models.DbCfg.Passwd)
|
||||
cfg.Section("database").Key("SSL_MODE").SetValue(models.DbCfg.SSLMode)
|
||||
cfg.Section("database").Key("PATH").SetValue(models.DbCfg.Path)
|
||||
|
||||
setting.Cfg.Section("session").Key("PROVIDER").SetValue("file")
|
||||
cfg.Section("repository").Key("ROOT").SetValue(form.RepoRootPath)
|
||||
cfg.Section("").Key("RUN_USER").SetValue(form.RunUser)
|
||||
cfg.Section("server").Key("DOMAIN").SetValue(form.Domain)
|
||||
cfg.Section("server").Key("HTTP_PORT").SetValue(form.HTTPPort)
|
||||
cfg.Section("server").Key("ROOT_URL").SetValue(form.AppUrl)
|
||||
|
||||
setting.Cfg.Section("log").Key("MODE").SetValue("file")
|
||||
if len(strings.TrimSpace(form.SMTPHost)) > 0 {
|
||||
cfg.Section("mailer").Key("ENABLED").SetValue("true")
|
||||
cfg.Section("mailer").Key("HOST").SetValue(form.SMTPHost)
|
||||
cfg.Section("mailer").Key("USER").SetValue(form.SMTPEmail)
|
||||
cfg.Section("mailer").Key("PASSWD").SetValue(form.SMTPPasswd)
|
||||
|
||||
setting.Cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")
|
||||
setting.Cfg.Section("security").Key("SECRET_KEY").SetValue(base.GetRandomString(15))
|
||||
cfg.Section("service").Key("REGISTER_EMAIL_CONFIRM").SetValue(com.ToStr(form.RegisterConfirm == "on"))
|
||||
cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").SetValue(com.ToStr(form.MailNotify == "on"))
|
||||
}
|
||||
|
||||
cfg.Section("").Key("RUN_MODE").SetValue("prod")
|
||||
|
||||
cfg.Section("session").Key("PROVIDER").SetValue("file")
|
||||
|
||||
cfg.Section("log").Key("MODE").SetValue("file")
|
||||
|
||||
cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")
|
||||
cfg.Section("security").Key("SECRET_KEY").SetValue(base.GetRandomString(15))
|
||||
|
||||
os.MkdirAll("custom/conf", os.ModePerm)
|
||||
if err := setting.Cfg.SaveTo(path.Join(setting.CustomPath, "conf/app.ini")); err != nil {
|
||||
if err := cfg.SaveTo(path.Join(setting.CustomPath, "conf/app.ini")); err != nil {
|
||||
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
|
||||
return
|
||||
}
|
||||
|
@ -264,5 +244,5 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
|
||||
log.Info("First-time run install finished!")
|
||||
ctx.Flash.Success(ctx.Tr("install.install_success"))
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/login")
|
||||
ctx.Redirect(form.AppUrl + "user/login")
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
|
|||
newCommits := list.New()
|
||||
for e := oldCommits.Front(); e != nil; e = e.Next() {
|
||||
c := e.Value.(*git.Commit)
|
||||
c.CommitMessage = string(base.RenderIssueIndexPattern([]byte(c.CommitMessage), repoLink))
|
||||
c.CommitMessage = c.CommitMessage
|
||||
newCommits.PushBack(c)
|
||||
}
|
||||
return newCommits
|
||||
|
@ -206,7 +206,7 @@ func Diff(ctx *middleware.Context) {
|
|||
commitId := ctx.Repo.CommitId
|
||||
|
||||
commit := ctx.Repo.Commit
|
||||
commit.CommitMessage = string(base.RenderIssueIndexPattern([]byte(commit.CommitMessage), ctx.Repo.RepoLink))
|
||||
commit.CommitMessage = commit.CommitMessage
|
||||
diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName),
|
||||
commitId, setting.Git.MaxGitDiffLines)
|
||||
if err != nil {
|
||||
|
|
|
@ -25,16 +25,16 @@ func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
|
|||
buf = buf[:n]
|
||||
}
|
||||
|
||||
contentType, isTextFile := base.IsTextFile(buf)
|
||||
_, isTextFile := base.IsTextFile(buf)
|
||||
_, isImageFile := base.IsImageFile(buf)
|
||||
ctx.Resp.Header().Set("Content-Type", contentType)
|
||||
ctx.Resp.Header().Set("Content-Type", "text/plain")
|
||||
if !isTextFile && !isImageFile {
|
||||
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(ctx.Repo.TreeName))
|
||||
ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
}
|
||||
ctx.Resp.Write(buf)
|
||||
io.Copy(ctx.Resp, dataRc)
|
||||
return nil
|
||||
_, err = io.Copy(ctx.Resp, dataRc)
|
||||
return err
|
||||
}
|
||||
|
||||
func SingleDownload(ctx *middleware.Context) {
|
||||
|
|
|
@ -156,9 +156,9 @@ func Home(ctx *middleware.Context) {
|
|||
for _, f := range files {
|
||||
switch c := f[1].(type) {
|
||||
case *git.Commit:
|
||||
c.CommitMessage = string(base.RenderIssueIndexPattern([]byte(c.CommitMessage), ctx.Repo.RepoLink))
|
||||
c.CommitMessage = c.CommitMessage
|
||||
case *git.SubModuleFile:
|
||||
c.CommitMessage = string(base.RenderIssueIndexPattern([]byte(c.CommitMessage), ctx.Repo.RepoLink))
|
||||
c.CommitMessage = c.CommitMessage
|
||||
}
|
||||
}
|
||||
ctx.Data["Files"] = files
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue