From 67a9416ae55ea765e3f405e00d89b0b8f3899330 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 12 Feb 2015 12:38:44 -0500 Subject: templates/user/auth/signin.tmpl: hide sign up prompt when registration is disabled #884 --- models/models.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'models') diff --git a/models/models.go b/models/models.go index 3eeeabda3f..35e803834c 100644 --- a/models/models.go +++ b/models/models.go @@ -15,7 +15,7 @@ import ( "github.com/go-xorm/xorm" _ "github.com/lib/pq" - "github.com/gogits/gogs/models/migrations" + // "github.com/gogits/gogs/models/migrations" "github.com/gogits/gogs/modules/setting" ) @@ -136,9 +136,9 @@ func NewEngine() (err error) { return err } - if err = migrations.Migrate(x); err != nil { - return err - } + // if err = migrations.Migrate(x); err != nil { + // return err + // } if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil { return fmt.Errorf("sync database struct error: %v\n", err) -- cgit v1.2.3 From 685ed1f8075c0fedc2cfaf0f8c43f9439132e1da Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 14 Feb 2015 17:01:33 -0500 Subject: models: fix XORM API break cmd/web.go: check version after load config --- cmd/web.go | 3 +-- gogs.go | 2 +- models/models.go | 2 +- templates/.VERSION | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) (limited to 'models') diff --git a/cmd/web.go b/cmd/web.go index 3284acb9df..4b06a882c0 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -166,12 +166,11 @@ func newMacaron() *macaron.Macaron { } func runWeb(ctx *cli.Context) { - checkVersion() - if ctx.IsSet("config") { setting.CustomConf = ctx.String("config") } routers.GlobalInit() + checkVersion() m := newMacaron() diff --git a/gogs.go b/gogs.go index 76c6c71fc3..34790b7258 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.13.0212 Beta" +const APP_VER = "0.5.13.0214 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/models.go b/models/models.go index 35e803834c..486aceac22 100644 --- a/models/models.go +++ b/models/models.go @@ -121,7 +121,7 @@ func SetEngine() (err error) { if err != nil { return fmt.Errorf("models.init(fail to create xorm.log): %v", err) } - x.Logger = xorm.NewSimpleLogger(f) + x.SetLogger(xorm.NewSimpleLogger(f)) x.ShowSQL = true x.ShowInfo = true diff --git a/templates/.VERSION b/templates/.VERSION index 6d13155b02..0c9421a4d2 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.13.0212 Beta \ No newline at end of file +0.5.13.0214 Beta \ No newline at end of file -- cgit v1.2.3 From b6519f78c704bf70b48e63f960ef88d430e07b3b Mon Sep 17 00:00:00 2001 From: Peter Smit Date: Mon, 16 Feb 2015 13:25:55 +0200 Subject: Remove collaborators when removing and transferring repository --- models/repo.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'models') diff --git a/models/repo.go b/models/repo.go index fd00823a23..388bcd0e5b 100644 --- a/models/repo.go +++ b/models/repo.go @@ -670,6 +670,19 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { return err } + // Remove redundant collaborators + collaborators, err := repo.GetCollaborators() + if err != nil { + return err + } + for _, c := range collaborators { + if c.Id == newUser.Id || newUser.IsOrgMember(c.Id) { + if _, err = sess.Delete(&Collaboration{RepoID: repo.Id, UserID: c.Id}); err != nil { + return err + } + } + } + // Update user repository number. if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", newUser.Id); err != nil { return err @@ -778,6 +791,8 @@ func DeleteRepository(uid, repoId int64, userName string) error { return err } else if _, err = sess.Delete(&Release{RepoId: repoId}); err != nil { return err + } else if _, err = sess.Delete(&Collaboration{RepoID: repoId}); err != nil { + return err } // Delete comments. -- cgit v1.2.3 From e6fc58a74461bd67efb06fc2e5658265ede2edb5 Mon Sep 17 00:00:00 2001 From: Peter Smit Date: Tue, 17 Feb 2015 10:36:17 +0200 Subject: Remove GoGet option from repository and handle it with ?go-get=1 instead The normal go get protocol is to show the go-import meta tag when ?go-get=1 is appended to the url. This commit implements that behaviour and cleans the go-get option from the repository settings page. --- conf/locale/locale_en-US.ini | 2 -- models/repo.go | 1 - modules/auth/repo_form.go | 1 - modules/middleware/repo.go | 3 +-- routers/repo/setting.go | 3 +-- templates/base/head.tmpl | 2 +- templates/ng/base/head.tmpl | 2 +- templates/repo/settings/options.tmpl | 5 ----- 8 files changed, 4 insertions(+), 15 deletions(-) (limited to 'models') diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 6b59be7391..54b80abb5e 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -281,8 +281,6 @@ init_readme = Initialize this repository with a README.md create_repo = Create Repository default_branch = Default Branch mirror_interval = Mirror Interval (hour) -goget_meta = Go-Get Meta -goget_meta_helper = This repository will be Go-Getable need_auth = Need Authorization migrate_type = Migration Type diff --git a/models/repo.go b/models/repo.go index cdb838a1fb..179120a311 100644 --- a/models/repo.go +++ b/models/repo.go @@ -154,7 +154,6 @@ type Repository struct { IsPrivate bool IsBare bool - IsGoget bool IsMirror bool *Mirror `xorm:"-"` diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 36e62f04fb..c771dd59b8 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -52,7 +52,6 @@ type RepoSettingForm struct { Branch string `form:"branch"` Interval int `form:"interval"` Private bool `form:"private"` - GoGet bool `form:"goget"` } func (f *RepoSettingForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 1ab158dd6d..67a9eda691 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -394,8 +394,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { } ctx.Data["CloneLink"] = ctx.Repo.CloneLink - if ctx.Repo.Repository.IsGoget { - ctx.Data["GoGetLink"] = fmt.Sprintf("%s%s/%s", setting.AppUrl, u.LowerName, repo.LowerName) + if ctx.Query("go-get") == "1" { ctx.Data["GoGetImport"] = fmt.Sprintf("%s/%s/%s", setting.Domain, u.LowerName, repo.LowerName) } diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 33bf1eab28..8368513ad8 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -8,9 +8,9 @@ import ( "encoding/json" "errors" "fmt" + "path" "strings" "time" - "path" "github.com/Unknwon/com" @@ -84,7 +84,6 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { ctx.Repo.Repository.Description = form.Description ctx.Repo.Repository.Website = form.Website ctx.Repo.Repository.IsPrivate = form.Private - ctx.Repo.Repository.IsGoget = form.GoGet if err := models.UpdateRepository(ctx.Repo.Repository); err != nil { ctx.Handle(404, "UpdateRepository", err) return diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 7775933ca9..cb3951ea2c 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -9,7 +9,7 @@ - {{if .Repository.IsGoget}}{{end}} + {{if .GoGetImport}}{{end}} {{if CdnMode}} diff --git a/templates/ng/base/head.tmpl b/templates/ng/base/head.tmpl index 40a7d28ff2..f2a235bd43 100644 --- a/templates/ng/base/head.tmpl +++ b/templates/ng/base/head.tmpl @@ -7,7 +7,7 @@ - {{if .Repository.IsGoget}}{{end}} + {{if .GoGetImport}}{{end}} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 093e937553..41683f8450 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -59,11 +59,6 @@ {{.i18n.Tr "repo.visiblity_helper" | Str2html}} -
- - - {{.i18n.Tr "repo.goget_meta_helper" | Str2html}} -
-- cgit v1.2.3 From 4f567edc6edbe8f43e6acd54bc3fe4e579b2389a Mon Sep 17 00:00:00 2001 From: Raphael Randschau Date: Fri, 20 Feb 2015 07:52:56 +0100 Subject: Fix #933 Not sure why, but xorm ignores the num_issues and num_closed_issues columns when updating, even though the values changed. Listing them explicitly fixes the issue with the wrong issue counts --- models/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models') diff --git a/models/issue.go b/models/issue.go index d9a24063c2..226ca3ca57 100644 --- a/models/issue.go +++ b/models/issue.go @@ -561,7 +561,7 @@ func GetLabels(repoId int64) ([]*Label, error) { // UpdateLabel updates label information. func UpdateLabel(l *Label) error { - _, err := x.Id(l.Id).Update(l) + _, err := x.Id(l.Id).AllCols().Update(l) return err } -- cgit v1.2.3 From 1654e9ecab3923b7fe5d528fc86c1a549546bd29 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 21 Feb 2015 22:13:47 -0500 Subject: templates/user/settings/emial.tmpl: little fix on UI - routers/user: little code format - conf/locale: update French locale --- conf/locale/locale_fr-CA.ini | 16 ++++---- gogs.go | 2 +- models/user.go | 9 +++-- modules/auth/user_form.go | 2 +- routers/user/auth.go | 5 +-- routers/user/setting.go | 80 ++++++++++++++++++-------------------- templates/.VERSION | 2 +- templates/user/settings/email.tmpl | 6 +-- 8 files changed, 58 insertions(+), 64 deletions(-) (limited to 'models') diff --git a/conf/locale/locale_fr-CA.ini b/conf/locale/locale_fr-CA.ini index 0aeae3423f..e744b9d97c 100755 --- a/conf/locale/locale_fr-CA.ini +++ b/conf/locale/locale_fr-CA.ini @@ -59,8 +59,8 @@ run_user=Entrer un Utilisateur run_user_helper=L'utilisateur doit avoir accès à la Racine du Référentiel et éxécuter Gogs. domain=Domaine domain_helper=Cela affecte les doublons d'URL SSH. -http_port=HTTP Port -http_port_helper=Port number which application will listen on. +http_port=Port HTTP +http_port_helper=Numéro de port que l'application écoutera. app_url=URL de l'Application app_url_helper=Cela affecte les doublons d'URL HTTP/HTTPS et le contenu d'e-mail. email_title=Paramètres du Service de Messagerie (Facultatif) @@ -514,10 +514,10 @@ dashboard.delete_repo_archives=Supprimer toutes les archives de référentiels dashboard.delete_repo_archives_success=Toutes les archives de référentiels ont été supprimés avec succès. dashboard.git_gc_repos=Collecter les déchets des référentiels dashboard.git_gc_repos_success=Tous les référentiels ont effectué la collecte avec succès. -dashboard.resync_all_sshkeys=Rewrite '.ssh/autorized_key' file (caution: non-Gogs keys will be lost) -dashboard.resync_all_sshkeys_success=All public keys have been rewritten successfully. -dashboard.resync_all_update_hooks=Rewrite all update hook of repositories (needed when custom config path is changed) -dashboard.resync_all_update_hooks_success=All repositories' update hook have been rewritten successfully. +dashboard.resync_all_sshkeys=Ré-écrire le fichier '.ssh/autorized_key' (attention : les clés hors-Gogs vont être perdues) +dashboard.resync_all_sshkeys_success=Toutes les clés publiques ont été ré-écrites avec succès. +dashboard.resync_all_update_hooks=Ré-écrire tous les hooks de mises à jour des dépôts (requis quand le chemin de la configuration personnalisé est modifié) +dashboard.resync_all_update_hooks_success=Tous les hooks de mises à jour des dépôts ont été ré-écris avec succès. dashboard.server_uptime=Durée de Marche Serveur dashboard.current_goroutine=Goroutines actuelles @@ -638,7 +638,7 @@ config.db_path_helper=("sqlite3" uniquement) config.service_config=Configuration du Service config.register_email_confirm=Nécessite une confirmation par courriel config.disable_register=Désactiver l'Enregistrement -config.show_registration_button=Show Register Button +config.show_registration_button=Afficher le bouton d'enregistrement config.require_sign_in_view=Connexion Obligatoire pour Visualiser config.mail_notify=Mailer les Notifications config.enable_cache_avatar=Activer le Cache d'Avatar @@ -647,7 +647,7 @@ config.reset_password_code_lives=Réinitialiser le Mot De Passe des Limites de C config.webhook_config=Configuration Webhook config.task_interval=Intervalles de Tâches config.deliver_timeout=Expiration d'Envoi -config.skip_tls_verify=Skip TLS Verify +config.skip_tls_verify=Ne pas vérifier TLS config.mailer_config=Configuration du Maileur config.mailer_enabled=Activé config.mailer_name=Nom diff --git a/gogs.go b/gogs.go index 34790b7258..5c24e229a1 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.13.0214 Beta" +const APP_VER = "0.5.14.0221 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/user.go b/models/user.go index 2da0881c81..9f9b0cd7fc 100644 --- a/models/user.go +++ b/models/user.go @@ -627,7 +627,7 @@ func GetUserIdsByNames(names []string) []int64 { return ids } -// Get all email addresses +// GetEmailAddresses returns all e-mail addresses belongs to given user. func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { emails := make([]*EmailAddress, 0, 5) err := x.Where("uid=?", uid).Find(&emails) @@ -641,7 +641,6 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { } isPrimaryFound := false - for _, email := range emails { if email.Email == u.Email { isPrimaryFound = true @@ -654,7 +653,11 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { // We alway want the primary email address displayed, even if it's not in // the emailaddress table (yet) if !isPrimaryFound { - emails = append(emails, &EmailAddress{Email: u.Email, IsActivated: true, IsPrimary: true}) + emails = append(emails, &EmailAddress{ + Email: u.Email, + IsActivated: true, + IsPrimary: true, + }) } return emails, nil } diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go index 3c0ff65174..b616a460ff 100644 --- a/modules/auth/user_form.go +++ b/modules/auth/user_form.go @@ -99,7 +99,7 @@ func (f *UploadAvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) b } type AddEmailForm struct { - Email string `form:"email" binding:"Required;Email;MaxSize(50)"` + Email string `binding:"Required;Email;MaxSize(50)"` } func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { diff --git a/routers/user/auth.go b/routers/user/auth.go index 9ed44e353c..5dacaf8c79 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -351,15 +351,12 @@ func ActivateEmail(ctx *middleware.Context) { // Verify code. if email := models.VerifyActiveEmailCode(code, email_string); email != nil { - err := email.Activate() - if err != nil { + if err := email.Activate(); err != nil { ctx.Handle(500, "ActivateEmail", err) } log.Trace("Email activated: %s", email.Email) - ctx.Flash.Success(ctx.Tr("settings.activate_email_success")) - } ctx.Redirect(setting.AppSubUrl + "/user/settings/email") diff --git a/routers/user/setting.go b/routers/user/setting.go index 953e61138f..9398f69a0e 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -133,13 +133,12 @@ func SettingsEmails(ctx *middleware.Context) { ctx.Data["PageIsUserSettings"] = true ctx.Data["PageIsSettingsEmails"] = true - var err error - ctx.Data["Emails"], err = models.GetEmailAddresses(ctx.User.Id) - + emails, err := models.GetEmailAddresses(ctx.User.Id) if err != nil { - ctx.Handle(500, "email.GetEmailAddresses", err) + ctx.Handle(500, "GetEmailAddresses", err) return } + ctx.Data["Emails"] = emails ctx.HTML(200, SETTINGS_EMAILS) } @@ -149,16 +148,16 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) { ctx.Data["PageIsUserSettings"] = true ctx.Data["PageIsSettingsEmails"] = true - var err error - ctx.Data["Emails"], err = models.GetEmailAddresses(ctx.User.Id) + emails, err := models.GetEmailAddresses(ctx.User.Id) if err != nil { - ctx.Handle(500, "email.GetEmailAddresses", err) + ctx.Handle(500, "GetEmailAddresses", err) return } + ctx.Data["Emails"] = emails - // Delete Email address. + // Delete E-mail address. if ctx.Query("_method") == "DELETE" { - id := com.StrTo(ctx.Query("id")).MustInt64() + id := ctx.QueryInt64("id") if id <= 0 { return } @@ -174,7 +173,7 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) { // Make emailaddress primary. if ctx.Query("_method") == "PRIMARY" { - id := com.StrTo(ctx.Query("id")).MustInt64() + id := ctx.QueryInt64("id") if id <= 0 { return } @@ -189,46 +188,41 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) { } // Add Email address. - if ctx.Req.Method == "POST" { - if ctx.HasError() { - ctx.HTML(200, SETTINGS_EMAILS) - return - } + if ctx.HasError() { + ctx.HTML(200, SETTINGS_EMAILS) + return + } - cleanEmail := strings.Replace(form.Email, "\n", "", -1) - e := &models.EmailAddress{ - Uid: ctx.User.Id, - Email: cleanEmail, - IsActivated: !setting.Service.RegisterEmailConfirm, - } + cleanEmail := strings.Replace(form.Email, "\n", "", -1) + e := &models.EmailAddress{ + Uid: ctx.User.Id, + Email: cleanEmail, + IsActivated: !setting.Service.RegisterEmailConfirm, + } - if err := models.AddEmailAddress(e); err != nil { - if err == models.ErrEmailAlreadyUsed { - ctx.RenderWithErr(ctx.Tr("form.email_has_been_used"), SETTINGS_EMAILS, &form) - return - } - ctx.Handle(500, "email.AddEmailAddress", err) + if err := models.AddEmailAddress(e); err != nil { + if err == models.ErrEmailAlreadyUsed { + ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_EMAILS, &form) return - } else { - - // Send confirmation e-mail - if setting.Service.RegisterEmailConfirm { - mailer.SendActivateEmail(ctx.Render, ctx.User, e) + } + ctx.Handle(500, "AddEmailAddress", err) + return + } else { + // Send confirmation e-mail + if setting.Service.RegisterEmailConfirm { + mailer.SendActivateEmail(ctx.Render, ctx.User, e) - if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { - log.Error(4, "Set cache(MailResendLimit) fail: %v", err) - } - ctx.Flash.Success(ctx.Tr("settings.add_email_success_confirmation_email_sent")) - } else { - ctx.Flash.Success(ctx.Tr("settings.add_email_success")) + if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { + log.Error(4, "Set cache(MailResendLimit) fail: %v", err) } - - log.Trace("Email address added: %s", e.Email) - - ctx.Redirect(setting.AppSubUrl + "/user/settings/email") - return + ctx.Flash.Success(ctx.Tr("settings.add_email_success_confirmation_email_sent")) + } else { + ctx.Flash.Success(ctx.Tr("settings.add_email_success")) } + log.Trace("Email address added: %s", e.Email) + ctx.Redirect(setting.AppSubUrl + "/user/settings/email") + return } ctx.HTML(200, SETTINGS_EMAILS) diff --git a/templates/.VERSION b/templates/.VERSION index 0c9421a4d2..489addf9a7 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.13.0214 Beta \ No newline at end of file +0.5.14.0221 Beta \ No newline at end of file diff --git a/templates/user/settings/email.tmpl b/templates/user/settings/email.tmpl index c99e6a0415..ec152c5d60 100644 --- a/templates/user/settings/email.tmpl +++ b/templates/user/settings/email.tmpl @@ -16,7 +16,7 @@ {{range .Emails}} -- cgit v1.2.3 From 04164eada3bc89bb3b54aa3dea0f22203ff4aa6e Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 22 Feb 2015 18:24:49 -0500 Subject: models: able to rename user with diff letter cases #981 - templates/org: mirror fix on name output - routers: add missing error check --- models/org.go | 2 +- models/user.go | 14 +++-- routers/org/setting.go | 15 +++-- routers/repo/setting.go | 2 +- routers/user/setting.go | 11 ++-- templates/org/base/header.tmpl | 2 +- templates/org/settings/nav.tmpl | 20 +++---- templates/org/settings/options.tmpl | 114 ++++++++++++++++++------------------ 8 files changed, 97 insertions(+), 83 deletions(-) (limited to 'models') diff --git a/models/org.go b/models/org.go index 3d37a37d69..b2f9c903a4 100644 --- a/models/org.go +++ b/models/org.go @@ -93,7 +93,7 @@ func CreateOrganization(org, owner *User) (*User, error) { return nil, ErrUserNameIllegal } - isExist, err := IsUserExist(org.Name) + isExist, err := IsUserExist(0, org.Name) if err != nil { return nil, err } else if isExist { diff --git a/models/user.go b/models/user.go index 9f9b0cd7fc..a974e081f1 100644 --- a/models/user.go +++ b/models/user.go @@ -249,11 +249,13 @@ func (u *User) GetFullNameFallback() string { // IsUserExist checks if given user name exist, // the user name should be noncased unique. -func IsUserExist(name string) (bool, error) { +// If uid is presented, then check will rule out that one, +// it is used when update a user name in settings page. +func IsUserExist(uid int64, name string) (bool, error) { if len(name) == 0 { return false, nil } - return x.Get(&User{LowerName: strings.ToLower(name)}) + return x.Where("id!=?", uid).Get(&User{LowerName: strings.ToLower(name)}) } // IsEmailUsed returns true if the e-mail has been used. @@ -278,7 +280,7 @@ func CreateUser(u *User) error { return ErrUserNameIllegal } - isExist, err := IsUserExist(u.Name) + isExist, err := IsUserExist(0, u.Name) if err != nil { return err } else if isExist { @@ -397,6 +399,10 @@ func ChangeUserName(u *User, newUserName string) (err error) { } newUserName = strings.ToLower(newUserName) + if u.LowerName == newUserName { + // User only change letter cases. + return nil + } // Update accesses of user. accesses := make([]Access, 0, 10) @@ -453,7 +459,7 @@ func ChangeUserName(u *User, newUserName string) (err error) { // UpdateUser updates user's information. func UpdateUser(u *User) error { - has, err := x.Where("id!=?", u.Id).And("type=?", INDIVIDUAL).And("email=?", u.Email).Get(new(User)) + has, err := x.Where("id!=?", u.Id).And("type=?", u.Type).And("email=?", u.Email).Get(new(User)) if err != nil { return err } else if has { diff --git a/routers/org/setting.go b/routers/org/setting.go index 41ec4a2141..c638a032e7 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -39,18 +39,18 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) { // Check if organization name has been changed. if org.Name != form.OrgUserName { - isExist, err := models.IsUserExist(form.OrgUserName) + isExist, err := models.IsUserExist(org.Id, form.OrgUserName) if err != nil { ctx.Handle(500, "IsUserExist", err) return } else if isExist { + ctx.Data["Err_UserName"] = true ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), SETTINGS_OPTIONS, &form) return } else if err = models.ChangeUserName(org, form.OrgUserName); err != nil { if err == models.ErrUserNameIllegal { - ctx.Flash.Error(ctx.Tr("form.illegal_username")) - ctx.Redirect(setting.AppSubUrl + "/org/" + org.LowerName + "/settings") - return + ctx.Data["Err_UserName"] = true + ctx.RenderWithErr(ctx.Tr("form.illegal_username"), SETTINGS_OPTIONS, &form) } else { ctx.Handle(500, "ChangeUserName", err) } @@ -68,7 +68,12 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) { org.Avatar = base.EncodeMd5(form.Avatar) org.AvatarEmail = form.Avatar if err := models.UpdateUser(org); err != nil { - ctx.Handle(500, "UpdateUser", err) + if err == models.ErrEmailAlreadyUsed { + ctx.Data["Err_Email"] = true + ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_OPTIONS, &form) + } else { + ctx.Handle(500, "UpdateUser", err) + } return } log.Trace("Organization setting updated: %s", org.Name) diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 8368513ad8..b40ef2d9ae 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -109,7 +109,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { } newOwner := ctx.Query("new_owner_name") - isExist, err := models.IsUserExist(newOwner) + isExist, err := models.IsUserExist(0, newOwner) if err != nil { ctx.Handle(500, "IsUserExist", err) return diff --git a/routers/user/setting.go b/routers/user/setting.go index 9398f69a0e..a44d3b7e5d 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -50,7 +50,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { // Check if user name has been changed. if ctx.User.Name != form.UserName { - isExist, err := models.IsUserExist(form.UserName) + isExist, err := models.IsUserExist(ctx.User.Id, form.UserName) if err != nil { ctx.Handle(500, "IsUserExist", err) return @@ -58,11 +58,14 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), SETTINGS_PROFILE, &form) return } else if err = models.ChangeUserName(ctx.User, form.UserName); err != nil { - if err == models.ErrUserNameIllegal { + switch err { + case models.ErrUserNameIllegal: ctx.Flash.Error(ctx.Tr("form.illegal_username")) ctx.Redirect(setting.AppSubUrl + "/user/settings") - return - } else { + case models.ErrEmailAlreadyUsed: + ctx.Flash.Error(ctx.Tr("form.email_been_used")) + ctx.Redirect(setting.AppSubUrl + "/user/settings") + default: ctx.Handle(500, "ChangeUserName", err) } return diff --git a/templates/org/base/header.tmpl b/templates/org/base/header.tmpl index 1bbb092bf5..1649b92090 100644 --- a/templates/org/base/header.tmpl +++ b/templates/org/base/header.tmpl @@ -2,7 +2,7 @@
- {{.Org.FullName}} + {{if .Org.FullName}}{{.Org.FullName}}{{else}}{{.Org.Name}}{{end}}