From 67a9416ae55ea765e3f405e00d89b0b8f3899330 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 12 Feb 2015 12:38:44 -0500 Subject: templates/user/auth/signin.tmpl: hide sign up prompt when registration is disabled #884 --- templates/.VERSION | 2 +- templates/user/auth/signin.tmpl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'templates') diff --git a/templates/.VERSION b/templates/.VERSION index 2aad3653..6d13155b 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.13.0211 Beta \ No newline at end of file +0.5.13.0212 Beta \ No newline at end of file diff --git a/templates/user/auth/signin.tmpl b/templates/user/auth/signin.tmpl index 78d6febb..455df63a 100644 --- a/templates/user/auth/signin.tmpl +++ b/templates/user/auth/signin.tmpl @@ -26,10 +26,12 @@      {{if not .IsSocialLogin}}{{.i18n.Tr "auth.forget_password"}}{{end}} + {{if .ShowRegistrationButton}}
{{.i18n.Tr "auth.sign_up_now" | Str2html}}
+ {{end}} {{if and (not .IsSocialLogin) .OauthEnabled}}
-- cgit v1.2.3 From 685ed1f8075c0fedc2cfaf0f8c43f9439132e1da Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 14 Feb 2015 17:01:33 -0500 Subject: models: fix XORM API break cmd/web.go: check version after load config --- cmd/web.go | 3 +-- gogs.go | 2 +- models/models.go | 2 +- templates/.VERSION | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) (limited to 'templates') diff --git a/cmd/web.go b/cmd/web.go index 3284acb9..4b06a882 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -166,12 +166,11 @@ func newMacaron() *macaron.Macaron { } func runWeb(ctx *cli.Context) { - checkVersion() - if ctx.IsSet("config") { setting.CustomConf = ctx.String("config") } routers.GlobalInit() + checkVersion() m := newMacaron() diff --git a/gogs.go b/gogs.go index 76c6c71f..34790b72 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.13.0212 Beta" +const APP_VER = "0.5.13.0214 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/models.go b/models/models.go index 35e80383..486aceac 100644 --- a/models/models.go +++ b/models/models.go @@ -121,7 +121,7 @@ func SetEngine() (err error) { if err != nil { return fmt.Errorf("models.init(fail to create xorm.log): %v", err) } - x.Logger = xorm.NewSimpleLogger(f) + x.SetLogger(xorm.NewSimpleLogger(f)) x.ShowSQL = true x.ShowInfo = true diff --git a/templates/.VERSION b/templates/.VERSION index 6d13155b..0c9421a4 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.13.0212 Beta \ No newline at end of file +0.5.13.0214 Beta \ No newline at end of file -- cgit v1.2.3 From 7759b9ee6efb069a1f846b43bd6bc981f998e55a Mon Sep 17 00:00:00 2001 From: Peter Smit Date: Mon, 16 Feb 2015 14:44:27 +0200 Subject: Remove the "PHP" style formatting function The "PHP" formatting function doesn't add anything, except an undocumented date format. All usages in the templates have been replaced with DateFmtShort and DateFmtLong for convenience. --- modules/base/template.go | 9 ++++- modules/base/tool.go | 67 +++---------------------------- templates/admin/auth/list.tmpl | 4 +- templates/admin/org/list.tmpl | 2 +- templates/admin/repo/list.tmpl | 2 +- templates/admin/user/list.tmpl | 2 +- templates/user/profile.tmpl | 2 +- templates/user/settings/applications.tmpl | 2 +- templates/user/settings/social.tmpl | 2 +- templates/user/settings/sshkeys.tmpl | 2 +- 10 files changed, 22 insertions(+), 72 deletions(-) (limited to 'templates') diff --git a/modules/base/template.go b/modules/base/template.go index f3fa1385..0fd519e6 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -126,8 +126,13 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ return a + b }, "ActionIcon": ActionIcon, - "DateFormat": DateFormat, - "List": List, + "DateFmtLong": func(t time.Time) string { + return t.Format(time.RFC1123Z) + }, + "DateFmtShort": func(t time.Time) string { + return t.Format("Jan 02, 2006") + }, + "List": List, "Mail2Domain": func(mail string) string { if !strings.Contains(mail, "@") { return "try.gogs.io" diff --git a/modules/base/tool.go b/modules/base/tool.go index 5043364c..55e6dffd 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -126,7 +126,7 @@ func VerifyTimeLimitCode(data string, minutes int, code string) bool { retCode := CreateTimeLimitCode(data, minutes, start) if retCode == code && minutes > 0 { // check time is expired or not - before, _ := DateParse(start, "YmdHi") + before, _ := time.ParseInLocation("200601021504", start, time.Local) now := time.Now() if before.Add(time.Minute*time.Duration(minutes)).Unix() > now.Unix() { return true @@ -141,7 +141,7 @@ const TimeLimitCodeLength = 12 + 6 + 40 // create a time limit code // code format: 12 length date time string + 6 minutes string + 40 sha1 encoded string func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string { - format := "YmdHi" + format := "200601021504" var start, end time.Time var startStr, endStr string @@ -149,16 +149,16 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string if startInf == nil { // Use now time create code start = time.Now() - startStr = DateFormat(start, format) + startStr = start.Format(format) } else { // use start string create code startStr = startInf.(string) - start, _ = DateParse(startStr, format) - startStr = DateFormat(start, format) + start, _ = time.ParseInLocation(format, startStr, time.Local) + startStr = start.Format(format) } end = start.Add(time.Minute * time.Duration(minutes)) - endStr = DateFormat(end, format) + endStr = end.Format(format) // create sha1 encode string sh := sha1.New() @@ -420,58 +420,3 @@ func Subtract(left interface{}, right interface{}) interface{} { return fleft + float64(rleft) - (fright + float64(rright)) } } - -// DateFormat pattern rules. -var datePatterns = []string{ - // year - "Y", "2006", // A full numeric representation of a year, 4 digits Examples: 1999 or 2003 - "y", "06", //A two digit representation of a year Examples: 99 or 03 - - // month - "m", "01", // Numeric representation of a month, with leading zeros 01 through 12 - "n", "1", // Numeric representation of a month, without leading zeros 1 through 12 - "M", "Jan", // A short textual representation of a month, three letters Jan through Dec - "F", "January", // A full textual representation of a month, such as January or March January through December - - // day - "d", "02", // Day of the month, 2 digits with leading zeros 01 to 31 - "j", "2", // Day of the month without leading zeros 1 to 31 - - // week - "D", "Mon", // A textual representation of a day, three letters Mon through Sun - "l", "Monday", // A full textual representation of the day of the week Sunday through Saturday - - // time - "g", "3", // 12-hour format of an hour without leading zeros 1 through 12 - "G", "15", // 24-hour format of an hour without leading zeros 0 through 23 - "h", "03", // 12-hour format of an hour with leading zeros 01 through 12 - "H", "15", // 24-hour format of an hour with leading zeros 00 through 23 - - "a", "pm", // Lowercase Ante meridiem and Post meridiem am or pm - "A", "PM", // Uppercase Ante meridiem and Post meridiem AM or PM - - "i", "04", // Minutes with leading zeros 00 to 59 - "s", "05", // Seconds, with leading zeros 00 through 59 - - // time zone - "T", "MST", - "P", "-07:00", - "O", "-0700", - - // RFC 2822 - "r", time.RFC1123Z, -} - -// Parse Date use PHP time format. -func DateParse(dateString, format string) (time.Time, error) { - replacer := strings.NewReplacer(datePatterns...) - format = replacer.Replace(format) - return time.ParseInLocation(format, dateString, time.Local) -} - -// Date takes a PHP like date func to Go's time format. -func DateFormat(t time.Time, format string) string { - replacer := strings.NewReplacer(datePatterns...) - format = replacer.Replace(format) - return t.Format(format) -} diff --git a/templates/admin/auth/list.tmpl b/templates/admin/auth/list.tmpl index aba516b8..ec701a8f 100644 --- a/templates/admin/auth/list.tmpl +++ b/templates/admin/auth/list.tmpl @@ -34,8 +34,8 @@ {{.Name}} {{.TypeString}} - {{DateFormat .Updated "M d, Y"}} - {{DateFormat .Created "M d, Y"}} + {{DateFmtShort .Updated}} + {{DateFmtShort .Created}} {{end}} diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index b522dc08..ce5083a0 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -35,7 +35,7 @@ {{.NumTeams}} {{.NumMembers}} {{.NumRepos}} - {{DateFormat .Created "M d, Y"}} + {{DateFmtShort .Created}} {{end}} diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 88e16a43..981e2ef7 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -37,7 +37,7 @@ {{.NumWatches}} {{.NumStars}} {{.NumIssues}} - {{DateFormat .Created "M d, Y"}} + {{DateFmtShort .Created}} {{end}} diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index d42d5291..1dd5553e 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -37,7 +37,7 @@ {{.NumRepos}} - {{DateFormat .Created "M d, Y"}} + {{DateFmtShort .Created }} {{end}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 44c22123..a18a8b50 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -28,7 +28,7 @@ {{if .Owner.Website}}
  •   {{.Owner.Website}}
  • {{end}} -
  •   {{.i18n.Tr "user.join_on"}} {{DateFormat .Owner.Created "M d, Y"}}
  • +
  •   {{.i18n.Tr "user.join_on"}} {{DateFmtShort .Owner.Created}}

    • diff --git a/templates/user/settings/applications.tmpl b/templates/user/settings/applications.tmpl index ce74ef77..2e766a3d 100644 --- a/templates/user/settings/applications.tmpl +++ b/templates/user/settings/applications.tmpl @@ -22,7 +22,7 @@

      {{.Name}}

      -

      {{$.i18n.Tr "settings.add_on"}} {{DateFormat .Created "M d, Y"}}{{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFormat .Updated "M d, Y"}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}

      +

      {{$.i18n.Tr "settings.add_on"}} {{DateFmtShort .Created}}{{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFmtShort .Updated}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}

      diff --git a/templates/user/settings/social.tmpl b/templates/user/settings/social.tmpl index b47f883e..f2a30da7 100644 --- a/templates/user/settings/social.tmpl +++ b/templates/user/settings/social.tmpl @@ -18,7 +18,7 @@

      {{Oauth2Name .Type}}

      {{.Identity}}

      -

      {{$.i18n.Tr "settings.add_on"}} {{DateFormat .Created "M d, Y"}}{{$.i18n.Tr "settings.last_used"}} {{DateFormat .Updated "M d, Y"}}

      +

      {{$.i18n.Tr "settings.add_on"}} {{DateFmtShort .Created}}{{$.i18n.Tr "settings.last_used"}} {{DateFmtShort .Updated}}

      {{$.i18n.Tr "settings.unbind"}} diff --git a/templates/user/settings/sshkeys.tmpl b/templates/user/settings/sshkeys.tmpl index 48a4d343..42b76039 100644 --- a/templates/user/settings/sshkeys.tmpl +++ b/templates/user/settings/sshkeys.tmpl @@ -23,7 +23,7 @@

      {{.Name}}

      {{.Fingerprint}}

      -

      {{$.i18n.Tr "settings.add_on"}} {{DateFormat .Created "M d, Y"}}{{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFormat .Updated "M d, Y"}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}

      +

      {{$.i18n.Tr "settings.add_on"}} {{DateFmtShort .Created}}{{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFmtShort .Updated}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}

      {{$.CsrfTokenHtml}} -- cgit v1.2.3 From e6fc58a74461bd67efb06fc2e5658265ede2edb5 Mon Sep 17 00:00:00 2001 From: Peter Smit Date: Tue, 17 Feb 2015 10:36:17 +0200 Subject: Remove GoGet option from repository and handle it with ?go-get=1 instead The normal go get protocol is to show the go-import meta tag when ?go-get=1 is appended to the url. This commit implements that behaviour and cleans the go-get option from the repository settings page. --- conf/locale/locale_en-US.ini | 2 -- models/repo.go | 1 - modules/auth/repo_form.go | 1 - modules/middleware/repo.go | 3 +-- routers/repo/setting.go | 3 +-- templates/base/head.tmpl | 2 +- templates/ng/base/head.tmpl | 2 +- templates/repo/settings/options.tmpl | 5 ----- 8 files changed, 4 insertions(+), 15 deletions(-) (limited to 'templates') diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 6b59be73..54b80abb 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -281,8 +281,6 @@ init_readme = Initialize this repository with a README.md create_repo = Create Repository default_branch = Default Branch mirror_interval = Mirror Interval (hour) -goget_meta = Go-Get Meta -goget_meta_helper = This repository will be Go-Getable need_auth = Need Authorization migrate_type = Migration Type diff --git a/models/repo.go b/models/repo.go index cdb838a1..179120a3 100644 --- a/models/repo.go +++ b/models/repo.go @@ -154,7 +154,6 @@ type Repository struct { IsPrivate bool IsBare bool - IsGoget bool IsMirror bool *Mirror `xorm:"-"` diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 36e62f04..c771dd59 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -52,7 +52,6 @@ type RepoSettingForm struct { Branch string `form:"branch"` Interval int `form:"interval"` Private bool `form:"private"` - GoGet bool `form:"goget"` } func (f *RepoSettingForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 1ab158dd..67a9eda6 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -394,8 +394,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { } ctx.Data["CloneLink"] = ctx.Repo.CloneLink - if ctx.Repo.Repository.IsGoget { - ctx.Data["GoGetLink"] = fmt.Sprintf("%s%s/%s", setting.AppUrl, u.LowerName, repo.LowerName) + if ctx.Query("go-get") == "1" { ctx.Data["GoGetImport"] = fmt.Sprintf("%s/%s/%s", setting.Domain, u.LowerName, repo.LowerName) } diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 33bf1eab..8368513a 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -8,9 +8,9 @@ import ( "encoding/json" "errors" "fmt" + "path" "strings" "time" - "path" "github.com/Unknwon/com" @@ -84,7 +84,6 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { ctx.Repo.Repository.Description = form.Description ctx.Repo.Repository.Website = form.Website ctx.Repo.Repository.IsPrivate = form.Private - ctx.Repo.Repository.IsGoget = form.GoGet if err := models.UpdateRepository(ctx.Repo.Repository); err != nil { ctx.Handle(404, "UpdateRepository", err) return diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 7775933c..cb3951ea 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -9,7 +9,7 @@ - {{if .Repository.IsGoget}}{{end}} + {{if .GoGetImport}}{{end}} {{if CdnMode}} diff --git a/templates/ng/base/head.tmpl b/templates/ng/base/head.tmpl index 40a7d28f..f2a235bd 100644 --- a/templates/ng/base/head.tmpl +++ b/templates/ng/base/head.tmpl @@ -7,7 +7,7 @@ - {{if .Repository.IsGoget}}{{end}} + {{if .GoGetImport}}{{end}} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 093e9375..41683f84 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -59,11 +59,6 @@ {{.i18n.Tr "repo.visiblity_helper" | Str2html}}
    -
    - - - {{.i18n.Tr "repo.goget_meta_helper" | Str2html}} -
    -- cgit v1.2.3 From 1628ef4ba5120d338c0616e37153f9f9b2f8f236 Mon Sep 17 00:00:00 2001 From: Stefan-Code Date: Wed, 18 Feb 2015 08:22:13 +0100 Subject: changed repo-clone-url behaviour for bare repo --- public/ng/css/gogs.css | 4 +--- public/ng/less/gogs/repository.less | 4 +--- templates/repo/bare.tmpl | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) (limited to 'templates') diff --git a/public/ng/css/gogs.css b/public/ng/css/gogs.css index 9f6cf12f..43931e94 100644 --- a/public/ng/css/gogs.css +++ b/public/ng/css/gogs.css @@ -1066,9 +1066,6 @@ The register and sign-in page style #repo-header-download-drop .btn > i { margin-right: 6px; } -#repo-header-download-drop input { - cursor: default; -} #repo-header-download-drop button, #repo-header-download-drop input { font-size: 11px; @@ -1089,6 +1086,7 @@ The register and sign-in page style border-right: none; width: 190px; border-left: none; + cursor: default; } #repo-clone-help { clear: both; diff --git a/public/ng/less/gogs/repository.less b/public/ng/less/gogs/repository.less index d683d033..63c25d06 100644 --- a/public/ng/less/gogs/repository.less +++ b/public/ng/less/gogs/repository.less @@ -81,9 +81,6 @@ .btn>i { margin-right: 6px; } - input { - cursor: default; - } button, input { font-size: 11px; } @@ -104,6 +101,7 @@ border-right: none; width: 190px; border-left: none; + cursor: default; } #repo-clone-help { clear: both; diff --git a/templates/repo/bare.tmpl b/templates/repo/bare.tmpl index 2a1409a6..c050b623 100644 --- a/templates/repo/bare.tmpl +++ b/templates/repo/bare.tmpl @@ -23,7 +23,7 @@

    {{.i18n.Tr "repo.clone_this_repo"}}

    - +

    {{.i18n.Tr "repo.clone_helper" | Str2html}}


    @@ -50,4 +50,4 @@ git push -u origin master
    -{{template "ng/base/footer" .}} \ No newline at end of file +{{template "ng/base/footer" .}} -- cgit v1.2.3 From 563e8b4ea98e57adf3992dcaef76b86d29c13cec Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Thu, 19 Feb 2015 00:52:22 +0300 Subject: gitlab-like hash naming --- modules/base/template.go | 5 +++++ public/ng/js/gogs.js | 20 ++++++++++---------- templates/repo/diff.tmpl | 6 +++--- 3 files changed, 18 insertions(+), 13 deletions(-) (limited to 'templates') diff --git a/modules/base/template.go b/modules/base/template.go index 0fd519e6..cfcabb71 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -41,6 +41,10 @@ func List(l *list.List) chan interface{} { return c } +func Sha1(str string) string { + return EncodeSha1(str) +} + func ShortSha(sha1 string) string { if len(sha1) == 40 { return sha1[:10] @@ -160,6 +164,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ }, "DiffTypeToStr": DiffTypeToStr, "DiffLineTypeToStr": DiffLineTypeToStr, + "Sha1": Sha1, "ShortSha": ShortSha, "Md5": EncodeMd5, "ActionContent2Commits": ActionContent2Commits, diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js index a6b9753e..bd320b44 100644 --- a/public/ng/js/gogs.js +++ b/public/ng/js/gogs.js @@ -209,14 +209,14 @@ var Gogs = {}; $list.parents('tr').removeClass('end-selected-line'); $list.parents('tr').find('td').removeClass('selected-line'); if ($from) { - var expr = new RegExp(/diff-(\d+)L(\d+)/); + var expr = new RegExp(/diff-(\w+)([LR])(\d+)/); var selectMatches = $select.attr('rel').match(expr) var fromMatches = $from.attr('rel').match(expr) - var a = parseInt(selectMatches[2]); - var b = parseInt(fromMatches[2]); + var a = parseInt(selectMatches[3]); + var b = parseInt(fromMatches[3]); var linesIntToStr = {}; - linesIntToStr[a] = selectMatches[2]; - linesIntToStr[b] = fromMatches[2]; + linesIntToStr[a] = selectMatches[3]; + linesIntToStr[b] = fromMatches[3]; var c; if (a != b) { @@ -225,11 +225,11 @@ var Gogs = {}; a = b; b = c; } - $('[rel=diff-'+fromMatches[1]+'L' + linesIntToStr[b] + ']').parents('tr').next().addClass('end-selected-line'); - var $selectedLines = $('[rel=diff-'+fromMatches[1]+'L' + linesIntToStr[a] + ']').parents('tr').nextUntil('.end-selected-line').andSelf(); + $('[rel=diff-'+fromMatches[1] + fromMatches[2] + linesIntToStr[b] + ']').parents('tr').next().addClass('end-selected-line'); + var $selectedLines = $('[rel=diff-'+fromMatches[1]+selectMatches[2] + linesIntToStr[a] + ']').parents('tr').nextUntil('.end-selected-line').andSelf(); $selectedLines.find('td.lines-num > span').addClass('active') $selectedLines.find('td').addClass('selected-line'); - $.changeHash('#diff-'+fromMatches[1]+'L' + linesIntToStr[a] + '-L' + linesIntToStr[b]); + $.changeHash('#diff-'+fromMatches[1]+fromMatches[2] + linesIntToStr[a] + '-' + selectMatches[2] + + linesIntToStr[b]); return } } @@ -262,7 +262,7 @@ var Gogs = {}; }); $(window).on('hashchange', function (e) { - var m = window.location.hash.match(/^#diff-(\d+)(L\d+)\-(L\d+)$/); + var m = window.location.hash.match(/^#diff-(\w+)([LR]\d+)\-([LR]\d+)$/); var $list = $('.code-diff td.lines-num > span'); var $first; if (m) { @@ -271,7 +271,7 @@ var Gogs = {}; $("html, body").scrollTop($first.offset().top - 200); return; } - m = window.location.hash.match(/^#diff-(\d+)(L\d+)$/); + m = window.location.hash.match(/^#diff-(\w+)([LR]\d+)$/); if (m) { $first = $list.filter('[rel=diff-' + m[1] + m[2] + ']'); selectRange($list, $first); diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 443e002d..2bc5c7d7 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -106,13 +106,13 @@ {{range $j, $section := $file.Sections}} - {{range $k, $line := $section.Lines}} + {{range $k, $line := $section.Lines}}
    - {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} + {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} - {{if $line.RightIdx}}{{$line.RightIdx}}{{end}} + {{if $line.RightIdx}}{{$line.RightIdx}}{{end}} -- cgit v1.2.3 From c0ad512398e0d8232f5e729f2c38e887e6d9329a Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Thu, 19 Feb 2015 00:55:17 +0300 Subject: remove not using vars --- templates/repo/diff.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'templates') diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 2bc5c7d7..7da932a4 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -105,9 +105,9 @@ {{else}} - {{range $j, $section := $file.Sections}} - {{range $k, $line := $section.Lines}} - + {{range .Sections}} + {{range $k, $line := .Lines}} + -- cgit v1.2.3 From d2f439a2410259dcce96889a02c7a6bbf64d385e Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Thu, 19 Feb 2015 10:19:10 +0300 Subject: fix typo mistake --- templates/repo/diff.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates') diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 7da932a4..f261da55 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -109,7 +109,7 @@ {{range $k, $line := .Lines}}
    {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}
    - {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} + {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} {{if $line.RightIdx}}{{$line.RightIdx}}{{end}} -- cgit v1.2.3 From 1654e9ecab3923b7fe5d528fc86c1a549546bd29 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 21 Feb 2015 22:13:47 -0500 Subject: templates/user/settings/emial.tmpl: little fix on UI - routers/user: little code format - conf/locale: update French locale --- conf/locale/locale_fr-CA.ini | 16 ++++---- gogs.go | 2 +- models/user.go | 9 +++-- modules/auth/user_form.go | 2 +- routers/user/auth.go | 5 +-- routers/user/setting.go | 80 ++++++++++++++++++-------------------- templates/.VERSION | 2 +- templates/user/settings/email.tmpl | 6 +-- 8 files changed, 58 insertions(+), 64 deletions(-) (limited to 'templates') diff --git a/conf/locale/locale_fr-CA.ini b/conf/locale/locale_fr-CA.ini index 0aeae342..e744b9d9 100755 --- a/conf/locale/locale_fr-CA.ini +++ b/conf/locale/locale_fr-CA.ini @@ -59,8 +59,8 @@ run_user=Entrer un Utilisateur run_user_helper=L'utilisateur doit avoir accès à la Racine du Référentiel et éxécuter Gogs. domain=Domaine domain_helper=Cela affecte les doublons d'URL SSH. -http_port=HTTP Port -http_port_helper=Port number which application will listen on. +http_port=Port HTTP +http_port_helper=Numéro de port que l'application écoutera. app_url=URL de l'Application app_url_helper=Cela affecte les doublons d'URL HTTP/HTTPS et le contenu d'e-mail. email_title=Paramètres du Service de Messagerie (Facultatif) @@ -514,10 +514,10 @@ dashboard.delete_repo_archives=Supprimer toutes les archives de référentiels dashboard.delete_repo_archives_success=Toutes les archives de référentiels ont été supprimés avec succès. dashboard.git_gc_repos=Collecter les déchets des référentiels dashboard.git_gc_repos_success=Tous les référentiels ont effectué la collecte avec succès. -dashboard.resync_all_sshkeys=Rewrite '.ssh/autorized_key' file (caution: non-Gogs keys will be lost) -dashboard.resync_all_sshkeys_success=All public keys have been rewritten successfully. -dashboard.resync_all_update_hooks=Rewrite all update hook of repositories (needed when custom config path is changed) -dashboard.resync_all_update_hooks_success=All repositories' update hook have been rewritten successfully. +dashboard.resync_all_sshkeys=Ré-écrire le fichier '.ssh/autorized_key' (attention : les clés hors-Gogs vont être perdues) +dashboard.resync_all_sshkeys_success=Toutes les clés publiques ont été ré-écrites avec succès. +dashboard.resync_all_update_hooks=Ré-écrire tous les hooks de mises à jour des dépôts (requis quand le chemin de la configuration personnalisé est modifié) +dashboard.resync_all_update_hooks_success=Tous les hooks de mises à jour des dépôts ont été ré-écris avec succès. dashboard.server_uptime=Durée de Marche Serveur dashboard.current_goroutine=Goroutines actuelles @@ -638,7 +638,7 @@ config.db_path_helper=("sqlite3" uniquement) config.service_config=Configuration du Service config.register_email_confirm=Nécessite une confirmation par courriel config.disable_register=Désactiver l'Enregistrement -config.show_registration_button=Show Register Button +config.show_registration_button=Afficher le bouton d'enregistrement config.require_sign_in_view=Connexion Obligatoire pour Visualiser config.mail_notify=Mailer les Notifications config.enable_cache_avatar=Activer le Cache d'Avatar @@ -647,7 +647,7 @@ config.reset_password_code_lives=Réinitialiser le Mot De Passe des Limites de C config.webhook_config=Configuration Webhook config.task_interval=Intervalles de Tâches config.deliver_timeout=Expiration d'Envoi -config.skip_tls_verify=Skip TLS Verify +config.skip_tls_verify=Ne pas vérifier TLS config.mailer_config=Configuration du Maileur config.mailer_enabled=Activé config.mailer_name=Nom diff --git a/gogs.go b/gogs.go index 34790b72..5c24e229 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.13.0214 Beta" +const APP_VER = "0.5.14.0221 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/user.go b/models/user.go index 2da0881c..9f9b0cd7 100644 --- a/models/user.go +++ b/models/user.go @@ -627,7 +627,7 @@ func GetUserIdsByNames(names []string) []int64 { return ids } -// Get all email addresses +// GetEmailAddresses returns all e-mail addresses belongs to given user. func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { emails := make([]*EmailAddress, 0, 5) err := x.Where("uid=?", uid).Find(&emails) @@ -641,7 +641,6 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { } isPrimaryFound := false - for _, email := range emails { if email.Email == u.Email { isPrimaryFound = true @@ -654,7 +653,11 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { // We alway want the primary email address displayed, even if it's not in // the emailaddress table (yet) if !isPrimaryFound { - emails = append(emails, &EmailAddress{Email: u.Email, IsActivated: true, IsPrimary: true}) + emails = append(emails, &EmailAddress{ + Email: u.Email, + IsActivated: true, + IsPrimary: true, + }) } return emails, nil } diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go index 3c0ff651..b616a460 100644 --- a/modules/auth/user_form.go +++ b/modules/auth/user_form.go @@ -99,7 +99,7 @@ func (f *UploadAvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) b } type AddEmailForm struct { - Email string `form:"email" binding:"Required;Email;MaxSize(50)"` + Email string `binding:"Required;Email;MaxSize(50)"` } func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { diff --git a/routers/user/auth.go b/routers/user/auth.go index 9ed44e35..5dacaf8c 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -351,15 +351,12 @@ func ActivateEmail(ctx *middleware.Context) { // Verify code. if email := models.VerifyActiveEmailCode(code, email_string); email != nil { - err := email.Activate() - if err != nil { + if err := email.Activate(); err != nil { ctx.Handle(500, "ActivateEmail", err) } log.Trace("Email activated: %s", email.Email) - ctx.Flash.Success(ctx.Tr("settings.activate_email_success")) - } ctx.Redirect(setting.AppSubUrl + "/user/settings/email") diff --git a/routers/user/setting.go b/routers/user/setting.go index 953e6113..9398f69a 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -133,13 +133,12 @@ func SettingsEmails(ctx *middleware.Context) { ctx.Data["PageIsUserSettings"] = true ctx.Data["PageIsSettingsEmails"] = true - var err error - ctx.Data["Emails"], err = models.GetEmailAddresses(ctx.User.Id) - + emails, err := models.GetEmailAddresses(ctx.User.Id) if err != nil { - ctx.Handle(500, "email.GetEmailAddresses", err) + ctx.Handle(500, "GetEmailAddresses", err) return } + ctx.Data["Emails"] = emails ctx.HTML(200, SETTINGS_EMAILS) } @@ -149,16 +148,16 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) { ctx.Data["PageIsUserSettings"] = true ctx.Data["PageIsSettingsEmails"] = true - var err error - ctx.Data["Emails"], err = models.GetEmailAddresses(ctx.User.Id) + emails, err := models.GetEmailAddresses(ctx.User.Id) if err != nil { - ctx.Handle(500, "email.GetEmailAddresses", err) + ctx.Handle(500, "GetEmailAddresses", err) return } + ctx.Data["Emails"] = emails - // Delete Email address. + // Delete E-mail address. if ctx.Query("_method") == "DELETE" { - id := com.StrTo(ctx.Query("id")).MustInt64() + id := ctx.QueryInt64("id") if id <= 0 { return } @@ -174,7 +173,7 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) { // Make emailaddress primary. if ctx.Query("_method") == "PRIMARY" { - id := com.StrTo(ctx.Query("id")).MustInt64() + id := ctx.QueryInt64("id") if id <= 0 { return } @@ -189,46 +188,41 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) { } // Add Email address. - if ctx.Req.Method == "POST" { - if ctx.HasError() { - ctx.HTML(200, SETTINGS_EMAILS) - return - } + if ctx.HasError() { + ctx.HTML(200, SETTINGS_EMAILS) + return + } - cleanEmail := strings.Replace(form.Email, "\n", "", -1) - e := &models.EmailAddress{ - Uid: ctx.User.Id, - Email: cleanEmail, - IsActivated: !setting.Service.RegisterEmailConfirm, - } + cleanEmail := strings.Replace(form.Email, "\n", "", -1) + e := &models.EmailAddress{ + Uid: ctx.User.Id, + Email: cleanEmail, + IsActivated: !setting.Service.RegisterEmailConfirm, + } - if err := models.AddEmailAddress(e); err != nil { - if err == models.ErrEmailAlreadyUsed { - ctx.RenderWithErr(ctx.Tr("form.email_has_been_used"), SETTINGS_EMAILS, &form) - return - } - ctx.Handle(500, "email.AddEmailAddress", err) + if err := models.AddEmailAddress(e); err != nil { + if err == models.ErrEmailAlreadyUsed { + ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_EMAILS, &form) return - } else { - - // Send confirmation e-mail - if setting.Service.RegisterEmailConfirm { - mailer.SendActivateEmail(ctx.Render, ctx.User, e) + } + ctx.Handle(500, "AddEmailAddress", err) + return + } else { + // Send confirmation e-mail + if setting.Service.RegisterEmailConfirm { + mailer.SendActivateEmail(ctx.Render, ctx.User, e) - if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { - log.Error(4, "Set cache(MailResendLimit) fail: %v", err) - } - ctx.Flash.Success(ctx.Tr("settings.add_email_success_confirmation_email_sent")) - } else { - ctx.Flash.Success(ctx.Tr("settings.add_email_success")) + if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { + log.Error(4, "Set cache(MailResendLimit) fail: %v", err) } - - log.Trace("Email address added: %s", e.Email) - - ctx.Redirect(setting.AppSubUrl + "/user/settings/email") - return + ctx.Flash.Success(ctx.Tr("settings.add_email_success_confirmation_email_sent")) + } else { + ctx.Flash.Success(ctx.Tr("settings.add_email_success")) } + log.Trace("Email address added: %s", e.Email) + ctx.Redirect(setting.AppSubUrl + "/user/settings/email") + return } ctx.HTML(200, SETTINGS_EMAILS) diff --git a/templates/.VERSION b/templates/.VERSION index 0c9421a4..489addf9 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.13.0214 Beta \ No newline at end of file +0.5.14.0221 Beta \ No newline at end of file diff --git a/templates/user/settings/email.tmpl b/templates/user/settings/email.tmpl index c99e6a04..ec152c5d 100644 --- a/templates/user/settings/email.tmpl +++ b/templates/user/settings/email.tmpl @@ -16,7 +16,7 @@ {{range .Emails}} -- cgit v1.2.3 From c753fdceaf0549aa865cff4e1f42be5d907bbdb1 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 22 Feb 2015 03:07:04 -0500 Subject: templates/org/home.tmpl: fix org member can't see public repo --- gogs.go | 2 +- templates/.VERSION | 2 +- templates/org/home.tmpl | 140 ++++++++++++++++++++++++------------------------ 3 files changed, 72 insertions(+), 72 deletions(-) (limited to 'templates') diff --git a/gogs.go b/gogs.go index 5c24e229..b2366b63 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.14.0221 Beta" +const APP_VER = "0.5.14.0222 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/templates/.VERSION b/templates/.VERSION index 489addf9..b9cd4a18 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.14.0221 Beta \ No newline at end of file +0.5.14.0222 Beta \ No newline at end of file diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index bb160b57..df29d61f 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -9,85 +9,85 @@ {{if .IsOrganizationOwner}}{{end}} {{if .Org.Description}}

    {{.Org.Description}}

    {{end}} - +
    {{$isMember := .Org.IsOrgMember $.SignedUser.Id}} -
    -
    - {{if .IsOrganizationOwner}} - {{.i18n.Tr "new_repo"}} - {{end}} -
    -
    - {{range .Repos}} - {{if .HasAccess $.SignedUser.Name}} -
    -
      -
    • {{.NumStars}}
    • -
    • {{.NumForks}}
    • -
    -

    {{.Name}}

    -

    {{.Description}}

    -

    {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

    -
    - {{end}} +
    +
    + {{if .IsOrganizationOwner}} + {{.i18n.Tr "new_repo"}} + {{end}} +
    +
    + {{range .Repos}} + {{if or (not .IsPrivate) (.HasAccess $.SignedUser.Name)}} +
    +
      +
    • {{.NumStars}}
    • +
    • {{.NumForks}}
    • +
    +

    {{.Name}}

    +

    {{.Description}}

    +

    {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

    +
    {{end}} -
    + {{end}}
    -
    -
    -
    -
    - {{if $isMember}} - {{.Org.NumMembers}} - {{end}} - {{.i18n.Tr "org.people"}} -
    -
    - {{range .Members}} +
    +
    +
    +
    +
    + {{if $isMember}} + {{.Org.NumMembers}} + {{end}} + {{.i18n.Tr "org.people"}} +
    +
    + {{range .Members}} {{if or $isMember (.IsPublicMember $.Org.Id)}} - - {{end}} + {{end}} -
    - {{if .IsOrganizationOwner}} - - {{end}} -
    - {{if $isMember}} -
    -
    -
    - {{.Org.NumTeams}} - {{.i18n.Tr "org.teams"}} -
    -
    -
      - {{range .Teams}} -
    • - {{.Name}} -

      {{.NumMembers}} {{$.i18n.Tr "org.lower_members"}} · {{.NumRepos}} {{$.i18n.Tr "org.lower_repositories"}}

      -
    • - {{end}} -
    -
    - {{if .IsOrganizationOwner}} - - {{end}} -
    - {{end}} + {{end}} +
    + {{if .IsOrganizationOwner}} + + {{end}}
    -
    + {{if $isMember}} +
    +
    +
    + {{.Org.NumTeams}} + {{.i18n.Tr "org.teams"}} +
    +
    +
      + {{range .Teams}} +
    • + {{.Name}} +

      {{.NumMembers}} {{$.i18n.Tr "org.lower_members"}} · {{.NumRepos}} {{$.i18n.Tr "org.lower_repositories"}}

      +
    • + {{end}} +
    +
    + {{if .IsOrganizationOwner}} + + {{end}} +
    + {{end}} +
    +
    {{template "ng/base/footer" .}} \ No newline at end of file -- cgit v1.2.3 From 059338139ca4a70cb1138dc09039abb5dac0d0f2 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 22 Feb 2015 09:49:25 -0500 Subject: routers: able to migrate repo from local path - modules/middleware/context.go: add HandleAPI method --- cmd/web.go | 4 +-- conf/locale/locale_en-US.ini | 2 ++ modules/auth/repo_form.go | 2 +- modules/middleware/context.go | 12 +++++++ routers/api/v1/repo.go | 75 ++++++++++++++++++++++--------------------- routers/repo/repo.go | 28 +++++++++------- templates/repo/migrate.tmpl | 4 +-- 7 files changed, 74 insertions(+), 53 deletions(-) (limited to 'templates') diff --git a/cmd/web.go b/cmd/web.go index 4b06a882..1b692ceb 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -79,7 +79,7 @@ func checkVersion() { // Check dependency version. checkers := []VerChecker{ {"github.com/Unknwon/macaron", macaron.Version, "0.5.1"}, - {"github.com/macaron-contrib/binding", binding.Version, "0.0.4"}, + {"github.com/macaron-contrib/binding", binding.Version, "0.0.5"}, {"github.com/macaron-contrib/cache", cache.Version, "0.0.7"}, {"github.com/macaron-contrib/csrf", csrf.Version, "0.0.3"}, {"github.com/macaron-contrib/i18n", i18n.Version, "0.0.5"}, @@ -229,7 +229,7 @@ func runWeb(ctx *cli.Context) { }) m.Any("/*", func(ctx *middleware.Context) { - ctx.JSON(404, &base.ApiJsonErr{"Not Found", base.DOC_URL}) + ctx.HandleAPI(404, "Page not found") }) }) }) diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 54b80abb..ca076b8b 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -286,6 +286,8 @@ need_auth = Need Authorization migrate_type = Migration Type migrate_type_helper = This repository will be a Mirror migrate_repo = Migrate Repository +migrate.clone_address = Clone Address +migrate.invalid_local_path = Invalid local path, it does not exist or not a directory. copy_link = Copy click_to_copy = Copy to clipboard diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index c771dd59..2902a92f 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -31,7 +31,7 @@ func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) bin } type MigrateRepoForm struct { - HttpsUrl string `form:"url" binding:"Required;Url"` + CloneAddr string `binding:"Required"` AuthUserName string `form:"auth_username"` AuthPasswd string `form:"auth_password"` Uid int64 `form:"uid" binding:"Required"` diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 28be3a30..45779d58 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -130,6 +130,18 @@ func (ctx *Context) Handle(status int, title string, err error) { ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) } +func (ctx *Context) HandleAPI(status int, obj interface{}) { + var message string + if err, ok := obj.(error); ok { + message = err.Error() + } else { + message = obj.(string) + } + ctx.JSON(status, map[string]string{ + "message": message, + }) +} + func (ctx *Context) ServeContent(name string, r io.ReadSeeker, params ...interface{}) { modtime := time.Now() for _, p := range params { diff --git a/routers/api/v1/repo.go b/routers/api/v1/repo.go index fbf9c73e..fde184d9 100644 --- a/routers/api/v1/repo.go +++ b/routers/api/v1/repo.go @@ -5,7 +5,7 @@ package v1 import ( - "fmt" + "net/url" "path" "strings" @@ -156,17 +156,15 @@ func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) { func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) { u, err := models.GetUserByName(ctx.Query("username")) if err != nil { - ctx.JSON(500, map[string]interface{}{ - "ok": false, - "error": err.Error(), - }) + if err == models.ErrUserNotExist { + ctx.HandleAPI(422, err) + } else { + ctx.HandleAPI(500, err) + } return } if !u.ValidtePassword(ctx.Query("password")) { - ctx.JSON(500, map[string]interface{}{ - "ok": false, - "error": "username or password is not correct", - }) + ctx.HandleAPI(422, "Username or password is not correct.") return } @@ -175,56 +173,59 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) { if form.Uid != u.Id { org, err := models.GetUserById(form.Uid) if err != nil { - log.Error(4, "GetUserById: %v", err) - ctx.Error(500) + if err == models.ErrUserNotExist { + ctx.HandleAPI(422, err) + } else { + ctx.HandleAPI(500, err) + } return } ctxUser = org } if ctx.HasError() { - ctx.JSON(422, map[string]interface{}{ - "ok": false, - "error": ctx.GetErrMsg(), - }) + ctx.HandleAPI(422, ctx.GetErrMsg()) return } if ctxUser.IsOrganization() { // Check ownership of organization. if !ctxUser.IsOwnedBy(u.Id) { - ctx.JSON(403, map[string]interface{}{ - "ok": false, - "error": "given user is not owner of organization", - }) + ctx.HandleAPI(403, "Given user is not owner of organization.") return } } - authStr := strings.Replace(fmt.Sprintf("://%s:%s", - form.AuthUserName, form.AuthPasswd), "@", "%40", -1) - url := strings.Replace(form.HttpsUrl, "://", authStr+"@", 1) - repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, - form.Mirror, url) - if err == nil { - log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) - ctx.JSON(200, map[string]interface{}{ - "ok": true, - "data": "/" + ctxUser.Name + "/" + form.RepoName, - }) + // Remote address can be HTTPS URL or local path. + remoteAddr := form.CloneAddr + if strings.HasPrefix(form.CloneAddr, "http") { + u, err := url.Parse(form.CloneAddr) + if err != nil { + ctx.HandleAPI(422, err) + return + } + if len(form.AuthUserName) > 0 || len(form.AuthPasswd) > 0 { + u.User = url.UserPassword(form.AuthUserName, form.AuthPasswd) + } + remoteAddr = u.String() + } else if !com.IsDir(remoteAddr) { + ctx.HandleAPI(422, "Invalid local path, it does not exist or not a directory.") return } - if repo != nil { - if errDelete := models.DeleteRepository(ctxUser.Id, repo.Id, ctxUser.Name); errDelete != nil { - log.Error(4, "DeleteRepository: %v", errDelete) + repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr) + if err != nil { + if repo != nil { + if errDelete := models.DeleteRepository(ctxUser.Id, repo.Id, ctxUser.Name); errDelete != nil { + log.Error(4, "DeleteRepository: %v", errDelete) + } } + ctx.HandleAPI(500, err) + return } - ctx.JSON(500, map[string]interface{}{ - "ok": false, - "error": err.Error(), - }) + log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) + ctx.WriteHeader(200) } // GET /user/repos diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 48f7b09b..dfd827bb 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -181,20 +181,26 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { } } - u, err := url.Parse(form.HttpsUrl) - - if err != nil || u.Scheme != "https" { - ctx.Data["Err_HttpsUrl"] = true - ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form) + // Remote address can be HTTPS URL or local path. + remoteAddr := form.CloneAddr + if strings.HasPrefix(form.CloneAddr, "http") { + u, err := url.Parse(form.CloneAddr) + if err != nil { + ctx.Data["Err_CloneAddr"] = true + ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form) + return + } + if len(form.AuthUserName) > 0 || len(form.AuthPasswd) > 0 { + u.User = url.UserPassword(form.AuthUserName, form.AuthPasswd) + } + remoteAddr = u.String() + } else if !com.IsDir(remoteAddr) { + ctx.Data["Err_CloneAddr"] = true + ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), MIGRATE, &form) return } - if len(form.AuthUserName) > 0 || len(form.AuthPasswd) > 0 { - u.User = url.UserPassword(form.AuthUserName, form.AuthPasswd) - } - - repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, - form.Mirror, u.String()) + repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr) if err == nil { log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + form.RepoName) diff --git a/templates/repo/migrate.tmpl b/templates/repo/migrate.tmpl index b28d0647..5869be15 100644 --- a/templates/repo/migrate.tmpl +++ b/templates/repo/migrate.tmpl @@ -7,8 +7,8 @@
    {{template "ng/base/alert" .}}
    - - + +
    -- cgit v1.2.3 From 04164eada3bc89bb3b54aa3dea0f22203ff4aa6e Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 22 Feb 2015 18:24:49 -0500 Subject: models: able to rename user with diff letter cases #981 - templates/org: mirror fix on name output - routers: add missing error check --- models/org.go | 2 +- models/user.go | 14 +++-- routers/org/setting.go | 15 +++-- routers/repo/setting.go | 2 +- routers/user/setting.go | 11 ++-- templates/org/base/header.tmpl | 2 +- templates/org/settings/nav.tmpl | 20 +++---- templates/org/settings/options.tmpl | 114 ++++++++++++++++++------------------ 8 files changed, 97 insertions(+), 83 deletions(-) (limited to 'templates') diff --git a/models/org.go b/models/org.go index 3d37a37d..b2f9c903 100644 --- a/models/org.go +++ b/models/org.go @@ -93,7 +93,7 @@ func CreateOrganization(org, owner *User) (*User, error) { return nil, ErrUserNameIllegal } - isExist, err := IsUserExist(org.Name) + isExist, err := IsUserExist(0, org.Name) if err != nil { return nil, err } else if isExist { diff --git a/models/user.go b/models/user.go index 9f9b0cd7..a974e081 100644 --- a/models/user.go +++ b/models/user.go @@ -249,11 +249,13 @@ func (u *User) GetFullNameFallback() string { // IsUserExist checks if given user name exist, // the user name should be noncased unique. -func IsUserExist(name string) (bool, error) { +// If uid is presented, then check will rule out that one, +// it is used when update a user name in settings page. +func IsUserExist(uid int64, name string) (bool, error) { if len(name) == 0 { return false, nil } - return x.Get(&User{LowerName: strings.ToLower(name)}) + return x.Where("id!=?", uid).Get(&User{LowerName: strings.ToLower(name)}) } // IsEmailUsed returns true if the e-mail has been used. @@ -278,7 +280,7 @@ func CreateUser(u *User) error { return ErrUserNameIllegal } - isExist, err := IsUserExist(u.Name) + isExist, err := IsUserExist(0, u.Name) if err != nil { return err } else if isExist { @@ -397,6 +399,10 @@ func ChangeUserName(u *User, newUserName string) (err error) { } newUserName = strings.ToLower(newUserName) + if u.LowerName == newUserName { + // User only change letter cases. + return nil + } // Update accesses of user. accesses := make([]Access, 0, 10) @@ -453,7 +459,7 @@ func ChangeUserName(u *User, newUserName string) (err error) { // UpdateUser updates user's information. func UpdateUser(u *User) error { - has, err := x.Where("id!=?", u.Id).And("type=?", INDIVIDUAL).And("email=?", u.Email).Get(new(User)) + has, err := x.Where("id!=?", u.Id).And("type=?", u.Type).And("email=?", u.Email).Get(new(User)) if err != nil { return err } else if has { diff --git a/routers/org/setting.go b/routers/org/setting.go index 41ec4a21..c638a032 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -39,18 +39,18 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) { // Check if organization name has been changed. if org.Name != form.OrgUserName { - isExist, err := models.IsUserExist(form.OrgUserName) + isExist, err := models.IsUserExist(org.Id, form.OrgUserName) if err != nil { ctx.Handle(500, "IsUserExist", err) return } else if isExist { + ctx.Data["Err_UserName"] = true ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), SETTINGS_OPTIONS, &form) return } else if err = models.ChangeUserName(org, form.OrgUserName); err != nil { if err == models.ErrUserNameIllegal { - ctx.Flash.Error(ctx.Tr("form.illegal_username")) - ctx.Redirect(setting.AppSubUrl + "/org/" + org.LowerName + "/settings") - return + ctx.Data["Err_UserName"] = true + ctx.RenderWithErr(ctx.Tr("form.illegal_username"), SETTINGS_OPTIONS, &form) } else { ctx.Handle(500, "ChangeUserName", err) } @@ -68,7 +68,12 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) { org.Avatar = base.EncodeMd5(form.Avatar) org.AvatarEmail = form.Avatar if err := models.UpdateUser(org); err != nil { - ctx.Handle(500, "UpdateUser", err) + if err == models.ErrEmailAlreadyUsed { + ctx.Data["Err_Email"] = true + ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_OPTIONS, &form) + } else { + ctx.Handle(500, "UpdateUser", err) + } return } log.Trace("Organization setting updated: %s", org.Name) diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 8368513a..b40ef2d9 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -109,7 +109,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { } newOwner := ctx.Query("new_owner_name") - isExist, err := models.IsUserExist(newOwner) + isExist, err := models.IsUserExist(0, newOwner) if err != nil { ctx.Handle(500, "IsUserExist", err) return diff --git a/routers/user/setting.go b/routers/user/setting.go index 9398f69a..a44d3b7e 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -50,7 +50,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { // Check if user name has been changed. if ctx.User.Name != form.UserName { - isExist, err := models.IsUserExist(form.UserName) + isExist, err := models.IsUserExist(ctx.User.Id, form.UserName) if err != nil { ctx.Handle(500, "IsUserExist", err) return @@ -58,11 +58,14 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), SETTINGS_PROFILE, &form) return } else if err = models.ChangeUserName(ctx.User, form.UserName); err != nil { - if err == models.ErrUserNameIllegal { + switch err { + case models.ErrUserNameIllegal: ctx.Flash.Error(ctx.Tr("form.illegal_username")) ctx.Redirect(setting.AppSubUrl + "/user/settings") - return - } else { + case models.ErrEmailAlreadyUsed: + ctx.Flash.Error(ctx.Tr("form.email_been_used")) + ctx.Redirect(setting.AppSubUrl + "/user/settings") + default: ctx.Handle(500, "ChangeUserName", err) } return diff --git a/templates/org/base/header.tmpl b/templates/org/base/header.tmpl index 1bbb092b..1649b920 100644 --- a/templates/org/base/header.tmpl +++ b/templates/org/base/header.tmpl @@ -2,7 +2,7 @@
    - {{.Org.FullName}} + {{if .Org.FullName}}{{.Org.FullName}}{{else}}{{.Org.Name}}{{end}}