diff options
-rw-r--r-- | conf/locale/locale_en-US.ini | 7 | ||||
-rw-r--r-- | conf/locale/locale_zh-CN.ini | 7 | ||||
-rw-r--r-- | gogs.go | 2 | ||||
-rw-r--r-- | modules/auth/repo_form.go | 4 | ||||
-rw-r--r-- | public/ng/css/gogs.css | 14 | ||||
-rw-r--r-- | public/ng/js/gogs.js | 10 | ||||
-rw-r--r-- | routers/repo/repo.go | 70 | ||||
-rw-r--r-- | templates/.VERSION | 2 | ||||
-rw-r--r-- | templates/repo/create.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/migrate.tmpl | 183 |
10 files changed, 153 insertions, 150 deletions
diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 8d5e85d89c..d25064a8f2 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 <span class="label label-blue label-radius">Mirror</span> +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 9ec267cd39..8ed157e66b 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 = 本仓库将是 <span class="label label-blue label-radius">镜像</span> +migrate_repo = 迁移仓库 + [org] org_name_holder = 组织名称 org_name_helper = 伟大的组织都有一个简短而寓意深刻的名字。 @@ -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 11efb24d1c..12bf5df501 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 2b8f57608f..b9eea52d25 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 ae2e8712b4..a861255e3e 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 5e7875e22f..9b3aca4c3d 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 82b0c22eb5..7cfc6b8584 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 13656becc2..a144ccbc36 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -36,7 +36,7 @@ </div> <div class="field"> <label class="req" for="repo-name">{{.i18n.Tr "repo.repo_name"}}</label> - <input class="ipt ipt-radius" id="repo-name" name="repo_name" type="text" value="{{.repo_name}}" required /> + <input class="ipt ipt-radius {{if .Err_RepoName}}ipt-error{{end}}" id="repo-name" name="repo_name" type="text" value="{{.repo_name}}" required /> <span class="form-label"></span> <span class="help">{{.i18n.Tr "repo.repo_name_helper" | Str2html}}</span> </div> @@ -47,7 +47,7 @@ </p> <div class="field clear"> <label class="left" for="desc">{{.i18n.Tr "repo.repo_desc"}}</label> - <textarea class="ipt ipt-radius" id="desc" name="desc">{{.desc}}</textarea> + <textarea class="ipt ipt-radius {{if .Err_Description}}ipt-error{{end}}" id="desc" name="desc">{{.desc}}</textarea> </div> <p class="field"> <label for="lang">{{.i18n.Tr "repo.repo_lang"}}</label> diff --git a/templates/repo/migrate.tmpl b/templates/repo/migrate.tmpl index fff25e6de5..7215960714 100644 --- a/templates/repo/migrate.tmpl +++ b/templates/repo/migrate.tmpl @@ -1,127 +1,82 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -<div class="container" id="body"> - <form action="/repo/migrate" method="post" class="form-horizontal card" id="repo-create"> +{{template "ng/base/head" .}} +{{template "ng/base/header" .}} +<div id="repo-wrapper"> + <form id="repo-migrate-form" class="form form-align panel panel-radius" action="/repo/migrate" method="post"> {{.CsrfTokenHtml}} - <h3>Repository Migration</h3> - {{template "base/alert" .}} - <!-- <div class="form-group"> - <label class="col-md-2 control-label">From<strong class="text-danger">*</strong></label> - <div class="col-md-8"> - <select class="form-control" name="from"> - <option value="github">GitHub</option> - </select> + <div class="panel-header"><h2>{{.i18n.Tr "new_migrate"}}</h2></div> + <div class="panel-content"> + {{template "ng/base/alert" .}} + <div class="field"> + <label class="req" for="url">HTTPS URL</label> + <input class="ipt ipt-radius {{if .Err_HttpsUrl}}ipt-error{{end}}" id="url" name="url" type="text" value="{{.url}}" required /> </div> - </div> --> - - <div class="form-group"> - <label class="col-md-2 control-label">HTTPS URL<strong class="text-danger">*</strong></label> - <div class="col-md-8"> - <input name="url" type="text" class="form-control" placeholder="Type your migration repository HTTPS URL" value="{{.url}}" required="required" > - </div> - </div> - - <div class="form-group"> - <div class="col-md-offset-2 col-md-8"> - <a class="btn btn-default" data-toggle="collapse" data-target="#repo-import-auth">Need Authorization</a> - </div> - <div id="repo-import-auth" class="collapse"> - <div class="form-group"> - <label class="col-md-2 control-label">Username</label> - <div class="col-md-8"> - <input name="auth_username" type="text" class="form-control" placeholder="Type your user name" value="{{.auth_username}}" > - </div> - </div> - <div class="form-group"> - <label class="col-md-2 control-label">Password</label> - <div class="col-md-8"> - <input name="auth_password" type="password" class="form-control" placeholder="Type your password" value="{{.auth_password}}" > + <div class="field"> + <span class="form-label"></span> + <button class="btn btn-large btn-gray btn-radius" id="auth-button" data-toggle="collapse" data-target="#repo-import-auth">{{.i18n.Tr "repo.need_auth"}}</button> + <div id="repo-migrate-auth" {{if not .Err_Auth}}class="hide"{{end}}> + <div class="field"> + <label for="auth_username">{{.i18n.Tr "username"}}</label> + <input class="ipt ipt-radius {{if .Err_Auth}}ipt-error{{end}}" id="auth_username" name="auth_username" type="text" value="{{.auth_username}}" /> </div> - </div> - </div> - </div> - <hr/> - <div class="form-group"> - <label class="col-md-2 control-label">Owner<strong class="text-danger">*</strong></label> - <div class="col-md-8"> - <div class="btn-group" id="repo-owner-switch"> - <button type="button" class="btn btn-default" id="repo-owner-current"> - <img src="{{.SignedUser.AvatarLink}}?s=28" alt="user-avatar" title="username" id="repo-owner-avatar"> - <span id="repo-owner-name">{{.SignedUser.Name}}</span> - </button> - <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> - <span class="caret"></span> - </button> - <div class="dropdown-menu clone-group-btn no-propagation"> - <ul id="dashboard-switch-menu" class="list-unstyled"> - <li data-uid="{{.SignedUser.Id}}" class="checked"> - <a> - <i class="fa fa-check"></i> - <img src="{{.SignedUser.AvatarLink}}?s=28" alt="user-avatar" title="username"> - {{.SignedUser.Name}} - </a> - </li> - {{range .Orgs}} - <li data-uid="{{.Id}}"> - <a> - <i class="fa fa-check"></i> - <img src="{{.AvatarLink}}?s=28" alt="user-avatar" title="username"> - {{.Name}} - </a> - </li> - {{end}} - </ul> + <div class="field"> + <label for="auth_password">{{.i18n.Tr "password"}}</label> + <input class="ipt ipt-radius {{if .Err_Auth}}ipt-error{{end}}" id="auth_password" name="auth_password" type="text" value="{{.auth_password}}" /> </div> </div> </div> - <input type="hidden" value="{{.SignedUserId}}" name="uid" id="repo-owner-id"/> - </div> - - <div class="form-group {{if .Err_RepoName}}has-error has-feedback{{end}}"> - <label class="col-md-2 control-label">Repository<strong class="text-danger">*</strong></label> - <div class="col-md-8"> - <input name="repo" type="text" class="form-control" placeholder="Type your repository name" value="{{.repo}}" required="required"> - <span class="help-block">Great repository names are short and memorable. </span> - </div> - </div> - - <div class="form-group"> - <label class="col-md-2 control-label">Migration Type</label> - <div class="col-md-8"> - <div class="checkbox"> - <label> - <input type="checkbox" name="mirror" {{if .mirror}}checked{{end}}> - <strong>This repository is a mirror</strong> - </label> - </div> - </div> - </div> - - <div class="form-group"> - <label class="col-md-2 control-label">Visibility</label> - <div class="col-md-8"> - <div class="checkbox"> - <label> - <input type="checkbox" name="private" {{if .private}}checked{{end}}> - <strong>This repository is private</strong> - </label> + <hr/> + <div class="field"> + <label for="owner" class="req">{{.i18n.Tr "repo.owner"}}</label> + <input id="repo-owner-id" type="hidden" name="uid" value="{{.ContextUser.Id}}" /> + <div class="inline-block drop"> + <a href="#" class="drop-bottom"> + <img class="avatar" src="{{.ContextUser.AvatarLink}}" id="repo-owner-avatar" alt="user-avatar"> + <strong id="repo-owner-name">{{.ContextUser.Name}}</strong> + </a> + <ul class="drop-down menu menu-vertical menu-radius switching-list" id="repo-create-owner-list"> + <li {{if eq $.ContextUser.Id .SignedUser.Id}}class="checked"{{end}} data-uid="{{.SignedUser.Id}}"> + <a> + <i class="octicon octicon-check"></i> + <img class="avatar" src="{{.SignedUser.AvatarLink}}" alt="user-avatar"> + <strong>{{.SignedUser.Name}}</strong> + </a> + </li> + {{range .Orgs}} + <li {{if eq $.ContextUser.Id .Id}}class="checked"{{end}} data-uid="{{.Id}}"> + <a> + <i class="octicon octicon-check"></i> + <img class="avatar" src="{{.AvatarLink}}" alt="user-avatar"> + <strong>{{.Name}}</strong> + </a> + </li> + {{end}} + </ul> </div> </div> - </div> - - <div class="form-group {{if .Err_Description}}has-error has-feedback{{end}}"> - <label class="col-md-2 control-label">Description</label> - <div class="col-md-8"> - <textarea name="desc" class="form-control" placeholder="Type your repository description">{{.desc}}</textarea> + <div class="field"> + <label class="req" for="repo-name">{{.i18n.Tr "repo.repo_name"}}</label> + <input class="ipt ipt-radius {{if .Err_RepoName}}ipt-error{{end}}" id="repo-name" name="repo_name" type="text" value="{{.repo_name}}" required /> </div> - </div> - - <div class="form-group"> - <div class="col-md-offset-2 col-md-8"> - <button type="submit" class="btn btn-lg btn-primary">Migrate repository</button> - <a href="/" class="text-danger">Cancel</a> + <p class="field"> + <label for="visibility">{{.i18n.Tr "repo.visibility"}}</label> + <input class="ipt-chk" id="visibility" name="private" type="checkbox" {{if .private}}checked{{end}} /> + <span>{{.i18n.Tr "repo.visiblity_helper" | Str2html}}</span> + </p> + <p class="field"> + <label for="visibility">{{.i18n.Tr "repo.migrate_type"}}</label> + <input class="ipt-chk" id="visibility" name="mirror" type="checkbox" {{if .mirror}}checked{{end}} /> + <span>{{.i18n.Tr "repo.migrate_type_helper" | Str2html}}</span> + </p> + <div class="field clear"> + <label class="left" for="desc">{{.i18n.Tr "repo.repo_desc"}}</label> + <textarea class="ipt ipt-radius {{if .Err_Description}}ipt-error{{end}}" id="desc" name="desc">{{.desc}}</textarea> </div> + <p class="field"> + <label for="repo-create-submit"></label> + <button class="btn btn-large btn-blue btn-radius" id="repo-create-submit">{{.i18n.Tr "repo.migrate_repo"}}</button> + <a class="btn btn-small btn-gray btn-radius" id="repo-create-cancel" href="/"><strong>{{.i18n.Tr "cancel"}}</strong></a> + </p> </div> </form> </div> -{{template "base/footer" .}}
\ No newline at end of file +{{template "ng/base/footer" .}}
\ No newline at end of file |