-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unit types commits and settings (#2161)
* Remove unit types commits and settings * Can not limit units in administrator teams * Limit changing units only to teams with read and write access mode * Small code optimization
- Loading branch information
Showing
20 changed files
with
174 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,9 @@ | |
user_id: 4 | ||
repo_id: 4 | ||
mode: 2 # write | ||
|
||
- | ||
id: 3 | ||
user_id: 4 | ||
repo_id: 3 | ||
mode: 2 # write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2017 The Gitea 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 ( | ||
"code.gitea.io/gitea/models" | ||
|
||
"github.com/go-xorm/xorm" | ||
) | ||
|
||
func removeCommitsUnitType(x *xorm.Engine) (err error) { | ||
// Update team unit types | ||
const batchSize = 100 | ||
for start := 0; ; start += batchSize { | ||
teams := make([]*models.Team, 0, batchSize) | ||
if err := x.Limit(batchSize, start).Find(&teams); err != nil { | ||
return err | ||
} | ||
if len(teams) == 0 { | ||
break | ||
} | ||
for _, team := range teams { | ||
ut := make([]models.UnitType, 0, len(team.UnitTypes)) | ||
for _, u := range team.UnitTypes { | ||
if u < V16UnitTypeCommits { | ||
ut = append(ut, u) | ||
} else if u > V16UnitTypeSettings { | ||
ut = append(ut, u-2) | ||
} else if u > V16UnitTypeCommits && u != V16UnitTypeSettings { | ||
ut = append(ut, u-1) | ||
} | ||
} | ||
team.UnitTypes = ut | ||
if _, err := x.Id(team.ID).Cols("unit_types").Update(team); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
// Delete commits and settings unit types | ||
if _, err = x.In("`type`", []models.UnitType{V16UnitTypeCommits, V16UnitTypeSettings}).Delete(new(RepoUnit)); err != nil { | ||
return err | ||
} | ||
// Fix renumber unit types that where in enumeration after settings unit type | ||
if _, err = x.Where("`type` > ?", V16UnitTypeSettings).Decr("type").Decr("index").Update(new(RepoUnit)); err != nil { | ||
return err | ||
} | ||
// Fix renumber unit types that where in enumeration after commits unit type | ||
if _, err = x.Where("`type` > ?", V16UnitTypeCommits).Decr("type").Decr("index").Update(new(RepoUnit)); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.