From f160b4f33ca69df13b071648aad09e561dafec26 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 8 Jun 2014 17:53:53 -0400 Subject: Add tar.gz download button and other mirror updates --- routers/admin/user.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'routers/admin/user.go') diff --git a/routers/admin/user.go b/routers/admin/user.go index fa98bd32..596fe7b1 100644 --- a/routers/admin/user.go +++ b/routers/admin/user.go @@ -51,12 +51,13 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { Email: form.Email, Passwd: form.Password, IsActive: true, - LoginType: models.LT_PLAIN, + LoginType: models.PLAIN, } if len(form.LoginType) > 0 { fields := strings.Split(form.LoginType, "-") - u.LoginType, _ = strconv.Atoi(fields[0]) + tp, _ := strconv.Atoi(fields[0]) + u.LoginType = models.LoginType(tp) u.LoginSource, _ = strconv.ParseInt(fields[1], 10, 64) u.LoginName = form.LoginName fmt.Println(u.LoginType, u.LoginSource, u.LoginName) -- cgit v1.2.3 From 9924e65ca11770f247723b10fcbdb81dc9534b32 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 22 Jun 2014 13:14:03 -0400 Subject: In progress of name template name constant --- modules/base/base.go | 1 + modules/mailer/mail.go | 19 ++- modules/middleware/context.go | 8 +- routers/admin/admin.go | 27 ++-- routers/admin/auth.go | 201 +++++++++++++++++++++++++++ routers/admin/auths.go | 196 -------------------------- routers/admin/user.go | 48 ++++--- routers/dashboard.go | 7 +- routers/dev/template.go | 3 +- routers/install.go | 26 ++-- routers/repo/repo.go | 2 +- templates/admin/auth/edit.tmpl | 165 ++++++++++++++++++++++ templates/admin/auth/new.tmpl | 178 ++++++++++++++++++++++++ templates/admin/auths/edit.tmpl | 165 ---------------------- templates/admin/auths/new.tmpl | 178 ------------------------ templates/admin/user/edit.tmpl | 103 ++++++++++++++ templates/admin/user/new.tmpl | 94 +++++++++++++ templates/admin/users/edit.tmpl | 103 -------------- templates/admin/users/new.tmpl | 94 ------------- templates/issue/create.tmpl | 112 --------------- templates/issue/list.tmpl | 116 ---------------- templates/issue/milestone.tmpl | 43 ------ templates/issue/milestone_edit.tmpl | 61 --------- templates/issue/milestone_new.tmpl | 62 --------- templates/issue/view.tmpl | 228 ------------------------------- templates/mail/auth/active.tmpl | 33 +++++ templates/mail/auth/active_email.tmpl | 33 ----- templates/release/edit.tmpl | 70 ---------- templates/release/list.tmpl | 62 --------- templates/release/new.tmpl | 70 ---------- templates/repo/issue/create.tmpl | 112 +++++++++++++++ templates/repo/issue/list.tmpl | 116 ++++++++++++++++ templates/repo/issue/milestone.tmpl | 43 ++++++ templates/repo/issue/milestone_edit.tmpl | 61 +++++++++ templates/repo/issue/milestone_new.tmpl | 62 +++++++++ templates/repo/issue/view.tmpl | 228 +++++++++++++++++++++++++++++++ templates/repo/release/edit.tmpl | 70 ++++++++++ templates/repo/release/list.tmpl | 62 +++++++++ templates/repo/release/new.tmpl | 70 ++++++++++ 39 files changed, 1688 insertions(+), 1644 deletions(-) create mode 100644 routers/admin/auth.go delete mode 100644 routers/admin/auths.go create mode 100644 templates/admin/auth/edit.tmpl create mode 100644 templates/admin/auth/new.tmpl delete mode 100644 templates/admin/auths/edit.tmpl delete mode 100644 templates/admin/auths/new.tmpl create mode 100644 templates/admin/user/edit.tmpl create mode 100644 templates/admin/user/new.tmpl delete mode 100644 templates/admin/users/edit.tmpl delete mode 100644 templates/admin/users/new.tmpl delete mode 100644 templates/issue/create.tmpl delete mode 100644 templates/issue/list.tmpl delete mode 100644 templates/issue/milestone.tmpl delete mode 100644 templates/issue/milestone_edit.tmpl delete mode 100644 templates/issue/milestone_new.tmpl delete mode 100644 templates/issue/view.tmpl create mode 100644 templates/mail/auth/active.tmpl delete mode 100644 templates/mail/auth/active_email.tmpl delete mode 100644 templates/release/edit.tmpl delete mode 100644 templates/release/list.tmpl delete mode 100644 templates/release/new.tmpl create mode 100644 templates/repo/issue/create.tmpl create mode 100644 templates/repo/issue/list.tmpl create mode 100644 templates/repo/issue/milestone.tmpl create mode 100644 templates/repo/issue/milestone_edit.tmpl create mode 100644 templates/repo/issue/milestone_new.tmpl create mode 100644 templates/repo/issue/view.tmpl create mode 100644 templates/repo/release/edit.tmpl create mode 100644 templates/repo/release/list.tmpl create mode 100644 templates/repo/release/new.tmpl (limited to 'routers/admin/user.go') diff --git a/modules/base/base.go b/modules/base/base.go index 145fae6f..570600c3 100644 --- a/modules/base/base.go +++ b/modules/base/base.go @@ -7,6 +7,7 @@ package base type ( // Type TmplData represents data in the templates. TmplData map[string]interface{} + TplName string ApiJsonErr struct { Message string `json:"message"` diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go index e212d006..62e15cd7 100644 --- a/modules/mailer/mail.go +++ b/modules/mailer/mail.go @@ -17,6 +17,15 @@ import ( "github.com/gogits/gogs/modules/setting" ) +const ( + AUTH_ACTIVE base.TplName = "mail/auth/active" + AUTH_REGISTER_SUCCESS base.TplName = "mail/auth/register_success" + AUTH_RESET_PASSWORD base.TplName = "mail/auth/reset_passwd" + + NOTIFY_COLLABORATOR base.TplName = "mail/notify/collaborator" + NOTIFY_MENTION base.TplName = "mail/notify/mention" +) + // Create New mail message use MailFrom and MailUser func NewMailMessageFrom(To []string, from, subject, body string) Message { msg := NewHtmlMessage(To, from, subject, body) @@ -61,7 +70,7 @@ func SendRegisterMail(r *middleware.Render, u *models.User) { data := GetMailTmplData(u) data["Code"] = code - body, err := r.HTMLString("mail/auth/register_success", data) + body, err := r.HTMLString(string(AUTH_REGISTER_SUCCESS), data) if err != nil { log.Error("mail.SendRegisterMail(fail to render): %v", err) return @@ -81,7 +90,7 @@ func SendActiveMail(r *middleware.Render, u *models.User) { data := GetMailTmplData(u) data["Code"] = code - body, err := r.HTMLString("mail/auth/active_email", data) + body, err := r.HTMLString(string(AUTH_ACTIVE), data) if err != nil { log.Error("mail.SendActiveMail(fail to render): %v", err) return @@ -101,7 +110,7 @@ func SendResetPasswdMail(r *middleware.Render, u *models.User) { data := GetMailTmplData(u) data["Code"] = code - body, err := r.HTMLString("mail/auth/reset_passwd", data) + body, err := r.HTMLString(string(AUTH_RESET_PASSWORD), data) if err != nil { log.Error("mail.SendResetPasswdMail(fail to render): %v", err) return @@ -161,7 +170,7 @@ func SendIssueMentionMail(r *middleware.Render, u, owner *models.User, data["IssueLink"] = fmt.Sprintf("%s/%s/issues/%d", owner.Name, repo.Name, issue.Index) data["Subject"] = subject - body, err := r.HTMLString("mail/notify/mention", data) + body, err := r.HTMLString(string(NOTIFY_MENTION), data) if err != nil { return fmt.Errorf("mail.SendIssueMentionMail(fail to render): %v", err) } @@ -182,7 +191,7 @@ func SendCollaboratorMail(r *middleware.Render, u, owner *models.User, data["RepoLink"] = path.Join(owner.Name, repo.Name) data["Subject"] = subject - body, err := r.HTMLString("mail/notify/collaborator", data) + body, err := r.HTMLString(string(NOTIFY_COLLABORATOR), data) if err != nil { return fmt.Errorf("mail.SendCollaboratorMail(fail to render): %v", err) } diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 19556118..45f0140a 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -104,12 +104,12 @@ func (ctx *Context) HasError() bool { } // HTML calls render.HTML underlying but reduce one argument. -func (ctx *Context) HTML(status int, name string, htmlOpt ...HTMLOptions) { - ctx.Render.HTML(status, name, ctx.Data, htmlOpt...) +func (ctx *Context) HTML(status int, name base.TplName, htmlOpt ...HTMLOptions) { + ctx.Render.HTML(status, string(name), ctx.Data, htmlOpt...) } // RenderWithErr used for page has form validation but need to prompt error to users. -func (ctx *Context) RenderWithErr(msg, tpl string, form auth.Form) { +func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form auth.Form) { if form != nil { auth.AssignForm(form, ctx.Data) } @@ -133,7 +133,7 @@ func (ctx *Context) Handle(status int, title string, err error) { case 500: ctx.Data["Title"] = "Internal Server Error" } - ctx.HTML(status, fmt.Sprintf("status/%d", status)) + ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) } func (ctx *Context) Debug(msg string, args ...interface{}) { diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 1567a300..140e1e9f 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -20,6 +20,16 @@ import ( "github.com/gogits/gogs/modules/setting" ) +const ( + DASHBOARD base.TplName = "admin/dashboard" + USERS base.TplName = "admin/users" + REPOS base.TplName = "admin/repos" + AUTHS base.TplName = "admin/auths" + CONFIG base.TplName = "admin/config" + MONITOR_PROCESS base.TplName = "admin/monitor/process" + MONITOR_CRON base.TplName = "admin/monitor/cron" +) + var startTime = time.Now() var sysStatus struct { @@ -140,7 +150,7 @@ func Dashboard(ctx *middleware.Context) { ctx.Data["Stats"] = models.GetStatistic() updateSystemStatus() ctx.Data["SysStatus"] = sysStatus - ctx.HTML(200, "admin/dashboard") + ctx.HTML(200, DASHBOARD) } func Users(ctx *middleware.Context) { @@ -150,10 +160,10 @@ func Users(ctx *middleware.Context) { var err error ctx.Data["Users"], err = models.GetUsers(200, 0) if err != nil { - ctx.Handle(500, "admin.Users", err) + ctx.Handle(500, "admin.Users(GetUsers)", err) return } - ctx.HTML(200, "admin/users") + ctx.HTML(200, USERS) } func Repositories(ctx *middleware.Context) { @@ -166,7 +176,7 @@ func Repositories(ctx *middleware.Context) { ctx.Handle(500, "admin.Repositories", err) return } - ctx.HTML(200, "admin/repos") + ctx.HTML(200, REPOS) } func Auths(ctx *middleware.Context) { @@ -179,7 +189,7 @@ func Auths(ctx *middleware.Context) { ctx.Handle(500, "admin.Auths", err) return } - ctx.HTML(200, "admin/auths") + ctx.HTML(200, AUTHS) } func Config(ctx *middleware.Context) { @@ -235,7 +245,7 @@ func Config(ctx *middleware.Context) { } ctx.Data["Loggers"] = loggers - ctx.HTML(200, "admin/config") + ctx.HTML(200, CONFIG) } func Monitor(ctx *middleware.Context) { @@ -247,11 +257,10 @@ func Monitor(ctx *middleware.Context) { case "process": ctx.Data["PageIsMonitorProcess"] = true ctx.Data["Processes"] = process.Processes - ctx.HTML(200, "admin/monitor/process") + ctx.HTML(200, MONITOR_PROCESS) default: ctx.Data["PageIsMonitorCron"] = true ctx.Data["Entries"] = cron.ListEntries() - ctx.HTML(200, "admin/monitor/cron") + ctx.HTML(200, MONITOR_CRON) } - } diff --git a/routers/admin/auth.go b/routers/admin/auth.go new file mode 100644 index 00000000..ff6c0325 --- /dev/null +++ b/routers/admin/auth.go @@ -0,0 +1,201 @@ +// 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 admin + +import ( + "strings" + + "github.com/go-martini/martini" + "github.com/go-xorm/core" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/auth" + "github.com/gogits/gogs/modules/auth/ldap" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/middleware" +) + +const ( + AUTH_NEW base.TplName = "admin/auth/new" + AUTH_EDIT base.TplName = "admin/auth/edit" +) + +func NewAuthSource(ctx *middleware.Context) { + ctx.Data["Title"] = "New Authentication" + ctx.Data["PageIsAuths"] = true + ctx.Data["LoginTypes"] = models.LoginTypes + ctx.Data["SMTPAuths"] = models.SMTPAuths + ctx.HTML(200, AUTH_NEW) +} + +func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { + ctx.Data["Title"] = "New Authentication" + ctx.Data["PageIsAuths"] = true + ctx.Data["LoginTypes"] = models.LoginTypes + ctx.Data["SMTPAuths"] = models.SMTPAuths + + if ctx.HasError() { + ctx.HTML(200, AUTH_NEW) + return + } + + var u core.Conversion + switch models.LoginType(form.Type) { + case models.LDAP: + u = &models.LDAPConfig{ + Ldapsource: ldap.Ldapsource{ + Host: form.Host, + Port: form.Port, + UseSSL: form.UseSSL, + BaseDN: form.BaseDN, + Attributes: form.Attributes, + Filter: form.Filter, + MsAdSAFormat: form.MsAdSA, + Enabled: true, + Name: form.AuthName, + }, + } + case models.SMTP: + u = &models.SMTPConfig{ + Auth: form.SmtpAuth, + Host: form.SmtpHost, + Port: form.SmtpPort, + TLS: form.Tls, + } + default: + ctx.Error(400) + return + } + + var source = &models.LoginSource{ + Type: models.LoginType(form.Type), + Name: form.AuthName, + IsActived: true, + AllowAutoRegister: form.AllowAutoRegister, + Cfg: u, + } + + if err := models.CreateSource(source); err != nil { + ctx.Handle(500, "admin.auths.NewAuth(CreateSource)", err) + return + } + + log.Trace("%s Authentication created by admin(%s): %s", ctx.Req.RequestURI, + ctx.User.LowerName, strings.ToLower(form.AuthName)) + + ctx.Redirect("/admin/auths") +} + +func EditAuthSource(ctx *middleware.Context, params martini.Params) { + ctx.Data["Title"] = "Edit Authentication" + ctx.Data["PageIsAuths"] = true + ctx.Data["LoginTypes"] = models.LoginTypes + ctx.Data["SMTPAuths"] = models.SMTPAuths + + id, err := base.StrTo(params["authid"]).Int64() + if err != nil { + ctx.Handle(404, "admin.auths.EditAuthSource", err) + return + } + u, err := models.GetLoginSourceById(id) + if err != nil { + ctx.Handle(500, "admin.user.EditUser(GetLoginSourceById)", err) + return + } + ctx.Data["Source"] = u + ctx.HTML(200, AUTH_EDIT) +} + +func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { + ctx.Data["Title"] = "Edit Authentication" + ctx.Data["PageIsAuths"] = true + ctx.Data["LoginTypes"] = models.LoginTypes + ctx.Data["SMTPAuths"] = models.SMTPAuths + + if ctx.HasError() { + ctx.HTML(200, AUTH_EDIT) + return + } + + var config core.Conversion + switch models.LoginType(form.Type) { + case models.LDAP: + config = &models.LDAPConfig{ + Ldapsource: ldap.Ldapsource{ + Host: form.Host, + Port: form.Port, + UseSSL: form.UseSSL, + BaseDN: form.BaseDN, + Attributes: form.Attributes, + Filter: form.Filter, + MsAdSAFormat: form.MsAdSA, + Enabled: true, + Name: form.AuthName, + }, + } + case models.SMTP: + config = &models.SMTPConfig{ + Auth: form.SmtpAuth, + Host: form.SmtpHost, + Port: form.SmtpPort, + TLS: form.Tls, + } + default: + ctx.Error(400) + return + } + + u := models.LoginSource{ + Id: form.Id, + Name: form.AuthName, + IsActived: form.IsActived, + Type: models.LoginType(form.Type), + AllowAutoRegister: form.AllowAutoRegister, + Cfg: config, + } + + if err := models.UpdateSource(&u); err != nil { + ctx.Handle(500, "admin.auths.EditAuth(UpdateSource)", err) + return + } + + log.Trace("%s Authentication changed by admin(%s): %s", ctx.Req.RequestURI, + ctx.User.LowerName, form.AuthName) + + ctx.Redirect("/admin/auths") +} + +func DeleteAuthSource(ctx *middleware.Context, params martini.Params) { + ctx.Data["Title"] = "Delete Authentication" + ctx.Data["PageIsAuths"] = true + + id, err := base.StrTo(params["authid"]).Int64() + if err != nil { + ctx.Handle(404, "admin.auths.DeleteAuth", err) + return + } + + a, err := models.GetLoginSourceById(id) + if err != nil { + ctx.Handle(500, "admin.auths.DeleteAuth(GetLoginSourceById)", err) + return + } + + if err = models.DelLoginSource(a); err != nil { + switch err { + case models.ErrAuthenticationUserUsed: + ctx.Flash.Error("This authentication still has used by some users, you should move them and then delete again.") + ctx.Redirect("/admin/auths/" + params["authid"]) + default: + ctx.Handle(500, "admin.auths.DeleteAuth(DelLoginSource)", err) + } + return + } + log.Trace("%s Authentication deleted by admin(%s): %s", ctx.Req.RequestURI, + ctx.User.LowerName, ctx.User.LowerName) + + ctx.Redirect("/admin/auths") +} diff --git a/routers/admin/auths.go b/routers/admin/auths.go deleted file mode 100644 index e0b99714..00000000 --- a/routers/admin/auths.go +++ /dev/null @@ -1,196 +0,0 @@ -// 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 admin - -import ( - "strings" - - "github.com/go-martini/martini" - "github.com/go-xorm/core" - - "github.com/gogits/gogs/models" - "github.com/gogits/gogs/modules/auth" - "github.com/gogits/gogs/modules/auth/ldap" - "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/log" - "github.com/gogits/gogs/modules/middleware" -) - -func NewAuthSource(ctx *middleware.Context) { - ctx.Data["Title"] = "New Authentication" - ctx.Data["PageIsAuths"] = true - ctx.Data["LoginTypes"] = models.LoginTypes - ctx.Data["SMTPAuths"] = models.SMTPAuths - ctx.HTML(200, "admin/auths/new") -} - -func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { - ctx.Data["Title"] = "New Authentication" - ctx.Data["PageIsAuths"] = true - ctx.Data["LoginTypes"] = models.LoginTypes - ctx.Data["SMTPAuths"] = models.SMTPAuths - - if ctx.HasError() { - ctx.HTML(200, "admin/auths/new") - return - } - - var u core.Conversion - switch models.LoginType(form.Type) { - case models.LDAP: - u = &models.LDAPConfig{ - Ldapsource: ldap.Ldapsource{ - Host: form.Host, - Port: form.Port, - UseSSL: form.UseSSL, - BaseDN: form.BaseDN, - Attributes: form.Attributes, - Filter: form.Filter, - MsAdSAFormat: form.MsAdSA, - Enabled: true, - Name: form.AuthName, - }, - } - case models.SMTP: - u = &models.SMTPConfig{ - Auth: form.SmtpAuth, - Host: form.SmtpHost, - Port: form.SmtpPort, - TLS: form.Tls, - } - default: - ctx.Error(400) - return - } - - var source = &models.LoginSource{ - Type: models.LoginType(form.Type), - Name: form.AuthName, - IsActived: true, - AllowAutoRegister: form.AllowAutoRegister, - Cfg: u, - } - - if err := models.CreateSource(source); err != nil { - ctx.Handle(500, "admin.auths.NewAuth", err) - return - } - - log.Trace("%s Authentication created by admin(%s): %s", ctx.Req.RequestURI, - ctx.User.LowerName, strings.ToLower(form.AuthName)) - - ctx.Redirect("/admin/auths") -} - -func EditAuthSource(ctx *middleware.Context, params martini.Params) { - ctx.Data["Title"] = "Edit Authentication" - ctx.Data["PageIsAuths"] = true - ctx.Data["LoginTypes"] = models.LoginTypes - ctx.Data["SMTPAuths"] = models.SMTPAuths - - id, err := base.StrTo(params["authid"]).Int64() - if err != nil { - ctx.Handle(404, "admin.auths.EditAuthSource", err) - return - } - u, err := models.GetLoginSourceById(id) - if err != nil { - ctx.Handle(500, "admin.user.EditUser", err) - return - } - ctx.Data["Source"] = u - ctx.HTML(200, "admin/auths/edit") -} - -func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { - ctx.Data["Title"] = "Edit Authentication" - ctx.Data["PageIsAuths"] = true - ctx.Data["LoginTypes"] = models.LoginTypes - ctx.Data["SMTPAuths"] = models.SMTPAuths - - if ctx.HasError() { - ctx.HTML(200, "admin/auths/edit") - return - } - - var config core.Conversion - switch models.LoginType(form.Type) { - case models.LDAP: - config = &models.LDAPConfig{ - Ldapsource: ldap.Ldapsource{ - Host: form.Host, - Port: form.Port, - UseSSL: form.UseSSL, - BaseDN: form.BaseDN, - Attributes: form.Attributes, - Filter: form.Filter, - MsAdSAFormat: form.MsAdSA, - Enabled: true, - Name: form.AuthName, - }, - } - case models.SMTP: - config = &models.SMTPConfig{ - Auth: form.SmtpAuth, - Host: form.SmtpHost, - Port: form.SmtpPort, - TLS: form.Tls, - } - default: - ctx.Error(400) - return - } - - u := models.LoginSource{ - Id: form.Id, - Name: form.AuthName, - IsActived: form.IsActived, - Type: models.LoginType(form.Type), - AllowAutoRegister: form.AllowAutoRegister, - Cfg: config, - } - - if err := models.UpdateSource(&u); err != nil { - ctx.Handle(500, "admin.auths.EditAuth", err) - return - } - - log.Trace("%s Authentication changed by admin(%s): %s", ctx.Req.RequestURI, - ctx.User.LowerName, form.AuthName) - - ctx.Redirect("/admin/auths") -} - -func DeleteAuthSource(ctx *middleware.Context, params martini.Params) { - ctx.Data["Title"] = "Delete Authentication" - ctx.Data["PageIsAuths"] = true - - id, err := base.StrTo(params["authid"]).Int64() - if err != nil { - ctx.Handle(404, "admin.auths.DeleteAuth", err) - return - } - - a, err := models.GetLoginSourceById(id) - if err != nil { - ctx.Handle(500, "admin.auths.DeleteAuth", err) - return - } - - if err = models.DelLoginSource(a); err != nil { - switch err { - case models.ErrAuthenticationUserUsed: - ctx.Flash.Error("This authentication still has used by some users, you should move them and then delete again.") - ctx.Redirect("/admin/auths/" + params["authid"]) - default: - ctx.Handle(500, "admin.auths.DeleteAuth", err) - } - return - } - log.Trace("%s Authentication deleted by admin(%s): %s", ctx.Req.RequestURI, - ctx.User.LowerName, ctx.User.LowerName) - - ctx.Redirect("/admin/auths") -} diff --git a/routers/admin/user.go b/routers/admin/user.go index 596fe7b1..d1bbb480 100644 --- a/routers/admin/user.go +++ b/routers/admin/user.go @@ -5,8 +5,6 @@ package admin import ( - "fmt" - "strconv" "strings" "github.com/go-martini/martini" @@ -18,16 +16,21 @@ import ( "github.com/gogits/gogs/modules/middleware" ) +const ( + USER_NEW base.TplName = "admin/user/new" + USER_EDIT base.TplName = "admin/user/edit" +) + func NewUser(ctx *middleware.Context) { ctx.Data["Title"] = "New Account" ctx.Data["PageIsUsers"] = true auths, err := models.GetAuths() if err != nil { - ctx.Handle(500, "admin.user.NewUser", err) + ctx.Handle(500, "admin.user.NewUser(GetAuths)", err) return } ctx.Data["LoginSources"] = auths - ctx.HTML(200, "admin/users/new") + ctx.HTML(200, USER_NEW) } func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { @@ -35,7 +38,7 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { ctx.Data["PageIsUsers"] = true if ctx.HasError() { - ctx.HTML(200, "admin/users/new") + ctx.HTML(200, USER_NEW) return } @@ -55,25 +58,25 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { } if len(form.LoginType) > 0 { + // NOTE: need rewrite. fields := strings.Split(form.LoginType, "-") - tp, _ := strconv.Atoi(fields[0]) + tp, _ := base.StrTo(fields[0]).Int() u.LoginType = models.LoginType(tp) - u.LoginSource, _ = strconv.ParseInt(fields[1], 10, 64) + u.LoginSource, _ = base.StrTo(fields[1]).Int64() u.LoginName = form.LoginName - fmt.Println(u.LoginType, u.LoginSource, u.LoginName) } var err error if u, err = models.RegisterUser(u); err != nil { switch err { case models.ErrUserAlreadyExist: - ctx.RenderWithErr("Username has been already taken", "admin/users/new", &form) + ctx.RenderWithErr("Username has been already taken", USER_NEW, &form) case models.ErrEmailAlreadyUsed: - ctx.RenderWithErr("E-mail address has been already used", "admin/users/new", &form) + ctx.RenderWithErr("E-mail address has been already used", USER_NEW, &form) case models.ErrUserNameIllegal: - ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "admin/users/new", &form) + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), USER_NEW, &form) default: - ctx.Handle(500, "admin.user.NewUser", err) + ctx.Handle(500, "admin.user.NewUser(RegisterUser)", err) } return } @@ -96,18 +99,18 @@ func EditUser(ctx *middleware.Context, params martini.Params) { u, err := models.GetUserById(int64(uid)) if err != nil { - ctx.Handle(500, "admin.user.EditUser", err) + ctx.Handle(500, "admin.user.EditUser(GetUserById)", err) return } ctx.Data["User"] = u auths, err := models.GetAuths() if err != nil { - ctx.Handle(500, "admin.user.NewUser", err) + ctx.Handle(500, "admin.user.NewUser(GetAuths)", err) return } ctx.Data["LoginSources"] = auths - ctx.HTML(200, "admin/users/edit") + ctx.HTML(200, USER_EDIT) } func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.AdminEditUserForm) { @@ -116,13 +119,18 @@ func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.Admi uid, err := base.StrTo(params["userid"]).Int() if err != nil { - ctx.Handle(404, "admin.user.EditUser", err) + ctx.Handle(404, "admin.user.EditUserPost", err) return } u, err := models.GetUserById(int64(uid)) if err != nil { - ctx.Handle(500, "admin.user.EditUser", err) + ctx.Handle(500, "admin.user.EditUserPost(GetUserById)", err) + return + } + + if ctx.HasError() { + ctx.HTML(200, USER_EDIT) return } @@ -134,7 +142,7 @@ func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.Admi u.IsActive = form.Active u.IsAdmin = form.Admin if err := models.UpdateUser(u); err != nil { - ctx.Handle(500, "admin.user.EditUser", err) + ctx.Handle(500, "admin.user.EditUserPost(UpdateUser)", err) return } log.Trace("%s User profile updated by admin(%s): %s", ctx.Req.RequestURI, @@ -152,13 +160,13 @@ func DeleteUser(ctx *middleware.Context, params martini.Params) { //log.Info("delete") uid, err := base.StrTo(params["userid"]).Int() if err != nil { - ctx.Handle(404, "admin.user.EditUser", err) + ctx.Handle(404, "admin.user.DeleteUser", err) return } u, err := models.GetUserById(int64(uid)) if err != nil { - ctx.Handle(500, "admin.user.EditUser", err) + ctx.Handle(500, "admin.user.DeleteUser(GetUserById)", err) return } diff --git a/routers/dashboard.go b/routers/dashboard.go index 438d0379..d65c403c 100644 --- a/routers/dashboard.go +++ b/routers/dashboard.go @@ -6,11 +6,16 @@ package routers import ( "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/routers/user" ) +const ( + HOME base.TplName = "home" +) + func Home(ctx *middleware.Context) { if ctx.IsSigned { user.Dashboard(ctx) @@ -40,7 +45,7 @@ func Home(ctx *middleware.Context) { } } ctx.Data["Repos"] = repos - ctx.HTML(200, "home") + ctx.HTML(200, HOME) } func NotFound(ctx *middleware.Context) { diff --git a/routers/dev/template.go b/routers/dev/template.go index 5e84d76e..da477c94 100644 --- a/routers/dev/template.go +++ b/routers/dev/template.go @@ -8,6 +8,7 @@ import ( "github.com/go-martini/martini" "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" ) @@ -22,5 +23,5 @@ func TemplatePreview(ctx *middleware.Context, params martini.Params) { ctx.Data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60 ctx.Data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60 ctx.Data["CurDbValue"] = "" - ctx.HTML(200, params["_1"]) + ctx.HTML(200, base.TplName(params["_1"])) } diff --git a/routers/install.go b/routers/install.go index c2eee88a..6ce7c980 100644 --- a/routers/install.go +++ b/routers/install.go @@ -26,6 +26,10 @@ import ( "github.com/gogits/gogs/modules/social" ) +const ( + INSTALL base.TplName = "install" +) + func checkRunMode() { switch setting.Cfg.MustValue("", "RUN_MODE") { case "prod": @@ -72,6 +76,7 @@ func renderDbOption(ctx *middleware.Context) { ctx.Data["DbOptions"] = []string{"MySQL", "PostgreSQL", "SQLite3"} } +// @router /install [get] func Install(ctx *middleware.Context, form auth.InstallForm) { if setting.InstallLock { ctx.Handle(404, "install.Install", errors.New("Installation is prohibited")) @@ -119,12 +124,12 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { ctx.Data["CurDbOption"] = curDbOp auth.AssignForm(form, ctx.Data) - ctx.HTML(200, "install") + ctx.HTML(200, INSTALL) } func InstallPost(ctx *middleware.Context, form auth.InstallForm) { if setting.InstallLock { - ctx.Handle(404, "install.Install", errors.New("Installation is prohibited")) + ctx.Handle(404, "install.InstallPost", errors.New("Installation is prohibited")) return } @@ -135,12 +140,12 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { ctx.Data["CurDbOption"] = form.Database if ctx.HasError() { - ctx.HTML(200, "install") + ctx.HTML(200, INSTALL) return } if _, err := exec.LookPath("git"); err != nil { - ctx.RenderWithErr("Fail to test 'git' command: "+err.Error(), "install", &form) + ctx.RenderWithErr("Fail to test 'git' command: "+err.Error(), INSTALL, &form) return } @@ -158,18 +163,19 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { // Set test engine. var x *xorm.Engine if err := models.NewTestEngine(x); err != nil { + // NOTE: should use core.QueryDriver (github.com/go-xorm/core) if strings.Contains(err.Error(), `Unknown database type: sqlite3`) { ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+ - "from http://gogs.io/docs/installation/install_from_binary.md, NOT the gobuild version.", "install", &form) + "from http://gogs.io/docs/installation/install_from_binary.md, NOT the gobuild version.", INSTALL, &form) } else { - ctx.RenderWithErr("Database setting is not correct: "+err.Error(), "install", &form) + ctx.RenderWithErr("Database setting is not correct: "+err.Error(), INSTALL, &form) } return } // Test repository root path. if err := os.MkdirAll(form.RepoRootPath, os.ModePerm); err != nil { - ctx.RenderWithErr("Repository root path is invalid: "+err.Error(), "install", &form) + ctx.RenderWithErr("Repository root path is invalid: "+err.Error(), INSTALL, &form) return } @@ -180,7 +186,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { } // Does not check run user when the install lock is off. if form.RunUser != curUser { - ctx.RenderWithErr("Run user isn't the current user: "+form.RunUser+" -> "+curUser, "install", &form) + ctx.RenderWithErr("Run user isn't the current user: "+form.RunUser+" -> "+curUser, INSTALL, &form) return } @@ -214,7 +220,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { os.MkdirAll("custom/conf", os.ModePerm) if err := goconfig.SaveConfigFile(setting.Cfg, path.Join(setting.CustomPath, "conf/app.ini")); err != nil { - ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form) + ctx.RenderWithErr("Fail to save configuration: "+err.Error(), INSTALL, &form) return } @@ -225,7 +231,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { IsAdmin: true, IsActive: true}); err != nil { if err != models.ErrUserAlreadyExist { setting.InstallLock = false - ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form) + ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), INSTALL, &form) return } log.Info("Admin account already exist") diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 6db45300..6154eede 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -318,7 +318,7 @@ func basicDecode(encoded string) (user string, name string, err error) { func authRequired(ctx *middleware.Context) { ctx.ResponseWriter.Header().Set("WWW-Authenticate", "Basic realm=\".\"") ctx.Data["ErrorMsg"] = "no basic auth and digit auth" - ctx.HTML(401, fmt.Sprintf("status/401")) + ctx.HTML(401, base.TplName("status/401")) } func Action(ctx *middleware.Context, params martini.Params) { diff --git a/templates/admin/auth/edit.tmpl b/templates/admin/auth/edit.tmpl new file mode 100644 index 00000000..a2c2ddc6 --- /dev/null +++ b/templates/admin/auth/edit.tmpl @@ -0,0 +1,165 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+ {{template "admin/nav" .}} +
+
+
+ Edit Authentication +
+ +
+
+
+ {{.CsrfTokenHtml}} + {{template "base/alert" .}} + + {{$type := .Source.Type}} +
+ + + +
+
+ +
+ +
+
+ + {{if eq $type 2}} +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ {{else if eq $type 3}} +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ {{end}} + +
+ {{if eq $type 3}} +
+
+ +
+
+ {{end}} + +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+
+ + Delete this authentication +
+
+
+
+
+ +
+
+{{template "base/footer" .}} diff --git a/templates/admin/auth/new.tmpl b/templates/admin/auth/new.tmpl new file mode 100644 index 00000000..abb88043 --- /dev/null +++ b/templates/admin/auth/new.tmpl @@ -0,0 +1,178 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+ {{template "admin/nav" .}} +
+
+
+ New Authentication +
+ +
+
+
+ {{.CsrfTokenHtml}} + {{template "base/alert" .}} +
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ + + +
+
+
+ +
+
+
+ +
+ +
+
+ +
+
+
+
+
+ +
+
+ Tips +
+ +
+
GMail Setting:
+

Host: smtp.gmail.com, Post: 587, Enable TLS Encryption: true

+
+
+
+
+ +{{template "base/footer" .}} diff --git a/templates/admin/auths/edit.tmpl b/templates/admin/auths/edit.tmpl deleted file mode 100644 index a2c2ddc6..00000000 --- a/templates/admin/auths/edit.tmpl +++ /dev/null @@ -1,165 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -
- {{template "admin/nav" .}} -
-
-
- Edit Authentication -
- -
-
-
- {{.CsrfTokenHtml}} - {{template "base/alert" .}} - - {{$type := .Source.Type}} -
- - - -
-
- -
- -
-
- - {{if eq $type 2}} -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- - -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- {{else if eq $type 3}} -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- {{end}} - -
- {{if eq $type 3}} -
-
- -
-
- {{end}} - -
-
- -
-
- -
-
- -
-
-
- -
- -
-
- - Delete this authentication -
-
-
-
-
- -
-
-{{template "base/footer" .}} diff --git a/templates/admin/auths/new.tmpl b/templates/admin/auths/new.tmpl deleted file mode 100644 index abb88043..00000000 --- a/templates/admin/auths/new.tmpl +++ /dev/null @@ -1,178 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -
- {{template "admin/nav" .}} -
-
-
- New Authentication -
- -
-
-
- {{.CsrfTokenHtml}} - {{template "base/alert" .}} -
- -
- -
-
-
- -
- -
-
-
-
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- - - -
-
-
- -
-
-
- -
- -
-
- -
-
-
-
-
- -
-
- Tips -
- -
-
GMail Setting:
-

Host: smtp.gmail.com, Post: 587, Enable TLS Encryption: true

-
-
-
-
- -{{template "base/footer" .}} diff --git a/templates/admin/user/edit.tmpl b/templates/admin/user/edit.tmpl new file mode 100644 index 00000000..b1fffb69 --- /dev/null +++ b/templates/admin/user/edit.tmpl @@ -0,0 +1,103 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+ {{template "admin/nav" .}} +
+
+
+ Edit Account +
+ +
+
+
+ {{.CsrfTokenHtml}} + {{template "base/alert" .}} +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ + +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+
+
+ + Delete this account +
+
+
+
+
+ +
+
+{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/admin/user/new.tmpl b/templates/admin/user/new.tmpl new file mode 100644 index 00000000..4f4866c4 --- /dev/null +++ b/templates/admin/user/new.tmpl @@ -0,0 +1,94 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+ {{template "admin/nav" .}} +
+
+
+ New Account +
+ +
+
+
+ {{.CsrfTokenHtml}} + {{template "base/alert" .}} +
+ +
+ +
+
+ + + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+ +
+
+ +
+ +
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+ +{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/admin/users/edit.tmpl b/templates/admin/users/edit.tmpl deleted file mode 100644 index b1fffb69..00000000 --- a/templates/admin/users/edit.tmpl +++ /dev/null @@ -1,103 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -
- {{template "admin/nav" .}} -
-
-
- Edit Account -
- -
-
-
- {{.CsrfTokenHtml}} - {{template "base/alert" .}} -
- -
- -
-
- -
- -
- -
-
- -
- - -
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
- - Delete this account -
-
-
-
-
- -
-
-{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/admin/users/new.tmpl b/templates/admin/users/new.tmpl deleted file mode 100644 index 4f4866c4..00000000 --- a/templates/admin/users/new.tmpl +++ /dev/null @@ -1,94 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -
- {{template "admin/nav" .}} -
-
-
- New Account -
- -
-
-
- {{.CsrfTokenHtml}} - {{template "base/alert" .}} -
- -
- -
-
- - - -
- -
- -
-
- -
- -
- -
-
- -
-
- -
- -
-
- -
- -
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
- -{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl deleted file mode 100644 index 34cecc78..00000000 --- a/templates/issue/create.tmpl +++ /dev/null @@ -1,112 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
-
-
- {{.CsrfTokenHtml}} - {{template "base/alert" .}} -
- -
-
-
- -
-
- No one will be assigned -    -
- - -
- No milestone - -
- - -
-
-
-
- Content with Markdown -
- -
-
-
- -
-
-
loading...
-
-
-
-
- - -
-
-
-
-
-
-{{template "base/footer" .}} diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl deleted file mode 100644 index 0fae3eb6..00000000 --- a/templates/issue/list.tmpl +++ /dev/null @@ -1,116 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
-
-
- -
-

Label

- - -
-
- {{.CsrfTokenHtml}} -
New Label
-
- - - -
-
- - -
-
-
-
-
- {{template "base/alert" .}} - -
- {{range .Issues}}{{if .Poster}} -
- #{{.Index}} -
- {{.Name}} - - {{range .Labels}} - {{.Name}} - {{end}} - -
-

- - {{.Poster.Name}} - {{TimeSince .Created}} - {{.NumComments}} -

-
- {{end}}{{end}} -
-
-
-
- - - -{{template "base/footer" .}} diff --git a/templates/issue/milestone.tmpl b/templates/issue/milestone.tmpl deleted file mode 100644 index 8a5751c1..00000000 --- a/templates/issue/milestone.tmpl +++ /dev/null @@ -1,43 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
-
- -
-
- {{range .Milestones}} -
-

{{.Name}}

- {{.NumOpenIssues}} - {{.NumClosedIssues}} -

- Edit - {{if .IsClosed}} - Open - {{else}} - Close - {{end}} - Delete - Issues -

-
-

{{.RenderedContent | str2html}}

-
- {{end}} -
-
-
-
- -{{template "base/footer" .}} diff --git a/templates/issue/milestone_edit.tmpl b/templates/issue/milestone_edit.tmpl deleted file mode 100644 index 8f1a05e0..00000000 --- a/templates/issue/milestone_edit.tmpl +++ /dev/null @@ -1,61 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
-
-
- {{.CsrfTokenHtml}} - {{template "base/alert" .}} -
- -
-
-
- -
-
-
- Content with Markdown -
- -
-
-
- -
-
-
loading...
-
-
-
-
- - -
-
-
-
-

Milestone Due Date

-
- -
-
-
-
-
- - -{{template "base/footer" .}} diff --git a/templates/issue/milestone_new.tmpl b/templates/issue/milestone_new.tmpl deleted file mode 100644 index 044b7d10..00000000 --- a/templates/issue/milestone_new.tmpl +++ /dev/null @@ -1,62 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
-
-
- {{.CsrfTokenHtml}} - {{template "base/alert" .}} -
- -
-
-
- -
-
-
- Content with Markdown -
- -
-
-
- -
-
-
loading...
-
-
-
-
- - -
-
-
-
-

Milestone Due Date

- -
- -
-
-
-
-
- - -{{template "base/footer" .}} diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl deleted file mode 100644 index ba1fe16b..00000000 --- a/templates/issue/view.tmpl +++ /dev/null @@ -1,228 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
-
-
-
-
-
#{{.Issue.Index}}
- -

{{.Issue.Name}}

- - -

- {{if .IsIssueOwner}}Edit - - {{end}} - {{if .Issue.IsClosed}}Closed{{else}}Open{{end}} - {{.Issue.Poster.Name}} opened this issue - {{TimeSince .Issue.Created}} · {{.Issue.NumComments}} comments -

-
-
-
-
-
- {{str2html .Issue.RenderedContent}} -
- -
-
- {{range .Comments}} - {{if eq .Type 0}} -
- -
-
- {{.Poster.Name}} commented {{TimeSince .Created}} - - Owner -
-
- {{str2html .Content}} -
-
-
- {{else if eq .Type 1}} -
- -
- {{.Poster.Name}} Reopened this issue {{TimeSince .Created}} -
-
- {{else if eq .Type 2}} -
- -
- {{.Poster.Name}} Closed this issue {{TimeSince .Created}} -
-
- {{end}} - {{end}} -
- {{if .SignedUser}}
- -
- {{.CsrfTokenHtml}} -
-
-
Content with Markdown -
- -
-
-
- - -
-
-
Loading...
-
-
-
-
- {{if .IsIssueOwner}}{{if .Issue.IsClosed}} - {{else}} - {{end}}{{end}}   - -
-
-
-
-
{{else}}
Sign up for free to join this conversation. Already have an account? Sign in to comment
{{end}} -
-
- -
-
-
- - -
-

Labels

- {{if .Issue.Labels}} - {{range .Issue.Labels}} -

{{.Name}}

- {{end}} - {{else}} -

None yet

- {{end}} -
-
-
- - -
-

Milestone

- {{if .Milestone}} -

 

-

{{.Milestone.Name}}

- {{else}} -

No milestone

- {{end}} -
- -
{{if .IsRepositoryOwner}} -
- - -
{{end}} -

Assignee

-

{{if .Issue.Assignee}}{{.Issue.Assignee.Name}}{{else}}No one assigned{{end}}

-
-
-
-
-
-{{template "base/footer" .}} diff --git a/templates/mail/auth/active.tmpl b/templates/mail/auth/active.tmpl new file mode 100644 index 00000000..72d9948b --- /dev/null +++ b/templates/mail/auth/active.tmpl @@ -0,0 +1,33 @@ + + + + +{{.User.Name}}, please activate your account + + +
+
+
+
+

{{.AppName}}

+
+
+ Hi {{.User.Name}}, +
+
+

Please click the following link to verify your e-mail address within {{.ActiveCodeLives}} hours.

+

+ {{.AppUrl}}user/activate?code={{.Code}} +

+

Not working? Try copying and pasting it to your browser.

+
+
+
+
+
+ © 2014 Gogs: Go Git Service +
+
+
+ + diff --git a/templates/mail/auth/active_email.tmpl b/templates/mail/auth/active_email.tmpl deleted file mode 100644 index 72d9948b..00000000 --- a/templates/mail/auth/active_email.tmpl +++ /dev/null @@ -1,33 +0,0 @@ - - - - -{{.User.Name}}, please activate your account - - -
-
-
-
-

{{.AppName}}

-
-
- Hi {{.User.Name}}, -
-
-

Please click the following link to verify your e-mail address within {{.ActiveCodeLives}} hours.

-

- {{.AppUrl}}user/activate?code={{.Code}} -

-

Not working? Try copying and pasting it to your browser.

-
-
-
-
-
- © 2014 Gogs: Go Git Service -
-
-
- - diff --git a/templates/release/edit.tmpl b/templates/release/edit.tmpl deleted file mode 100644 index e437092c..00000000 --- a/templates/release/edit.tmpl +++ /dev/null @@ -1,70 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
-
-

Edit Release

- {{template "base/alert" .}} -
- {{.CsrfTokenHtml}} -
- {{.Release.TagName}} - @ -
- - - - -
-

Choose an existing tag, or create a new tag on publish

-
-
- -
-
-
- Content with Markdown -
- -
-
-
- -
-
-
loading...
-
-
-
-
- -

We’ll point out that this release is identified as non-production ready.

-
-
- - -
-
-
-
-{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/release/list.tmpl b/templates/release/list.tmpl deleted file mode 100644 index 0f02508f..00000000 --- a/templates/release/list.tmpl +++ /dev/null @@ -1,62 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
-
-

- Releases - -

- -
-
-{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/release/new.tmpl b/templates/release/new.tmpl deleted file mode 100644 index 6c5cf40c..00000000 --- a/templates/release/new.tmpl +++ /dev/null @@ -1,70 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
-
-

New Release

- {{template "base/alert" .}} -
- {{.CsrfTokenHtml}} -
- - @ -
- - - - -
-

Choose an existing tag, or create a new tag on publish

-
-
- -
-
-
- Content with Markdown -
- -
-
-
- -
-
-
loading...
-
-
-
-
- -

We’ll point out that this release is identified as non-production ready.

-
-
- - -
-
-
-
-{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/repo/issue/create.tmpl b/templates/repo/issue/create.tmpl new file mode 100644 index 00000000..34cecc78 --- /dev/null +++ b/templates/repo/issue/create.tmpl @@ -0,0 +1,112 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
+
+
+ {{.CsrfTokenHtml}} + {{template "base/alert" .}} +
+ +
+
+
+ +
+
+ No one will be assigned +    +
+ + +
+ No milestone + +
+ + +
+
+
+
+ Content with Markdown +
+ +
+
+
+ +
+
+
loading...
+
+
+
+
+ + +
+
+
+
+
+
+{{template "base/footer" .}} diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl new file mode 100644 index 00000000..0fae3eb6 --- /dev/null +++ b/templates/repo/issue/list.tmpl @@ -0,0 +1,116 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
+
+
+ +
+

Label

+ + +
+
+ {{.CsrfTokenHtml}} +
New Label
+
+ + + +
+
+ + +
+
+
+
+
+ {{template "base/alert" .}} + +
+ {{range .Issues}}{{if .Poster}} +
+ #{{.Index}} +
+ {{.Name}} + + {{range .Labels}} + {{.Name}} + {{end}} + +
+

+ + {{.Poster.Name}} + {{TimeSince .Created}} + {{.NumComments}} +

+
+ {{end}}{{end}} +
+
+
+
+ + + +{{template "base/footer" .}} diff --git a/templates/repo/issue/milestone.tmpl b/templates/repo/issue/milestone.tmpl new file mode 100644 index 00000000..8a5751c1 --- /dev/null +++ b/templates/repo/issue/milestone.tmpl @@ -0,0 +1,43 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
+
+ +
+
+ {{range .Milestones}} +
+

{{.Name}}

+ {{.NumOpenIssues}} + {{.NumClosedIssues}} +

+ Edit + {{if .IsClosed}} + Open + {{else}} + Close + {{end}} + Delete + Issues +

+
+

{{.RenderedContent | str2html}}

+
+ {{end}} +
+
+
+
+ +{{template "base/footer" .}} diff --git a/templates/repo/issue/milestone_edit.tmpl b/templates/repo/issue/milestone_edit.tmpl new file mode 100644 index 00000000..8f1a05e0 --- /dev/null +++ b/templates/repo/issue/milestone_edit.tmpl @@ -0,0 +1,61 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
+
+
+ {{.CsrfTokenHtml}} + {{template "base/alert" .}} +
+ +
+
+
+ +
+
+
+ Content with Markdown +
+ +
+
+
+ +
+
+
loading...
+
+
+
+
+ + +
+
+
+
+

Milestone Due Date

+
+ +
+
+
+
+
+ + +{{template "base/footer" .}} diff --git a/templates/repo/issue/milestone_new.tmpl b/templates/repo/issue/milestone_new.tmpl new file mode 100644 index 00000000..044b7d10 --- /dev/null +++ b/templates/repo/issue/milestone_new.tmpl @@ -0,0 +1,62 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
+
+
+ {{.CsrfTokenHtml}} + {{template "base/alert" .}} +
+ +
+
+
+ +
+
+
+ Content with Markdown +
+ +
+
+
+ +
+
+
loading...
+
+
+
+
+ + +
+
+
+
+

Milestone Due Date

+ +
+ +
+
+
+
+
+ + +{{template "base/footer" .}} diff --git a/templates/repo/issue/view.tmpl b/templates/repo/issue/view.tmpl new file mode 100644 index 00000000..ba1fe16b --- /dev/null +++ b/templates/repo/issue/view.tmpl @@ -0,0 +1,228 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
+
+
+
+
+
#{{.Issue.Index}}
+ +

{{.Issue.Name}}

+ + +

+ {{if .IsIssueOwner}}Edit + + {{end}} + {{if .Issue.IsClosed}}Closed{{else}}Open{{end}} + {{.Issue.Poster.Name}} opened this issue + {{TimeSince .Issue.Created}} · {{.Issue.NumComments}} comments +

+
+
+
+
+
+ {{str2html .Issue.RenderedContent}} +
+ +
+
+ {{range .Comments}} + {{if eq .Type 0}} +
+ +
+
+ {{.Poster.Name}} commented {{TimeSince .Created}} + + Owner +
+
+ {{str2html .Content}} +
+
+
+ {{else if eq .Type 1}} +
+ +
+ {{.Poster.Name}} Reopened this issue {{TimeSince .Created}} +
+
+ {{else if eq .Type 2}} +
+ +
+ {{.Poster.Name}} Closed this issue {{TimeSince .Created}} +
+
+ {{end}} + {{end}} +
+ {{if .SignedUser}}
+ +
+ {{.CsrfTokenHtml}} +
+
+
Content with Markdown +
+ +
+
+
+ + +
+
+
Loading...
+
+
+
+
+ {{if .IsIssueOwner}}{{if .Issue.IsClosed}} + {{else}} + {{end}}{{end}}   + +
+
+
+
+
{{else}}
Sign up for free to join this conversation. Already have an account? Sign in to comment
{{end}} +
+
+ +
+
+
+ + +
+

Labels

+ {{if .Issue.Labels}} + {{range .Issue.Labels}} +

{{.Name}}

+ {{end}} + {{else}} +

None yet

+ {{end}} +
+
+
+ + +
+

Milestone

+ {{if .Milestone}} +

 

+

{{.Milestone.Name}}

+ {{else}} +

No milestone

+ {{end}} +
+ +
{{if .IsRepositoryOwner}} +
+ + +
{{end}} +

Assignee

+

{{if .Issue.Assignee}}{{.Issue.Assignee.Name}}{{else}}No one assigned{{end}}

+
+
+
+
+
+{{template "base/footer" .}} diff --git a/templates/repo/release/edit.tmpl b/templates/repo/release/edit.tmpl new file mode 100644 index 00000000..e437092c --- /dev/null +++ b/templates/repo/release/edit.tmpl @@ -0,0 +1,70 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
+
+

Edit Release

+ {{template "base/alert" .}} +
+ {{.CsrfTokenHtml}} +
+ {{.Release.TagName}} + @ +
+ + + + +
+

Choose an existing tag, or create a new tag on publish

+
+
+ +
+
+
+ Content with Markdown +
+ +
+
+
+ +
+
+
loading...
+
+
+
+
+ +

We’ll point out that this release is identified as non-production ready.

+
+
+ + +
+
+
+
+{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl new file mode 100644 index 00000000..0f02508f --- /dev/null +++ b/templates/repo/release/list.tmpl @@ -0,0 +1,62 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
+
+

+ Releases + +

+ +
+
+{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl new file mode 100644 index 00000000..6c5cf40c --- /dev/null +++ b/templates/repo/release/new.tmpl @@ -0,0 +1,70 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
+
+

New Release

+ {{template "base/alert" .}} +
+ {{.CsrfTokenHtml}} +
+ + @ +
+ + + + +
+

Choose an existing tag, or create a new tag on publish

+
+
+ +
+
+
+ Content with Markdown +
+ +
+
+
+ +
+
+
loading...
+
+
+
+
+ +

We’ll point out that this release is identified as non-production ready.

+
+
+ + +
+
+
+
+{{template "base/footer" .}} \ No newline at end of file -- cgit v1.2.3 From e0f9c628c5ff7399167944b3d0730698487af498 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 25 Jun 2014 00:44:48 -0400 Subject: Add create organization --- cmd/serve.go | 20 ++--- cmd/web.go | 5 +- gogs.go | 2 +- models/access.go | 17 ++-- models/issue.go | 4 +- models/login.go | 4 +- models/models.go | 2 +- models/org.go | 69 ++++++++++++++++ models/repo.go | 10 ++- models/user.go | 186 +++++++++++++++++++++++++++++++++--------- modules/auth/org.go | 33 ++++++++ modules/middleware/repo.go | 4 +- routers/admin/user.go | 4 +- routers/install.go | 2 +- routers/org/org.go | 96 ++++++++++++++++++++-- routers/repo/http.go | 8 +- routers/repo/setting.go | 4 +- routers/user/home.go | 13 ++- routers/user/user.go | 7 +- templates/VERSION | 2 +- templates/org/dashboard.tmpl | 73 ----------------- templates/org/new.tmpl | 24 +----- templates/user/dashboard.tmpl | 39 ++++++--- templates/user/issues.tmpl | 3 +- 24 files changed, 436 insertions(+), 195 deletions(-) create mode 100644 models/org.go create mode 100644 modules/auth/org.go delete mode 100644 templates/org/dashboard.tmpl (limited to 'routers/admin/user.go') diff --git a/cmd/serve.go b/cmd/serve.go index 62e290d8..2a76da79 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -56,19 +56,19 @@ func parseCmd(cmd string) (string, string) { } var ( - COMMANDS_READONLY = map[string]int{ - "git-upload-pack": models.AU_WRITABLE, - "git upload-pack": models.AU_WRITABLE, - "git-upload-archive": models.AU_WRITABLE, + COMMANDS_READONLY = map[string]models.AccessType{ + "git-upload-pack": models.WRITABLE, + "git upload-pack": models.WRITABLE, + "git-upload-archive": models.WRITABLE, } - COMMANDS_WRITE = map[string]int{ - "git-receive-pack": models.AU_READABLE, - "git receive-pack": models.AU_READABLE, + COMMANDS_WRITE = map[string]models.AccessType{ + "git-receive-pack": models.READABLE, + "git receive-pack": models.READABLE, } ) -func In(b string, sl map[string]int) bool { +func In(b string, sl map[string]models.AccessType) bool { _, e := sl[b] return e } @@ -129,7 +129,7 @@ func runServ(k *cli.Context) { // Access check. switch { case isWrite: - has, err := models.HasAccess(user.Name, path.Join(repoUserName, repoName), models.AU_WRITABLE) + has, err := models.HasAccess(user.Name, path.Join(repoUserName, repoName), models.WRITABLE) if err != nil { println("Gogs: internal error:", err) log.GitLogger.Fatal("Fail to check write access:", err) @@ -152,7 +152,7 @@ func runServ(k *cli.Context) { break } - has, err := models.HasAccess(user.Name, path.Join(repoUserName, repoName), models.AU_READABLE) + has, err := models.HasAccess(user.Name, path.Join(repoUserName, repoName), models.READABLE) if err != nil { println("Gogs: internal error:", err) log.GitLogger.Fatal("Fail to check read access:", err) diff --git a/cmd/web.go b/cmd/web.go index d29183a9..878fdeac 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -188,14 +188,15 @@ func runWeb(*cli.Context) { reqOwner := middleware.RequireOwner() - m.Group("/o", func(r martini.Router) { + m.Group("/org", func(r martini.Router) { r.Get("/create", org.New) + r.Post("/create", bindIgnErr(auth.CreateOrganizationForm{}), org.NewPost) r.Get("/:org", org.Organization) r.Get("/:org/dashboard", org.Dashboard) r.Get("/:org/members", org.Members) r.Get("/:org/teams", org.Teams) r.Get("/:org/setting", org.Setting) - }) + }, reqSignIn) m.Group("/:username/:reponame", func(r martini.Router) { r.Get("/settings", repo.Setting) diff --git a/gogs.go b/gogs.go index 75d3eb4b..5c2c6ed9 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.4.5.0624 Alpha" +const APP_VER = "0.4.5.0625 Alpha" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/access.go b/models/access.go index cf31fc13..5238daba 100644 --- a/models/access.go +++ b/models/access.go @@ -11,19 +11,20 @@ import ( "github.com/go-xorm/xorm" ) -// Access types. +type AccessType int + const ( - AU_READABLE = iota + 1 - AU_WRITABLE + READABLE AccessType = iota + 1 + WRITABLE ) // Access represents the accessibility of user to repository. type Access struct { Id int64 - UserName string `xorm:"unique(s)"` - RepoName string `xorm:"unique(s)"` // / - Mode int `xorm:"unique(s)"` - Created time.Time `xorm:"created"` + UserName string `xorm:"unique(s)"` + RepoName string `xorm:"unique(s)"` // / + Mode AccessType `xorm:"unique(s)"` + Created time.Time `xorm:"created"` } // AddAccess adds new access record. @@ -59,7 +60,7 @@ func UpdateAccessWithSession(sess *xorm.Session, access *Access) error { // HasAccess returns true if someone can read or write to given repository. // The repoName should be in format /. -func HasAccess(uname, repoName string, mode int) (bool, error) { +func HasAccess(uname, repoName string, mode AccessType) (bool, error) { if len(repoName) == 0 { return false, nil } diff --git a/models/issue.go b/models/issue.go index 11f6dd4e..6d67a72b 100644 --- a/models/issue.go +++ b/models/issue.go @@ -213,9 +213,9 @@ func GetIssueCountByPoster(uid, rid int64, isClosed bool) int64 { // IssueUser represents an issue-user relation. type IssueUser struct { Id int64 - Uid int64 // User ID. + Uid int64 `xorm:"INDEX"` // User ID. IssueId int64 - RepoId int64 + RepoId int64 `xorm:"INDEX"` MilestoneId int64 IsRead bool IsAssigned bool diff --git a/models/login.go b/models/login.go index 98c5c64e..e99b61e7 100644 --- a/models/login.go +++ b/models/login.go @@ -255,7 +255,7 @@ func LoginUserLdapSource(user *User, name, passwd string, sourceId int64, cfg *L Email: mail, } - return RegisterUser(user) + return CreateUser(user) } type loginAuth struct { @@ -359,5 +359,5 @@ func LoginUserSMTPSource(user *User, name, passwd string, sourceId int64, cfg *S Passwd: passwd, Email: name, } - return RegisterUser(user) + return CreateUser(user) } diff --git a/models/models.go b/models/models.go index d6273d7f..4e65c00b 100644 --- a/models/models.go +++ b/models/models.go @@ -35,7 +35,7 @@ func init() { tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch), new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow), new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssueUser), - new(Milestone), new(Label), new(HookTask)) + new(Milestone), new(Label), new(HookTask), new(Team), new(OrgUser), new(TeamUser)) } func LoadModelsConfig() { diff --git a/models/org.go b/models/org.go new file mode 100644 index 00000000..1cfe1798 --- /dev/null +++ b/models/org.go @@ -0,0 +1,69 @@ +// 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 models + +type AuthorizeType int + +const ( + ORG_READABLE AuthorizeType = iota + 1 + ORG_WRITABLE + ORG_ADMIN +) + +// Team represents a organization team. +type Team struct { + Id int64 + OrgId int64 `xorm:"INDEX"` + Name string + Description string + Authorize AuthorizeType + NumMembers int + NumRepos int +} + +// NewTeam creates a record of new team. +func NewTeam(t *Team) error { + _, err := x.Insert(t) + return err +} + +// ________ ____ ___ +// \_____ \_______ ____ | | \______ ___________ +// / | \_ __ \/ ___\| | / ___// __ \_ __ \ +// / | \ | \/ /_/ > | /\___ \\ ___/| | \/ +// \_______ /__| \___ /|______//____ >\___ >__| +// \/ /_____/ \/ \/ + +// OrgUser represents an organization-user relation. +type OrgUser struct { + Id int64 + Uid int64 `xorm:"INDEX"` + OrgId int64 `xorm:"INDEX"` + IsPublic bool + IsOwner bool + NumTeam int +} + +// GetOrgUsersByUserId returns all organization-user relations by user ID. +func GetOrgUsersByUserId(uid int64) ([]*OrgUser, error) { + ous := make([]*OrgUser, 0, 10) + err := x.Where("uid=?", uid).Find(&ous) + return ous, err +} + +// ___________ ____ ___ +// \__ ___/___ _____ _____ | | \______ ___________ +// | |_/ __ \\__ \ / \| | / ___// __ \_ __ \ +// | |\ ___/ / __ \| Y Y \ | /\___ \\ ___/| | \/ +// |____| \___ >____ /__|_| /______//____ >\___ >__| +// \/ \/ \/ \/ \/ + +// TeamUser represents an team-user relation. +type TeamUser struct { + Id int64 + Uid int64 + OrgId int64 `xorm:"INDEX"` + TeamId int64 +} diff --git a/models/repo.go b/models/repo.go index 4ccaccbf..f0e46c71 100644 --- a/models/repo.go +++ b/models/repo.go @@ -158,7 +158,7 @@ func IsRepositoryExist(u *User, repoName string) (bool, error) { } var ( - illegalEquals = []string{"raw", "install", "api", "avatar", "user", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin"} + illegalEquals = []string{"raw", "install", "api", "avatar", "user", "org", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin"} illegalSuffixs = []string{".git"} ) @@ -483,7 +483,9 @@ func CreateRepository(user *User, name, desc, lang, license string, private, mir sess := x.NewSession() defer sess.Close() - sess.Begin() + if err = sess.Begin(); err != nil { + return nil, err + } if _, err = sess.Insert(repo); err != nil { if err2 := os.RemoveAll(repoPath); err2 != nil { @@ -495,9 +497,9 @@ func CreateRepository(user *User, name, desc, lang, license string, private, mir return nil, err } - mode := AU_WRITABLE + mode := WRITABLE if mirror { - mode = AU_READABLE + mode = READABLE } access := Access{ UserName: user.LowerName, diff --git a/models/user.go b/models/user.go index 50d81c94..2388be9a 100644 --- a/models/user.go +++ b/models/user.go @@ -21,10 +21,11 @@ import ( "github.com/gogits/gogs/modules/setting" ) -// User types. +type UserType int + const ( - UT_INDIVIDUAL = iota + 1 - UT_ORGANIZATION + INDIVIDUAL UserType = iota // Historic reason to make it starts at 0. + ORGANIZATION ) var ( @@ -50,7 +51,8 @@ type User struct { LoginType LoginType LoginSource int64 `xorm:"not null default 0"` LoginName string - Type int + Type UserType + Orgs []*User `xorm:"-"` NumFollowers int NumFollowings int NumStars int @@ -65,36 +67,60 @@ type User struct { Salt string `xorm:"VARCHAR(10)"` Created time.Time `xorm:"created"` Updated time.Time `xorm:"updated"` + + // For organization. + NumTeams int + NumMembers int } // HomeLink returns the user home page link. -func (user *User) HomeLink() string { - return "/user/" + user.Name +func (u *User) HomeLink() string { + return "/user/" + u.Name } // AvatarLink returns user gravatar link. -func (user *User) AvatarLink() string { +func (u *User) AvatarLink() string { if setting.DisableGravatar { return "/img/avatar_default.jpg" } else if setting.Service.EnableCacheAvatar { - return "/avatar/" + user.Avatar + return "/avatar/" + u.Avatar } - return "//1.gravatar.com/avatar/" + user.Avatar + return "//1.gravatar.com/avatar/" + u.Avatar } // NewGitSig generates and returns the signature of given user. -func (user *User) NewGitSig() *git.Signature { +func (u *User) NewGitSig() *git.Signature { return &git.Signature{ - Name: user.Name, - Email: user.Email, + Name: u.Name, + Email: u.Email, When: time.Now(), } } // EncodePasswd encodes password to safe format. -func (user *User) EncodePasswd() { - newPasswd := base.PBKDF2([]byte(user.Passwd), []byte(user.Salt), 10000, 50, sha256.New) - user.Passwd = fmt.Sprintf("%x", newPasswd) +func (u *User) EncodePasswd() { + newPasswd := base.PBKDF2([]byte(u.Passwd), []byte(u.Salt), 10000, 50, sha256.New) + u.Passwd = fmt.Sprintf("%x", newPasswd) +} + +func (u *User) IsOrganization() bool { + return u.Type == ORGANIZATION +} + +func (u *User) GetOrganizations() error { + ous, err := GetOrgUsersByUserId(u.Id) + if err != nil { + return err + } + + u.Orgs = make([]*User, len(ous)) + for i, ou := range ous { + u.Orgs[i], err = GetUserById(ou.OrgId) + if err != nil { + return err + } + } + return nil } // Member represents user is member of organization. @@ -126,49 +152,135 @@ func GetUserSalt() string { return base.GetRandomString(10) } -// RegisterUser creates record of a new user. -func RegisterUser(user *User) (*User, error) { +// CreateUser creates record of a new user. +func CreateUser(u *User) (*User, error) { + if !IsLegalName(u.Name) { + return nil, ErrUserNameIllegal + } + + isExist, err := IsUserExist(u.Name) + if err != nil { + return nil, err + } else if isExist { + return nil, ErrUserAlreadyExist + } + + isExist, err = IsEmailUsed(u.Email) + if err != nil { + return nil, err + } else if isExist { + return nil, ErrEmailAlreadyUsed + } + + u.LowerName = strings.ToLower(u.Name) + u.Avatar = base.EncodeMd5(u.Email) + u.AvatarEmail = u.Email + u.Rands = GetUserSalt() + u.Salt = GetUserSalt() + u.EncodePasswd() + + sess := x.NewSession() + defer sess.Close() + if err = sess.Begin(); err != nil { + return nil, err + } - if !IsLegalName(user.Name) { + if _, err = sess.Insert(u); err != nil { + sess.Rollback() + return nil, err + } + + if err = os.MkdirAll(UserPath(u.Name), os.ModePerm); err != nil { + sess.Rollback() + return nil, err + } + + if err = sess.Commit(); err != nil { + return nil, err + } + + // Auto-set admin for user whose ID is 1. + if u.Id == 1 { + u.IsAdmin = true + u.IsActive = true + _, err = x.Id(u.Id).UseBool().Update(u) + } + return u, err +} + +// CreateOrganization creates record of a new organization. +func CreateOrganization(org, owner *User) (*User, error) { + if !IsLegalName(org.Name) { return nil, ErrUserNameIllegal } - isExist, err := IsUserExist(user.Name) + isExist, err := IsUserExist(org.Name) if err != nil { return nil, err } else if isExist { return nil, ErrUserAlreadyExist } - isExist, err = IsEmailUsed(user.Email) + isExist, err = IsEmailUsed(org.Email) if err != nil { return nil, err } else if isExist { return nil, ErrEmailAlreadyUsed } - user.LowerName = strings.ToLower(user.Name) - user.Avatar = base.EncodeMd5(user.Email) - user.AvatarEmail = user.Email - user.Rands = GetUserSalt() - user.Salt = GetUserSalt() - user.EncodePasswd() - if _, err = x.Insert(user); err != nil { + org.LowerName = strings.ToLower(org.Name) + org.Avatar = base.EncodeMd5(org.Email) + org.AvatarEmail = org.Email + // No password for organization. + org.NumTeams = 1 + org.NumMembers = 1 + + sess := x.NewSession() + defer sess.Close() + if err = sess.Begin(); err != nil { + return nil, err + } + + if _, err = sess.Insert(org); err != nil { + sess.Rollback() return nil, err - } else if err = os.MkdirAll(UserPath(user.Name), os.ModePerm); err != nil { - if _, err := x.Id(user.Id).Delete(&User{}); err != nil { - return nil, errors.New(fmt.Sprintf( - "both create userpath %s and delete table record faild: %v", user.Name, err)) - } + } + + // Create default owner team. + t := &Team{ + OrgId: org.Id, + Name: "Owner", + Authorize: ORG_ADMIN, + NumMembers: 1, + } + if _, err = sess.Insert(t); err != nil { + sess.Rollback() return nil, err } - if user.Id == 1 { - user.IsAdmin = true - user.IsActive = true - _, err = x.Id(user.Id).UseBool().Update(user) + // Add initial creator to organization and owner team. + ou := &OrgUser{ + Uid: owner.Id, + OrgId: org.Id, + IsOwner: true, + NumTeam: 1, } - return user, err + if _, err = sess.Insert(ou); err != nil { + sess.Rollback() + return nil, err + } + + tu := &TeamUser{ + Uid: owner.Id, + OrgId: org.Id, + TeamId: t.Id, + } + if _, err = sess.Insert(tu); err != nil { + sess.Rollback() + return nil, err + } + + return org, sess.Commit() } // GetUsers returns given number of user objects with offset. diff --git a/modules/auth/org.go b/modules/auth/org.go new file mode 100644 index 00000000..a60fbb85 --- /dev/null +++ b/modules/auth/org.go @@ -0,0 +1,33 @@ +// 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/go-martini/martini" + + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware/binding" +) + +type CreateOrganizationForm struct { + OrgName string `form:"orgname" binding:"Required;AlphaDashDot;MaxSize(30)"` + Email string `form:"email" binding:"Required;Email;MaxSize(50)"` +} + +func (f *CreateOrganizationForm) Name(field string) string { + names := map[string]string{ + "OrgName": "Organization name", + "Email": "E-mail address", + } + return names[field] +} + +func (f *CreateOrganizationForm) Validate(errs *binding.Errors, req *http.Request, ctx martini.Context) { + data := ctx.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + validate(errs, data, f) +} diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 6c77ed2a..43ba1e8c 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -46,7 +46,7 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler { // Collaborators who have write access can be seen as owners. if ctx.IsSigned { - ctx.Repo.IsOwner, err = models.HasAccess(ctx.User.Name, userName+"/"+repoName, models.AU_WRITABLE) + ctx.Repo.IsOwner, err = models.HasAccess(ctx.User.Name, userName+"/"+repoName, models.WRITABLE) if err != nil { ctx.Handle(500, "RepoAssignment(HasAccess)", err) return @@ -107,7 +107,7 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler { return } - hasAccess, err := models.HasAccess(ctx.User.Name, ctx.Repo.Owner.Name+"/"+repo.Name, models.AU_READABLE) + hasAccess, err := models.HasAccess(ctx.User.Name, ctx.Repo.Owner.Name+"/"+repo.Name, models.READABLE) if err != nil { ctx.Handle(500, "RepoAssignment(HasAccess)", err) return diff --git a/routers/admin/user.go b/routers/admin/user.go index d1bbb480..cf99db2b 100644 --- a/routers/admin/user.go +++ b/routers/admin/user.go @@ -67,7 +67,7 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { } var err error - if u, err = models.RegisterUser(u); err != nil { + if u, err = models.CreateUser(u); err != nil { switch err { case models.ErrUserAlreadyExist: ctx.RenderWithErr("Username has been already taken", USER_NEW, &form) @@ -76,7 +76,7 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { case models.ErrUserNameIllegal: ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), USER_NEW, &form) default: - ctx.Handle(500, "admin.user.NewUser(RegisterUser)", err) + ctx.Handle(500, "admin.user.NewUser(CreateUser)", err) } return } diff --git a/routers/install.go b/routers/install.go index 6ce7c980..bb3c16ea 100644 --- a/routers/install.go +++ b/routers/install.go @@ -227,7 +227,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { GlobalInit() // Create admin account. - if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd, + if _, err := models.CreateUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd, IsAdmin: true, IsActive: true}); err != nil { if err != models.ErrUserAlreadyExist { setting.InstallLock = false diff --git a/routers/org/org.go b/routers/org/org.go index ff97402e..0595a81b 100644 --- a/routers/org/org.go +++ b/routers/org/org.go @@ -1,33 +1,117 @@ +// 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 org import ( "github.com/go-martini/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" + "github.com/gogits/gogs/routers/user" +) + +const ( + NEW base.TplName = "org/new" ) func Organization(ctx *middleware.Context, params martini.Params) { - ctx.Data["Title"] = "Organization "+params["org"] + ctx.Data["Title"] = "Organization " + params["org"] ctx.HTML(200, "org/org") } func Members(ctx *middleware.Context, params martini.Params) { - ctx.Data["Title"] = "Organization "+params["org"]+" Members" + ctx.Data["Title"] = "Organization " + params["org"] + " Members" ctx.HTML(200, "org/members") } func Teams(ctx *middleware.Context, params martini.Params) { - ctx.Data["Title"] = "Organization "+params["org"]+" Teams" + ctx.Data["Title"] = "Organization " + params["org"] + " Teams" ctx.HTML(200, "org/teams") } func New(ctx *middleware.Context) { - ctx.Data["Title"] = "Create an Organization" - ctx.HTML(200, "org/new") + ctx.Data["Title"] = "Create An Organization" + ctx.HTML(200, NEW) +} + +func NewPost(ctx *middleware.Context, form auth.CreateOrganizationForm) { + ctx.Data["Title"] = "Create An Organization" + + if ctx.HasError() { + ctx.HTML(200, NEW) + return + } + + org := &models.User{ + Name: form.OrgName, + Email: form.Email, + IsActive: true, // NOTE: may need to set false when require e-mail confirmation. + Type: models.ORGANIZATION, + } + + var err error + if org, err = models.CreateOrganization(org, ctx.User); err != nil { + switch err { + case models.ErrUserAlreadyExist: + ctx.Data["Err_OrgName"] = true + ctx.RenderWithErr("Organization name has been already taken", NEW, &form) + case models.ErrEmailAlreadyUsed: + ctx.Data["Err_Email"] = true + ctx.RenderWithErr("E-mail address has been already used", NEW, &form) + case models.ErrUserNameIllegal: + ctx.Data["Err_OrgName"] = true + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), NEW, &form) + default: + ctx.Handle(500, "user.NewPost(CreateUser)", err) + } + return + } + log.Trace("%s Organization created: %s", ctx.Req.RequestURI, org.Name) + + ctx.Redirect("/org/" + form.OrgName + "/dashboard") } func Dashboard(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Dashboard" - ctx.HTML(200, "org/dashboard") + ctx.Data["PageIsUserDashboard"] = true + ctx.Data["PageIsOrgDashboard"] = true + + org, err := models.GetUserByName(params["org"]) + if err != nil { + if err == models.ErrUserNotExist { + ctx.Handle(404, "org.Dashboard(GetUserByName)", err) + } else { + ctx.Handle(500, "org.Dashboard(GetUserByName)", err) + } + return + } + + if err := ctx.User.GetOrganizations(); err != nil { + ctx.Handle(500, "home.Dashboard(GetOrganizations)", err) + return + } + ctx.Data["Orgs"] = ctx.User.Orgs + ctx.Data["ContextUser"] = org + + ctx.Data["MyRepos"], err = models.GetRepositories(org.Id, true) + if err != nil { + ctx.Handle(500, "org.Dashboard(GetRepositories)", err) + return + } + + actions, err := models.GetFeeds(org.Id, 0, false) + if err != nil { + ctx.Handle(500, "org.Dashboard(GetFeeds)", err) + return + } + ctx.Data["Feeds"] = actions + + ctx.HTML(200, user.DASHBOARD) } func Setting(ctx *middleware.Context, param martini.Params) { diff --git a/routers/repo/http.go b/routers/repo/http.go index d2bff299..981266d5 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -107,9 +107,9 @@ func Http(ctx *middleware.Context, params martini.Params) { } if !isPublicPull { - var tp = models.AU_WRITABLE + var tp = models.WRITABLE if isPull { - tp = models.AU_READABLE + tp = models.READABLE } has, err := models.HasAccess(authUsername, username+"/"+reponame, tp) @@ -117,8 +117,8 @@ func Http(ctx *middleware.Context, params martini.Params) { ctx.Handle(401, "no basic auth and digit auth", nil) return } else if !has { - if tp == models.AU_READABLE { - has, err = models.HasAccess(authUsername, username+"/"+reponame, models.AU_WRITABLE) + if tp == models.READABLE { + has, err = models.HasAccess(authUsername, username+"/"+reponame, models.WRITABLE) if err != nil || !has { ctx.Handle(401, "no basic auth and digit auth", nil) return diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 6479cb30..3d48e79c 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -175,7 +175,7 @@ func CollaborationPost(ctx *middleware.Context) { ctx.Redirect(ctx.Req.RequestURI) return } - has, err := models.HasAccess(name, repoLink, models.AU_WRITABLE) + has, err := models.HasAccess(name, repoLink, models.WRITABLE) if err != nil { ctx.Handle(500, "setting.CollaborationPost(HasAccess)", err) return @@ -196,7 +196,7 @@ func CollaborationPost(ctx *middleware.Context) { } if err = models.AddAccess(&models.Access{UserName: name, RepoName: repoLink, - Mode: models.AU_WRITABLE}); err != nil { + Mode: models.WRITABLE}); err != nil { ctx.Handle(500, "setting.CollaborationPost(AddAccess)", err) return } diff --git a/routers/user/home.go b/routers/user/home.go index 0f2cee25..86907b5a 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -20,7 +20,7 @@ import ( const ( DASHBOARD base.TplName = "user/dashboard" PROFILE base.TplName = "user/profile" - ISSUES base.TplName = "user/issue" + ISSUES base.TplName = "user/issues" PULLS base.TplName = "user/pulls" STARS base.TplName = "user/stars" ) @@ -29,6 +29,13 @@ func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = "Dashboard" ctx.Data["PageIsUserDashboard"] = true + if err := ctx.User.GetOrganizations(); err != nil { + ctx.Handle(500, "home.Dashboard(GetOrganizations)", err) + return + } + ctx.Data["Orgs"] = ctx.User.Orgs + ctx.Data["ContextUser"] = ctx.User + var err error ctx.Data["MyRepos"], err = models.GetRepositories(ctx.User.Id, true) if err != nil { @@ -53,7 +60,7 @@ func Dashboard(ctx *middleware.Context) { for _, act := range actions { if act.IsPrivate { if has, _ := models.HasAccess(ctx.User.Name, act.RepoUserName+"/"+act.RepoName, - models.AU_READABLE); !has { + models.READABLE); !has { continue } } @@ -131,7 +138,7 @@ func Feeds(ctx *middleware.Context, form auth.FeedsForm) { for _, act := range actions { if act.IsPrivate { if has, _ := models.HasAccess(ctx.User.Name, act.RepoUserName+"/"+act.RepoName, - models.AU_READABLE); !has { + models.READABLE); !has { continue } } diff --git a/routers/user/user.go b/routers/user/user.go index 8144730e..a50f126c 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -226,7 +226,7 @@ func SignUpPost(ctx *middleware.Context, form auth.RegisterForm) { } var err error - if u, err = models.RegisterUser(u); err != nil { + if u, err = models.CreateUser(u); err != nil { switch err { case models.ErrUserAlreadyExist: ctx.Data["Err_UserName"] = true @@ -235,13 +235,14 @@ func SignUpPost(ctx *middleware.Context, form auth.RegisterForm) { ctx.Data["Err_Email"] = true ctx.RenderWithErr("E-mail address has been already used", SIGNUP, &form) case models.ErrUserNameIllegal: + ctx.Data["Err_UserName"] = true ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), SIGNUP, &form) default: - ctx.Handle(500, "user.SignUpPost(RegisterUser)", err) + ctx.Handle(500, "user.SignUpPost(CreateUser)", err) } return } - log.Trace("%s User created: %s", ctx.Req.RequestURI, form.UserName) + log.Trace("%s User created: %s", ctx.Req.RequestURI, u.Name) // Bind social account. if isOauth { diff --git a/templates/VERSION b/templates/VERSION index 8c2be60b..b5cda695 100644 --- a/templates/VERSION +++ b/templates/VERSION @@ -1 +1 @@ -0.4.5.0624 Alpha \ No newline at end of file +0.4.5.0625 Alpha \ No newline at end of file diff --git a/templates/org/dashboard.tmpl b/templates/org/dashboard.tmpl deleted file mode 100644 index f86de1f4..00000000 --- a/templates/org/dashboard.tmpl +++ /dev/null @@ -1,73 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -
-
-
- - - -
- -

News Feed

-
-
-
- {{if .HasInfo}}
{{.InfoMsg}}
{{end}} -
-
    - {{range .Feeds}} -
  • - -
    {{TimeSince .Created}}
    {{ActionDesc . | str2html}}
    - -
  • - {{else}} -
  • Oh. Looks like there isn't any activity here yet. Get Busy!
  • - {{end}} -
-
-
-
-
Repositories -
- - -
-
- -
- -
-
-
-
-{{template "base/footer" .}} diff --git a/templates/org/new.tmpl b/templates/org/new.tmpl index baa9c9df..bb46db4a 100644 --- a/templates/org/new.tmpl +++ b/templates/org/new.tmpl @@ -1,22 +1,14 @@ {{template "base/head" .}} {{template "base/navbar" .}}
-
+ {{.CsrfTokenHtml}}

Create New Organization

{{template "base/alert" .}} -
- -
-

{{.SignedUserName}}

- -
-
- -
+
- + Great organization names are short and memorable.
@@ -24,18 +16,10 @@
- + Organization's Email receives all notifications and confirmations.
- -
diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl index 12018ad8..e1b43e15 100644 --- a/templates/user/dashboard.tmpl +++ b/templates/user/dashboard.tmpl @@ -4,29 +4,46 @@
-

News Feed

+
{{if .HasInfo}}
{{.InfoMsg}}
{{end}}
@@ -44,7 +61,7 @@
-
Your Repositories +
{{if not .PageIsOrgDashboard}}Your {{end}}Repositories
- + + {{if not .PageIsOrgDashboard}}
Collaborative Repositories
@@ -78,6 +96,7 @@
+ {{end}}
{{template "base/footer" .}} diff --git a/templates/user/issues.tmpl b/templates/user/issues.tmpl index d1c2bd99..c4ad64a4 100644 --- a/templates/user/issues.tmpl +++ b/templates/user/issues.tmpl @@ -3,7 +3,7 @@
+
{{if .HasInfo}}
{{.InfoMsg}}
{{end}}
-- cgit v1.2.3