finish new repo options page

This commit is contained in:
Unknwon 2015-08-31 13:36:31 +08:00
parent c6b039c6f9
commit cb381078ff
7 changed files with 53 additions and 58 deletions

View File

@ -496,8 +496,7 @@ settings.basic_settings = Basic Settings
settings.danger_zone = Danger Zone settings.danger_zone = Danger Zone
settings.site = Official Site settings.site = Official Site
settings.update_settings = Update Settings settings.update_settings = Update Settings
settings.change_reponame = Repository Name Changed settings.change_reponame_prompt = This change will affect how links relate to the repository.
settings.change_reponame_desc = Repository name was changed. This will affect how links relate to the repository. Do you want to continue?
settings.transfer = Transfer Ownership settings.transfer = Transfer Ownership
settings.transfer_desc = Transfer this repository to another user or to an organization in which you have admin rights. settings.transfer_desc = Transfer this repository to another user or to an organization in which you have admin rights.
settings.new_owner_has_same_repo = The new owner already has a repository with same name. Please choose another name. settings.new_owner_has_same_repo = The new owner already has a repository with same name. Please choose another name.

View File

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.6.7.0830 Beta" const APP_VER = "0.6.7.0831 Beta"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

File diff suppressed because one or more lines are too long

View File

@ -182,6 +182,18 @@ function initRepository() {
return; return;
} }
// Options
if ($('.repository.settings.options').length > 0) {
$('#repo_name').keyup(function () {
var $prompt_span = $('#repo-name-change-prompt');
if ($(this).val().toLowerCase() != $(this).data('repo-name').toLowerCase()) {
$prompt_span.show();
}else{
$prompt_span.hide();
}
});
}
// Labels // Labels
if ($('.repository.labels').length > 0) { if ($('.repository.labels').length > 0) {
// Create label // Create label

View File

@ -44,6 +44,8 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsOptions"] = true ctx.Data["PageIsSettingsOptions"] = true
repo := ctx.Repo.Repository
switch ctx.Query("action") { switch ctx.Query("action") {
case "update": case "update":
if ctx.HasError() { if ctx.HasError() {
@ -53,44 +55,41 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
newRepoName := form.RepoName newRepoName := form.RepoName
// Check if repository name has been changed. // Check if repository name has been changed.
if ctx.Repo.Repository.Name != newRepoName { if repo.LowerName != strings.ToLower(newRepoName) {
if err := models.ChangeRepositoryName(ctx.Repo.Owner, ctx.Repo.Repository.Name, newRepoName); err != nil { if err := models.ChangeRepositoryName(ctx.Repo.Owner, repo.Name, newRepoName); err != nil {
ctx.Data["Err_RepoName"] = true
switch { switch {
case models.IsErrRepoAlreadyExist(err): case models.IsErrRepoAlreadyExist(err):
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), SETTINGS_OPTIONS, &form) ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), SETTINGS_OPTIONS, &form)
case models.IsErrNameReserved(err): case models.IsErrNameReserved(err):
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), SETTINGS_OPTIONS, &form) ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), SETTINGS_OPTIONS, &form)
case models.IsErrNamePatternNotAllowed(err): case models.IsErrNamePatternNotAllowed(err):
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), SETTINGS_OPTIONS, &form) ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), SETTINGS_OPTIONS, &form)
default: default:
ctx.Handle(500, "ChangeRepositoryName", err) ctx.Handle(500, "ChangeRepositoryName", err)
} }
return return
} }
log.Trace("Repository name changed: %s/%s -> %s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newRepoName) log.Trace("Repository name changed: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newRepoName)
ctx.Repo.Repository.Name = newRepoName
ctx.Repo.Repository.LowerName = strings.ToLower(newRepoName)
} }
// In case it's just a case change.
repo.Name = newRepoName
repo.LowerName = strings.ToLower(newRepoName)
br := form.Branch if ctx.Repo.GitRepo.IsBranchExist(form.Branch) {
repo.DefaultBranch = form.Branch
if ctx.Repo.GitRepo.IsBranchExist(br) {
ctx.Repo.Repository.DefaultBranch = br
} }
ctx.Repo.Repository.Description = form.Description repo.Description = form.Description
ctx.Repo.Repository.Website = form.Website repo.Website = form.Website
visibilityChanged := ctx.Repo.Repository.IsPrivate != form.Private visibilityChanged := repo.IsPrivate != form.Private
ctx.Repo.Repository.IsPrivate = form.Private repo.IsPrivate = form.Private
if err := models.UpdateRepository(ctx.Repo.Repository, visibilityChanged); err != nil { if err := models.UpdateRepository(repo, visibilityChanged); err != nil {
ctx.Handle(404, "UpdateRepository", err) ctx.Handle(404, "UpdateRepository", err)
return return
} }
log.Trace("Repository updated: %s/%s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) log.Trace("Repository updated: %s/%s", ctx.Repo.Owner.Name, repo.Name)
if ctx.Repo.Repository.IsMirror { if repo.IsMirror {
if form.Interval > 0 { if form.Interval > 0 {
ctx.Repo.Mirror.Interval = form.Interval ctx.Repo.Mirror.Interval = form.Interval
ctx.Repo.Mirror.NextUpdate = time.Now().Add(time.Duration(form.Interval) * time.Hour) ctx.Repo.Mirror.NextUpdate = time.Now().Add(time.Duration(form.Interval) * time.Hour)
@ -101,13 +100,20 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
} }
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
ctx.Redirect(fmt.Sprintf("%s/%s/%s/settings", setting.AppSubUrl, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)) ctx.Redirect(fmt.Sprintf("%s/%s/%s/settings", setting.AppSubUrl, ctx.Repo.Owner.Name, repo.Name))
case "transfer": case "transfer":
if ctx.Repo.Repository.Name != form.RepoName { if repo.Name != form.RepoName {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil) ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil)
return return
} }
if ctx.Repo.Owner.IsOrganization() {
if !ctx.Repo.Owner.IsOwnedBy(ctx.User.Id) {
ctx.Error(404)
return
}
}
newOwner := ctx.Query("new_owner_name") newOwner := ctx.Query("new_owner_name")
isExist, err := models.IsUserExist(0, newOwner) isExist, err := models.IsUserExist(0, newOwner)
if err != nil { if err != nil {
@ -118,16 +124,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
return return
} }
if _, err = models.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil { if err = models.TransferOwnership(ctx.User, newOwner, repo); err != nil {
if models.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_OPTIONS, nil)
} else {
ctx.Handle(500, "UserSignIn", err)
}
return
}
if err = models.TransferOwnership(ctx.User, newOwner, ctx.Repo.Repository); err != nil {
if models.IsErrRepoAlreadyExist(err) { if models.IsErrRepoAlreadyExist(err) {
ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), SETTINGS_OPTIONS, nil) ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), SETTINGS_OPTIONS, nil)
} else { } else {
@ -135,11 +132,11 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
} }
return return
} }
log.Trace("Repository transfered: %s/%s -> %s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newOwner) log.Trace("Repository transfered: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newOwner)
ctx.Flash.Success(ctx.Tr("repo.settings.transfer_succeed")) ctx.Flash.Success(ctx.Tr("repo.settings.transfer_succeed"))
ctx.Redirect(setting.AppSubUrl + "/") ctx.Redirect(setting.AppSubUrl + "/" + newOwner + "/" + repo.Name)
case "delete": case "delete":
if ctx.Repo.Repository.Name != form.RepoName { if repo.Name != form.RepoName {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil) ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil)
return return
} }
@ -151,25 +148,12 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
} }
} }
if _, err := models.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil { if err := models.DeleteRepository(ctx.Repo.Owner.Id, repo.ID, ctx.Repo.Owner.Name); err != nil {
if models.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_OPTIONS, nil)
} else {
ctx.Handle(500, "UserSignIn", err)
}
return
}
if err := models.DeleteRepository(ctx.Repo.Owner.Id, ctx.Repo.Repository.ID, ctx.Repo.Owner.Name); err != nil {
ctx.Handle(500, "DeleteRepository", err) ctx.Handle(500, "DeleteRepository", err)
return return
} }
log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, repo.Name)
if ctx.Repo.Owner.IsOrganization() { ctx.Redirect(ctx.Repo.Owner.DashboardLink())
ctx.Redirect(setting.AppSubUrl + "/org/" + ctx.Repo.Owner.Name + "/dashboard")
} else {
ctx.Redirect(setting.AppSubUrl + "/")
}
} }
} }

