From b466a3654d8f78723805eb13ac0312a5d1fdc865 Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Wed, 19 Jan 2022 12:08:15 +0800 Subject: [PATCH 1/5] convert alias to lowercase when check --- models/repo.go | 14 ++++++++------ routers/repo/setting.go | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/models/repo.go b/models/repo.go index f32b42ef7..0ae395c78 100755 --- a/models/repo.go +++ b/models/repo.go @@ -222,9 +222,10 @@ type Repository struct { CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` - Hot int64 `xorm:"-"` - Active int64 `xorm:"-"` - Alias string + Hot int64 `xorm:"-"` + Active int64 `xorm:"-"` + Alias string `xorm:"INDEX"` + LowerAlias string `xorm:"INDEX"` } // SanitizedOriginalURL returns a sanitized OriginalURL @@ -942,10 +943,10 @@ func isRepositoryExist(e Engine, u *User, repoName string, alias string) (bool, cond = cond.And(builder.Eq{"owner_id": u.ID}) if alias != "" { subCon := builder.NewCond() - subCon = subCon.Or(builder.Eq{"alias": alias}, builder.Eq{"lower_name": repoName}) + subCon = subCon.Or(builder.Eq{"lower_alias": strings.ToLower(alias)}, builder.Eq{"lower_name": strings.ToLower(repoName)}) cond = cond.And(subCon) } else { - cond = cond.And(builder.Eq{"lower_name": repoName}) + cond = cond.And(builder.Eq{"lower_name": strings.ToLower(repoName)}) } count, err := e.Where(cond).Count(&Repository{}) return count > 0 || com.IsDir(RepoPath(u.Name, repoName)), err @@ -964,7 +965,7 @@ func IsRepositoryAliasExist(u *User, alias string) (bool, error) { func isRepositoryAliasExist(e Engine, u *User, alias string) (bool, error) { var cond = builder.NewCond() cond = cond.And(builder.Eq{"owner_id": u.ID}) - cond = cond.And(builder.Eq{"alias": alias}) + cond = cond.And(builder.Eq{"lower_alias": strings.ToLower(alias)}) count, err := e.Where(cond).Count(&Repository{}) return count > 0, err } @@ -1108,6 +1109,7 @@ func IsUsableRepoAlias(name string) error { // CreateRepository creates a repository for the user/organization. func CreateRepository(ctx DBContext, doer, u *User, repo *Repository) (err error) { + repo.LowerAlias = strings.ToLower(repo.Alias) if err = IsUsableRepoName(repo.Name); err != nil { return err } diff --git a/routers/repo/setting.go b/routers/repo/setting.go index cebaefdf2..b9b7b20f6 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -72,7 +72,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { newAlias := form.Alias // Check if repository alias has been changed. - if repo.Alias != newAlias { + if strings.ToLower(repo.Alias) != strings.ToLower(newAlias) { //check new alias is available or not if err := models.IsRepositoryAliasAvailable(ctx.Repo.Owner, newAlias); err != nil { ctx.Data["Err_Alias"] = true @@ -125,6 +125,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { repo.Website = form.Website repo.IsTemplate = form.Template repo.Alias = newAlias + repo.LowerAlias = strings.ToLower(newAlias) // Visibility of forked repository is forced sync with base repository. if repo.IsFork { From c9312b8340feb6dd5f4bbbad46ada4510be6acbf Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Wed, 19 Jan 2022 15:30:30 +0800 Subject: [PATCH 2/5] #1387 fix bug --- routers/repo/setting.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routers/repo/setting.go b/routers/repo/setting.go index b9b7b20f6..72bdbfa68 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -405,7 +405,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Error(404) return } - if repo.Name != form.RepoName { + if repo.Alias != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil) return } @@ -432,7 +432,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Error(404) return } - if repo.Name != form.RepoName { + if repo.Alias != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil) return } @@ -470,7 +470,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Error(404) return } - if repo.Name != form.RepoName { + if repo.Alias != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil) return } @@ -490,7 +490,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Error(404) return } - if repo.Name != form.RepoName { + if repo.Alias != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil) return } From 89cb32a02a3ab79f6915f6cd7c0f67a4c96e4497 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Wed, 19 Jan 2022 16:05:51 +0800 Subject: [PATCH 3/5] fix issue --- templates/repo/home.tmpl | 13 ++----------- templates/repo/settings/options.tmpl | 12 ++++++------ web_src/js/components/EditAboutInfo.vue | 3 +++ 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 08bf3e825..c9edff0c3 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -256,11 +256,8 @@
-

简介 - -

+

简介

+

{{if .Repository.DescriptionHTML}} {{.Repository.DescriptionHTML}} @@ -286,14 +283,8 @@

- {{range .Topics}} - {{.Name}} - - {{end}}
diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index ae688c628..f4127023c 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -509,7 +509,7 @@
@@ -541,7 +541,7 @@
@@ -568,7 +568,7 @@
{{.i18n.Tr "repo.settings.delete_notices_1" | Safe}}
- {{.i18n.Tr "repo.settings.delete_notices_2" .Repository.FullName | Safe}} + {{.i18n.Tr "repo.settings.delete_notices_2" .Repository.Alias | Safe}} {{if .Repository.NumForks}}
{{.i18n.Tr "repo.settings.delete_notices_fork_1"}} {{end}} @@ -579,7 +579,7 @@
@@ -603,7 +603,7 @@
{{.i18n.Tr "repo.settings.delete_notices_1" | Safe}}
- {{.i18n.Tr "repo.settings.wiki_delete_notices_1" .Repository.Name | Safe}} + {{.i18n.Tr "repo.settings.wiki_delete_notices_1" .Repository.Alias | Safe}}
{{.CsrfTokenHtml}} @@ -611,7 +611,7 @@
diff --git a/web_src/js/components/EditAboutInfo.vue b/web_src/js/components/EditAboutInfo.vue index eeb0ddaa8..425cf4bcc 100644 --- a/web_src/js/components/EditAboutInfo.vue +++ b/web_src/js/components/EditAboutInfo.vue @@ -52,6 +52,7 @@ export default { desc: '', index_web: '', repo_name_name: '', + alias:'' }, // rule1:[{min:3,max:5,message:'1',trigger:"blur"}], rule: { @@ -76,6 +77,7 @@ export default { getRepoName() { const el = this.url.split('/')[2]; this.info.repo_name = el; + this.info.alias = $('input#edit-alias').val() }, initForm(diaolog) { if (diaolog === false) { @@ -95,6 +97,7 @@ export default { data: this.qs.stringify({ _csrf: csrf, action: 'update', + alias:this.info.alias, repo_name: this.info.repo_name, description: this.info.desc, website: this.info.index_web From 66913993cd0b215949d3aa91ce1191376e6d51f7 Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Wed, 19 Jan 2022 16:24:11 +0800 Subject: [PATCH 4/5] #1392 fix bug --- modules/notification/action/action.go | 16 ++++++++++++++++ modules/notification/base/notifier.go | 1 + modules/notification/base/null.go | 4 ++++ routers/repo/setting.go | 7 +++++++ services/repository/transfer.go | 4 ++-- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go index 9956940f3..4bc296657 100644 --- a/modules/notification/action/action.go +++ b/modules/notification/action/action.go @@ -154,6 +154,22 @@ func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models. } } +func (a *actionNotifier) NotifyAliasRepository(doer *models.User, repo *models.Repository, oldAlias string) { + log.Trace("action.ChangeRepositoryAlias: %s/%s", doer.Name, repo.Alias) + + if err := models.NotifyWatchers(&models.Action{ + ActUserID: doer.ID, + ActUser: doer, + OpType: models.ActionRenameRepo, + RepoID: repo.ID, + Repo: repo, + IsPrivate: repo.IsPrivate, + Content: oldAlias, + }); err != nil { + log.Error("NotifyWatchers: %v", err) + } +} + func (a *actionNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { if err := models.NotifyWatchers(&models.Action{ ActUserID: doer.ID, diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index 0b3e1173b..8325f710c 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -18,6 +18,7 @@ type Notifier interface { NotifyDeleteRepository(doer *models.User, repo *models.Repository) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) + NotifyAliasRepository(doer *models.User, repo *models.Repository, oldAlias string) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) NotifyNewIssue(*models.Issue) diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index d2fd51d71..a74c47980 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -135,6 +135,10 @@ func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { } +func (a *NullNotifier) NotifyAliasRepository(doer *models.User, repo *models.Repository, oldAlias string) { + +} + // NotifyTransferRepository places a place holder function func (*NullNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { } diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 72bdbfa68..5b057dbe5 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -6,6 +6,7 @@ package repo import ( + "code.gitea.io/gitea/modules/notification" "errors" "fmt" "io/ioutil" @@ -71,8 +72,10 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { } newAlias := form.Alias + var aliasChanged = false // Check if repository alias has been changed. if strings.ToLower(repo.Alias) != strings.ToLower(newAlias) { + aliasChanged = true //check new alias is available or not if err := models.IsRepositoryAliasAvailable(ctx.Repo.Owner, newAlias); err != nil { ctx.Data["Err_Alias"] = true @@ -117,6 +120,10 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { log.Trace("Repository name changed: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newRepoName) } + //notify + if aliasChanged { + notification.NotifyRenameRepository(ctx.Repo.Owner, repo, repo.Alias) + } // In case it's just a case change. repo.Name = newRepoName diff --git a/services/repository/transfer.go b/services/repository/transfer.go index d34c812b8..0173f81d1 100644 --- a/services/repository/transfer.go +++ b/services/repository/transfer.go @@ -55,7 +55,7 @@ func TransferOwnership(doer, newOwner *models.User, repo *models.Repository, tea // ChangeRepositoryName changes all corresponding setting from old repository name to new one. func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoName string) error { - oldRepoName := repo.Name + //oldRepoName := repo.Name // Change repository directory name. We must lock the local copy of the // repo so that we can atomically rename the repo path and updates the @@ -68,7 +68,7 @@ func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoNam } repoWorkingPool.CheckOut(com.ToStr(repo.ID)) - notification.NotifyRenameRepository(doer, repo, oldRepoName) + //notification.NotifyRenameRepository(doer, repo, oldRepoName) return nil } From ec89e003ee30c5b0c51dc7ada6134a1cef7b1e8a Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Wed, 19 Jan 2022 16:30:42 +0800 Subject: [PATCH 5/5] fix issue --- templates/user/dashboard/feeds.tmpl | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 3eefca78c..f3794989c 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -21,55 +21,55 @@ {{$.i18n.Tr "action.commit_repo" .GetRepoLink $branchLink (Escape .GetBranch) .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 6}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.create_issue" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.create_issue" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 7}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.create_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.create_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 8}} - {{$.i18n.Tr "action.transfer_repo" .GetContent .GetRepoLink .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.transfer_repo" .GetContent .GetRepoLink .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 9}} {{ $branchLink := .GetBranch | EscapePound | Escape}} - {{$.i18n.Tr "action.push_tag" .GetRepoLink $branchLink .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.push_tag" .GetRepoLink $branchLink .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 10}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.comment_issue" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.comment_issue" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 11}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.merge_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.merge_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 12}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.close_issue" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.close_issue" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 13}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.reopen_issue" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.reopen_issue" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 14}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.close_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.close_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 15}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.reopen_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.reopen_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 16}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.delete_tag" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.delete_tag" .GetRepoLink .GetBranch .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 17}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.delete_branch" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.delete_branch" .GetRepoLink .GetBranch .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 18}} {{ $branchLink := .GetBranch | EscapePound}} - {{$.i18n.Tr "action.mirror_sync_push" .GetRepoLink $branchLink .GetBranch .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.mirror_sync_push" .GetRepoLink $branchLink .GetBranch .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 19}} - {{$.i18n.Tr "action.mirror_sync_create" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.mirror_sync_create" .GetRepoLink .GetBranch .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 20}} - {{$.i18n.Tr "action.mirror_sync_delete" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.mirror_sync_delete" .GetRepoLink .GetBranch .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 21}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.approve_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.approve_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 22}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.reject_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.reject_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 23}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.comment_pull" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.comment_pull" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{end}}

{{if or (eq .GetOpType 5) (eq .GetOpType 18)}}