Browse Source

convert alias to lowercase when check

tags/v1.22.1.3
chenyifan01 3 years ago
parent
commit
b466a3654d
2 changed files with 10 additions and 7 deletions
  1. +8
    -6
      models/repo.go
  2. +2
    -1
      routers/repo/setting.go

+ 8
- 6
models/repo.go View File

@@ -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
}


+ 2
- 1
routers/repo/setting.go View File

@@ -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 {


Loading…
Cancel
Save