diff --git a/gogs.go b/gogs.go index 99d365ba..060b150b 100644 --- a/gogs.go +++ b/gogs.go @@ -16,7 +16,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.10.30.0325" +const APP_VER = "0.10.31.0327" func init() { setting.AppVer = APP_VER diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 99ba8a43..7acd7259 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -62,6 +62,8 @@ var migrations = []Migration{ NewMigration("generate and migrate Git hooks", generateAndMigrateGitHooks), // v15 -> v16:v0.10.16 NewMigration("update repository sizes", updateRepositorySizes), + // v16 -> v17:v0.10.31 + NewMigration("remove invalid protect branch whitelist", removeInvalidProtectBranchWhitelist), } // Migrate database to current version diff --git a/models/migrations/v17.go b/models/migrations/v17.go new file mode 100644 index 00000000..6769b754 --- /dev/null +++ b/models/migrations/v17.go @@ -0,0 +1,14 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package migrations + +import ( + "github.com/go-xorm/xorm" +) + +func removeInvalidProtectBranchWhitelist(x *xorm.Engine) error { + _, err := x.Exec("DELETE FROM protect_branch_whitelist WHERE protect_branch_id = 0") + return err +} diff --git a/models/org_team.go b/models/org_team.go index 816f2370..a7fe3a33 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -424,7 +424,7 @@ func IsTeamMember(orgID, teamID, uid int64) bool { func getTeamMembers(e Engine, teamID int64) (_ []*User, err error) { teamUsers := make([]*TeamUser, 0, 10) - if err = e.Sql("SELECT `id`, `org_id`, `team_id`, `uid` FROM `team_user` WHERE team_id=?", teamID). + if err = e.Sql("SELECT `id`, `org_id`, `team_id`, `uid` FROM `team_user` WHERE team_id = ?", teamID). Find(&teamUsers); err != nil { return nil, fmt.Errorf("get team-users: %v", err) } diff --git a/models/repo_branch.go b/models/repo_branch.go index 6c5b7ec8..de0ee26d 100644 --- a/models/repo_branch.go +++ b/models/repo_branch.go @@ -187,6 +187,13 @@ func UpdateOrgProtectBranch(repo *Repository, protectBranch *ProtectBranch, whit protectBranch.WhitelistTeamIDs = strings.Join(base.Int64sToStrings(validTeamIDs), ",") } + // Make sure protectBranch.ID is not 0 for whitelists + if protectBranch.ID == 0 { + if _, err = x.Insert(protectBranch); err != nil { + return fmt.Errorf("Insert: %v", err) + } + } + // Merge users and members of teams var whitelists []*ProtectBranchWhitelist if hasUsersChanged || hasTeamsChanged { @@ -226,12 +233,6 @@ func UpdateOrgProtectBranch(repo *Repository, protectBranch *ProtectBranch, whit return err } - if protectBranch.ID == 0 { - if _, err = sess.Insert(protectBranch); err != nil { - return fmt.Errorf("Insert: %v", err) - } - } - if _, err = sess.Id(protectBranch.ID).AllCols().Update(protectBranch); err != nil { return fmt.Errorf("Update: %v", err) } diff --git a/templates/.VERSION b/templates/.VERSION index 0e5097c0..f14cdf1c 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.10.30.0325 \ No newline at end of file +0.10.31.0327 \ No newline at end of file