diff --git a/conf/app.ini b/conf/app.ini index d988b4acb..abc27c39c 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -7,7 +7,7 @@ RUN_USER = git RUN_MODE = dev [repository] -ROOT = /Users/%(RUN_USER)s/git/gogs-repositories +ROOT = LANG_IGNS = Google Go|C|C++|Python|Ruby|C Sharp LICENSES = Apache v2 License|GPL v2|MIT License|Affero GPL|Artistic License 2.0|BSD (3-Clause) License @@ -20,7 +20,7 @@ HTTP_PORT = 3000 [database] ; Either "mysql", "postgres" or "sqlite3"(binary release only), it's your choice DB_TYPE = mysql -HOST = +HOST = 127.0.0.1:3306 NAME = gogs USER = root PASSWD = @@ -33,8 +33,6 @@ PATH = data/gogs.db [security] INSTALL_LOCK = false -; Use HTTPS to clone repository, otherwise use HTTP. -ENABLE_HTTPS_CLONE = false ; !!CHANGE THIS TO KEEP YOUR USER DATA SAFE!! SECRET_KEY = !#@FDEWREWR&*( ; Auto-login remember days diff --git a/gogs.go b/gogs.go index f2f408ccc..f4b7c72fe 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.1.9.0327 Alpha" +const APP_VER = "0.1.9.0328 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/git.go b/models/git.go index e2ee52083..34f0267f6 100644 --- a/models/git.go +++ b/models/git.go @@ -244,11 +244,11 @@ func GetCommitsByCommitId(userName, repoName, commitId string) (*list.List, erro if err != nil { return nil, err } - r, err := repo.LookupReference(commitId) + oid, err := git.NewOidFromString(commitId) if err != nil { return nil, err } - return r.AllCommits() + return repo.CommitsBefore(oid) } // Diff line types. diff --git a/models/models.go b/models/models.go index 813725be4..bafa1747e 100644 --- a/models/models.go +++ b/models/models.go @@ -34,11 +34,11 @@ func LoadModelsConfig() { DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db") } -func setEngine() { +func SetEngine() { var err error switch DbCfg.Type { case "mysql": - orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@%s/%s?charset=utf8", + orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name)) case "postgres": orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", @@ -70,7 +70,7 @@ func setEngine() { } func NewEngine() { - setEngine() + SetEngine() if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch), new(Action), new(Access), new(Issue), new(Comment)); err != nil { fmt.Printf("sync database struct error: %v\n", err) diff --git a/models/repo.go b/models/repo.go index 726d435d3..4be655d28 100644 --- a/models/repo.go +++ b/models/repo.go @@ -510,6 +510,7 @@ func NotifyWatchers(act *Action) error { continue } + act.Id = 0 act.UserId = watches[i].UserId if _, err = orm.InsertOne(act); err != nil { return errors.New("repo.NotifyWatchers(create action): " + err.Error()) diff --git a/modules/auth/auth.go b/modules/auth/auth.go index 2e0555f6d..ac03a8f12 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -161,3 +161,53 @@ func AssignForm(form interface{}, data base.TmplData) { data[fieldName] = val.Field(i).Interface() } } + +type InstallForm struct { + Database string `form:"database" binding:"Required"` + Host string `form:"host"` + User string `form:"user"` + Passwd string `form:"passwd"` + DatabaseName string `form:"database_name"` + SslMode string `form:"ssl_mode"` + DatabasePath string `form:"database_path"` + RepoRootPath string `form:"repo_path"` + RunUser string `form:"run_user"` + AppUrl string `form:"app_url"` + AdminName string `form:"admin_name" binding:"Required"` + AdminPasswd string `form:"admin_pwd" binding:"Required;MinSize(6);MaxSize(30)"` + AdminEmail string `form:"admin_email" binding:"Required;Email;MaxSize(50)"` + SmtpHost string `form:"smtp_host"` + SmtpEmail string `form:"mailer_user"` + SmtpPasswd string `form:"mailer_pwd"` + RegisterConfirm string `form:"register_confirm"` + MailNotify string `form:"mail_notify"` +} + +func (f *InstallForm) Name(field string) string { + names := map[string]string{ + "Database": "Database name", + "AdminName": "Admin user name", + "AdminPasswd": "Admin password", + "AdminEmail": "Admin e-maill address", + } + return names[field] +} + +func (f *InstallForm) 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("InstallForm.Validate: %v", err) + } + return + } + + validate(errors, data, f) +} diff --git a/modules/base/conf.go b/modules/base/conf.go index 2e5688393..fd77cfd3c 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -38,7 +38,7 @@ var ( RunUser string RepoRootPath string - EnableHttpsClone bool + InstallLock bool LogInRememberDays int CookieUserName string @@ -282,7 +282,7 @@ func NewConfigContext() { os.Exit(2) } - EnableHttpsClone = Cfg.MustBool("security", "ENABLE_HTTPS_CLONE", false) + InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false) LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS") CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME") @@ -291,9 +291,14 @@ func NewConfigContext() { PictureService = Cfg.MustValue("picture", "SERVICE") // Determine and create root git reposiroty path. - RepoRootPath = Cfg.MustValue("repository", "ROOT") + homeDir, err := com.HomeDir() + if err != nil { + fmt.Printf("Fail to get home directory): %v\n", err) + os.Exit(2) + } + RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "git/gogs-repositories")) if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil { - fmt.Printf("models.init(fail to create RepoRootPath(%s)): %v\n", RepoRootPath, err) + fmt.Printf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err) os.Exit(2) } } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index cb4a8632a..54b735af0 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -71,12 +71,8 @@ func RepoAssignment(redirect bool) martini.Handler { ctx.Repo.IsWatching = models.IsWatching(ctx.User.Id, repo.Id) } ctx.Repo.Repository = repo - scheme := "http" - if base.EnableHttpsClone { - scheme = "https" - } ctx.Repo.CloneLink.SSH = fmt.Sprintf("%s@%s:%s/%s.git", base.RunUser, base.Domain, user.LowerName, repo.LowerName) - ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s://%s/%s/%s.git", scheme, base.Domain, user.LowerName, repo.LowerName) + ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s%s/%s.git", base.AppUrl, user.LowerName, repo.LowerName) if len(params["branchname"]) == 0 { params["branchname"] = "master" diff --git a/public/css/gogs.css b/public/css/gogs.css index d4976460e..d6c117c84 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -856,6 +856,7 @@ html, body { .commit-list .sha a { font-family: Consolas, Menlo, Monaco, "Lucida Console", monospace; + font-size: 14px; } .guide-box pre, .guide-box .input-group { @@ -1165,7 +1166,7 @@ html, body { font-weight: normal; } -#issue .issue-child .panel-heading .user { +#issue .issue-child .panel-heading .user,#issue .issue-closed a.user,#issue .issue-opened a.user { font-weight: bold; } @@ -1173,6 +1174,10 @@ html, body { border-color: #CCC; } +#issue .issue-is-closed .issue-line{ + display: none; +} + #issue .issue-head .info .btn { margin-top: -8px; margin-left: 8px; @@ -1188,6 +1193,20 @@ html, body { width: 60%; } +#issue .issue-closed .issue-content,#issue .issue-opened .issue-content{ + line-height: 42px; +} + +#issue .issue-closed{ + border-bottom: 3px solid #CCC; + margin-bottom: 24px; + padding-bottom: 24px; +} + +#issue .issue-closed .btn-danger,#issue .issue-opened .btn-success{ + margin: 0 .8em; +} + /* wrapper and footer */ #wrapper { diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 0b5e3d8e7..f303439fd 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -141,7 +141,6 @@ func Config(ctx *middleware.Context) { ctx.Data["Domain"] = base.Domain ctx.Data["RunUser"] = base.RunUser ctx.Data["RunMode"] = strings.Title(martini.Env) - ctx.Data["EnableHttpsClone"] = base.EnableHttpsClone ctx.Data["RepoRootPath"] = base.RepoRootPath ctx.Data["Service"] = base.Service diff --git a/routers/install.go b/routers/install.go index d7d5159ef..b5c3a9364 100644 --- a/routers/install.go +++ b/routers/install.go @@ -4,10 +4,30 @@ package routers -import "github.com/gogits/gogs/modules/middleware" +import ( + "errors" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/auth" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware" +) + +func Install(ctx *middleware.Context, form auth.InstallForm) { + if base.InstallLock { + ctx.Handle(404, "install.Install", errors.New("Installation is prohibited")) + return + } -func Install(ctx *middleware.Context){ - ctx.Data["PageIsInstall"] = true ctx.Data["Title"] = "Install" - ctx.HTML(200,"install") + ctx.Data["DbCfg"] = models.DbCfg + ctx.Data["RepoRootPath"] = base.RepoRootPath + ctx.Data["RunUser"] = base.RunUser + ctx.Data["AppUrl"] = base.AppUrl + ctx.Data["PageIsInstall"] = true + + if ctx.Req.Method == "GET" { + ctx.HTML(200, "install") + return + } } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 77e35bbae..6ac8a5357 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -40,9 +40,7 @@ func Issues(ctx *middleware.Context) { ctx.Redirect("/user/login/", 302) return } - posterId = ctx.User.Id ctx.Data["ViewType"] = "created_by" - ctx.Data["IssueCreatedCount"] = models.GetUserIssueCount(posterId, ctx.Repo.Repository.Id) } // Get issues. @@ -53,6 +51,11 @@ func Issues(ctx *middleware.Context) { return } + if ctx.IsSigned { + posterId = ctx.User.Id + } + var createdByCount int + // Get posters. for i := range issues { u, err := models.GetUserById(issues[i].PosterId) @@ -61,12 +64,16 @@ func Issues(ctx *middleware.Context) { return } issues[i].Poster = u + if u.Id == posterId { + createdByCount++ + } } ctx.Data["Issues"] = issues ctx.Data["IssueCount"] = ctx.Repo.Repository.NumIssues ctx.Data["OpenCount"] = ctx.Repo.Repository.NumIssues - ctx.Repo.Repository.NumClosedIssues ctx.Data["ClosedCount"] = ctx.Repo.Repository.NumClosedIssues + ctx.Data["IssueCreatedCount"] = createdByCount ctx.Data["IsShowClosed"] = ctx.Query("state") == "closed" ctx.HTML(200, "issue/list") } @@ -224,6 +231,12 @@ func Comment(ctx *middleware.Context, params martini.Params) { return } + content := ctx.Query("content") + if len(content) == 0 { + ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", ctx.User.Name, ctx.Repo.Repository.Name, index)) + return + } + issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, int64(index)) if err != nil { if err == models.ErrIssueNotExist { @@ -234,12 +247,6 @@ func Comment(ctx *middleware.Context, params martini.Params) { return } - content := ctx.Query("content") - if len(content) == 0 { - ctx.Handle(404, "issue.Comment", err) - return - } - switch params["action"] { case "new": if err = models.CreateComment(ctx.User.Id, issue.Id, 0, 0, content); err != nil { diff --git a/serve.go b/serve.go index 96f03e724..ad31260f0 100644 --- a/serve.go +++ b/serve.go @@ -78,7 +78,7 @@ func runServ(k *cli.Context) { base.NewConfigContext() models.LoadModelsConfig() - models.NewEngine() + models.SetEngine() keys := strings.Split(os.Args[2], "-") if len(keys) != 2 { diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index 39895aa31..ab805d8de 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -17,7 +17,6 @@
Run User: {{.RunUser}}
Run Mode: {{.RunMode}}

-
Enable HTTPS Clone
Repository Root Path: {{.RepoRootPath}}
diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl index 829ecba62..7d1f64e49 100644 --- a/templates/base/navbar.tmpl +++ b/templates/base/navbar.tmpl @@ -3,7 +3,7 @@ - \ No newline at end of file + diff --git a/update.go b/update.go index 1c14c33d7..faec0029a 100644 --- a/update.go +++ b/update.go @@ -32,7 +32,7 @@ gogs serv provide access auth for repositories`, func runUpdate(c *cli.Context) { base.NewConfigContext() models.LoadModelsConfig() - models.NewEngine() + models.SetEngine() w, _ := os.Create("update.log") defer w.Close() diff --git a/web.go b/web.go index 4ed273ea9..35695f0bf 100644 --- a/web.go +++ b/web.go @@ -90,7 +90,7 @@ func runWeb(*cli.Context) { // Routers. m.Get("/", ignSignIn, routers.Home) - m.Get("/install", routers.Install) + m.Any("/install", routers.Install) m.Get("/issues", reqSignIn, user.Issues) m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars)