diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 8d5e85d89..d25064a8f 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -60,6 +60,7 @@ Email = E-mail address Password = Password Retype = Re-type password SSHTitle = SSH key name +HttpsUrl = HTTPS URL require_error = ` cannot be empty.` alpha_dash_error = ` must be valid alpha or numeric or dash(-_) characters.` @@ -83,6 +84,7 @@ illegal_org_name = Organization name contains illegal characters. username_password_incorrect = Username or password is not correct. invalid_ssh_key = Sorry, we're not able to verify your SSH key: %s +auth_failed = Authentication failed: %v still_own_repo = Your account still have ownership of repository, you have to delete or transfer them first. @@ -142,6 +144,11 @@ license_helper = Select a license file init_readme = Initialize this repository with a README.md create_repo = Create Repository +need_auth = Need Authorization +migrate_type = Migration Type +migrate_type_helper = This repository will be a Mirror +migrate_repo = Migrate Repository + [org] org_name_holder = Organization Name org_name_helper = Great organization names are short and memorable. diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index 9ec267cd3..8ed157e66 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -60,6 +60,7 @@ Email = 邮箱地址 Password = 密码 Retype = 确认密码 SSHTitle = SSH 密钥名称 +HttpsUrl = HTTPS URL 地址 require_error = 不能为空。 alpha_dash_error = 必须为英文字母、阿拉伯数字或横线(-_)。 @@ -83,6 +84,7 @@ illegal_org_name = 组织名称包含非法字符。 username_password_incorrect = 用户名或密码不正确。 invalid_ssh_key = 很抱歉,我们无法验证您输入的 SSH 密钥:%s +auth_failed = 授权验证失败:%v still_own_repo = 您的帐户仍然是某些仓库的拥有者,您必须先转移或删除它们才能执行删除帐户操作! @@ -142,6 +144,11 @@ license_helper = 请选择授权许可文件 init_readme = 使用 README.md 文件初始化仓库 create_repo = 创建仓库 +need_auth = 需要授权验证 +migrate_type = 迁移类型 +migrate_type_helper = 本仓库将是 镜像 +migrate_repo = 迁移仓库 + [org] org_name_holder = 组织名称 org_name_helper = 伟大的组织都有一个简短而寓意深刻的名字。 diff --git a/gogs.go b/gogs.go index 8e3635a1e..77a9b1b75 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.4.7.0731 Alpha" +const APP_VER = "0.4.7.0801 Alpha" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 11efb24d1..12bf5df50 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -33,11 +33,11 @@ func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs *binding.Errors, l } type MigrateRepoForm struct { - Url string `form:"url" binding:"Url"` + HttpsUrl string `form:"url" binding:"Url"` AuthUserName string `form:"auth_username"` AuthPasswd string `form:"auth_password"` Uid int64 `form:"uid" binding:"Required"` - RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"` + RepoName string `form:"repo_name" binding:"Required;AlphaDash;MaxSize(100)"` Mirror bool `form:"mirror"` Private bool `form:"private"` Description string `form:"desc" binding:"MaxSize(255)"` diff --git a/public/ng/css/gogs.css b/public/ng/css/gogs.css index 2b8f57608..b9eea52d2 100644 --- a/public/ng/css/gogs.css +++ b/public/ng/css/gogs.css @@ -294,6 +294,8 @@ img.avatar-30 { border: 1px solid #ddd; border-radius: .25em; margin: 5px 0; + padding: 10px; + background-color: #f8f8f8; } .markdown > pre.linenums { padding: 0; @@ -836,6 +838,9 @@ The register and sign-in page style margin-left: -15px; } /* repository main */ +#repo-wrapper { + padding-bottom: 100px; +} #repo-header { height: 69px; border-bottom: 1px solid #d6d6d6; @@ -1100,29 +1105,36 @@ The register and sign-in page style width: 520px; } /* repository create */ +#repo-migrate-form, #repo-create-form { width: 800px; - margin: 60px auto 150px auto; + margin: 60px auto auto auto; background: white; } +#repo-migrate-form h2, #repo-create-form h2 { margin: .5em 1em; } +#repo-migrate-form .field, #repo-create-form .field { margin: 1.2em 0 2em 0; } +#repo-migrate-form .ipt, #repo-create-form .ipt { width: 540px; } +#repo-migrate-form textarea, #repo-create-form textarea { height: 120px; } +#repo-migrate-form .avatar, #repo-create-form .avatar { vertical-align: middle; margin-right: .6em; width: 28px; height: 28px; } +#repo-migrate-form:hover, #repo-create-form:hover { box-shadow: 0px 0px 6px #CCC; } diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js index ae2e8712b..a861255e3 100644 --- a/public/ng/js/gogs.js +++ b/public/ng/js/gogs.js @@ -59,7 +59,7 @@ var Gogs = {}; Gogs.renderMarkdown = function () { var $md = $('.markdown'); var $pre = $md.find('pre > code').parent(); - $pre.addClass('prettyprint linenums'); + $pre.addClass('prettyprint'); prettyPrint(); // Set anchor. @@ -166,11 +166,17 @@ function initRepoCreate() { console.log("set repo owner to uid :", uid, $(this).text().trim()); } }); + + $('#auth-button').click(function (e) { + $('#repo-migrate-auth').slideToggle('fast'); + e.preventDefault(); + }) + console.log('initRepoCreate'); } $(document).ready(function () { initCore(); - if ($('#repo-create-form').length) { + if ($('#repo-create-form').length || $('#repo-migrate-form').length) { initRepoCreate(); } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 5e7875e22..9b3aca4c3 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -27,7 +27,6 @@ const ( func Create(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("new_repo") - ctx.Data["PageIsRepoCreate"] = true // Give default value for template to render. ctx.Data["gitignore"] = "0" @@ -57,7 +56,6 @@ func Create(ctx *middleware.Context) { func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.Data["Title"] = ctx.Tr("new_repo") - ctx.Data["PageIsRepoCreate"] = true ctx.Data["Gitignores"] = models.Gitignores ctx.Data["Licenses"] = models.Licenses @@ -100,9 +98,11 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.Redirect("/" + ctxUser.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { + ctx.Data["Err_RepoName"] = true ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), CREATE, &form) return } else if err == models.ErrRepoNameIllegal { + ctx.Data["Err_RepoName"] = true ctx.RenderWithErr(ctx.Tr("form.illegal_repo_name"), CREATE, &form) return } @@ -112,12 +112,22 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { log.Error(4, "DeleteRepository: %v", errDelete) } } - ctx.Handle(500, "CreateRepository", err) + ctx.Handle(500, "CreatePost", err) } func Migrate(ctx *middleware.Context) { - ctx.Data["Title"] = "Migrate repository" - ctx.Data["PageIsNewRepo"] = true + ctx.Data["Title"] = ctx.Tr("new_migrate") + + ctxUser := ctx.User + if orgId := com.StrTo(ctx.Query("org")).MustInt64(); orgId > 0 { + org, err := models.GetUserById(orgId) + if err != nil && err != models.ErrUserNotExist { + ctx.Handle(500, "GetUserById", err) + return + } + ctxUser = org + } + ctx.Data["ContextUser"] = ctxUser if err := ctx.User.GetOrganizations(); err != nil { ctx.Handle(500, "GetOrganizations", err) @@ -129,8 +139,18 @@ func Migrate(ctx *middleware.Context) { } func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { - ctx.Data["Title"] = "Migrate repository" - ctx.Data["PageIsNewRepo"] = true + ctx.Data["Title"] = ctx.Tr("new_migrate") + + ctxUser := ctx.User + if orgId := com.StrTo(ctx.Query("org")).MustInt64(); orgId > 0 { + org, err := models.GetUserById(orgId) + if err != nil && err != models.ErrUserNotExist { + ctx.Handle(500, "GetUserById", err) + return + } + ctxUser = org + } + ctx.Data["ContextUser"] = ctxUser if err := ctx.User.GetOrganizations(); err != nil { ctx.Handle(500, "GetOrganizations", err) @@ -143,49 +163,45 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { return } - u := ctx.User - // Not equal means current user is an organization. - if u.Id != form.Uid { - var err error - u, err = models.GetUserById(form.Uid) - if err != nil { - if err == models.ErrUserNotExist { - ctx.Handle(404, "GetUserById", err) - } else { - ctx.Handle(500, "GetUserById", err) - } + if ctxUser.IsOrganization() { + // Check ownership of organization. + if !ctxUser.IsOrgOwner(ctx.User.Id) { + ctx.Error(403) return } } authStr := strings.Replace(fmt.Sprintf("://%s:%s", form.AuthUserName, form.AuthPasswd), "@", "%40", -1) - url := strings.Replace(form.Url, "://", authStr+"@", 1) - repo, err := models.MigrateRepository(u, form.RepoName, form.Description, form.Private, + 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("%s Repository migrated: %s/%s", ctx.Req.RequestURI, u.LowerName, form.RepoName) - ctx.Redirect("/" + u.Name + "/" + form.RepoName) + log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) + ctx.Redirect("/" + ctxUser.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { - ctx.RenderWithErr("Repository name has already been used", MIGRATE, &form) + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), MIGRATE, &form) return } else if err == models.ErrRepoNameIllegal { - ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), MIGRATE, &form) + ctx.Data["Err_RepoName"] = true + ctx.RenderWithErr(ctx.Tr("form.illegal_repo_name"), MIGRATE, &form) return } if repo != nil { - if errDelete := models.DeleteRepository(u.Id, repo.Id, u.Name); errDelete != nil { + if errDelete := models.DeleteRepository(ctxUser.Id, repo.Id, ctxUser.Name); errDelete != nil { log.Error(4, "DeleteRepository: %v", errDelete) } } if strings.Contains(err.Error(), "Authentication failed") { - ctx.RenderWithErr(err.Error(), MIGRATE, &form) + ctx.Data["Err_Auth"] = true + ctx.RenderWithErr(ctx.Tr("form.auth_failed", err), MIGRATE, &form) return } - ctx.Handle(500, "MigrateRepository", err) + ctx.Handle(500, "MigratePost", err) } // func Action(ctx *middleware.Context, params martini.Params) { diff --git a/templates/.VERSION b/templates/.VERSION index 82b0c22eb..7cfc6b858 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.4.7.0731 Alpha \ No newline at end of file +0.4.7.0801 Alpha \ No newline at end of file diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index 13656becc..a144ccbc3 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -36,7 +36,7 @@
- + {{.i18n.Tr "repo.repo_name_helper" | Str2html}}
@@ -47,7 +47,7 @@

- +

diff --git a/templates/repo/migrate.tmpl b/templates/repo/migrate.tmpl index fff25e6de..721596071 100644 --- a/templates/repo/migrate.tmpl +++ b/templates/repo/migrate.tmpl @@ -1,127 +1,82 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -

-
+{{template "ng/base/head" .}} +{{template "ng/base/header" .}} +
+ {{.CsrfTokenHtml}} -

Repository Migration

- {{template "base/alert" .}} - - -
- -
- -
-
- -
- -
-
- -
- +
+ + +
+
+ +
-
-
- -
- +
+ +
-
-
-
- -
-
- - - +
+
+ + +
- -
- -
- -
- - Great repository names are short and memorable. +
+ +
-
- -
- -
-
- -
-
-
- -
- -
-
- -
-
-
- -
- -
- -
-
- -
-
- - Cancel +

+ + + {{.i18n.Tr "repo.visiblity_helper" | Str2html}} +

+

+ + + {{.i18n.Tr "repo.migrate_type_helper" | Str2html}} +

+
+ +
+

+ + + {{.i18n.Tr "cancel"}} +

-{{template "base/footer" .}} \ No newline at end of file +{{template "ng/base/footer" .}} \ No newline at end of file