View File

@ -1 +1 @@
0.6.7.0830 Beta 0.6.7.0831 Beta

View File

@ -14,7 +14,7 @@
{{.CsrfTokenHtml}} {{.CsrfTokenHtml}}
<input type="hidden" name="action" value="update"> <input type="hidden" name="action" value="update">
<div class="required field {{if .Err_RepoName}}error{{end}}"> <div class="required field {{if .Err_RepoName}}error{{end}}">
<label for="repo_name">{{.i18n.Tr "repo.repo_name"}}</label> <label for="repo_name">{{.i18n.Tr "repo.repo_name"}}<span class="text red hide" id="repo-name-change-prompt"> {{.i18n.Tr "repo.settings.change_reponame_prompt"}}</span></label>
<input id="repo_name" name="repo_name" value="{{.Repository.Name}}" data-repo-name="{{.Repository.Name}}" autofocus required> <input id="repo_name" name="repo_name" value="{{.Repository.Name}}" data-repo-name="{{.Repository.Name}}" autofocus required>
</div> </div>
<div class="field {{if .Err_Description}}error{{end}}"> <div class="field {{if .Err_Description}}error{{end}}">
@ -46,7 +46,7 @@
<div class="inline field"> <div class="inline field">
<label>{{.i18n.Tr "repo.visibility"}}</label> <label>{{.i18n.Tr "repo.visibility"}}</label>
<div class="ui checkbox"> <div class="ui checkbox">
<input name="private" type="checkbox" {{if .private}}checked{{end}}> <input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}>
<label>{{.i18n.Tr "repo.visiblity_helper" | Safe}}</label> <label>{{.i18n.Tr "repo.visiblity_helper" | Safe}}</label>
</div> </div>
</div> </div>