mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-03 01:42:25 +02:00
[BUG] Don't allow owner team with incorrect unit access
- On editting a team, only update the units if the team isn't the 'Owners' team. Otherwise the 'Owners' team end up having all of their unit access modes set to 'None'; because the request form doesn't send over any units, as it's simply not shown in the UI. - Adds a database inconstency check and fix for the case where the 'Owners' team is affected by this bug. - Adds unit test. - Adds integration test. - Resolves #5528 - Regression of https://github.com/go-gitea/gitea/pull/24012
This commit is contained in:
parent
4cb01ba5da
commit
9de9034400
7 changed files with 199 additions and 10 deletions
|
@ -268,3 +268,43 @@ func IncrTeamRepoNum(ctx context.Context, teamID int64) error {
|
|||
_, err := db.GetEngine(ctx).Incr("num_repos").ID(teamID).Update(new(Team))
|
||||
return err
|
||||
}
|
||||
|
||||
// CountInconsistentOwnerTeams returns the amount of owner teams that have all of
|
||||
// their access modes set to "None".
|
||||
func CountInconsistentOwnerTeams(ctx context.Context) (int64, error) {
|
||||
return db.GetEngine(ctx).Table("team").
|
||||
Join("INNER", "team_unit", "`team`.id = `team_unit`.team_id").
|
||||
Where("`team`.lower_name = ?", strings.ToLower(OwnerTeamName)).
|
||||
GroupBy("`team_unit`.team_id").
|
||||
Having("SUM(`team_unit`.access_mode) = 0").
|
||||
Count()
|
||||
}
|
||||
|
||||
// FixInconsistentOwnerTeams fixes inconsistent owner teams that have all of
|
||||
// their access modes set to "None", it sets it back to "Owner".
|
||||
func FixInconsistentOwnerTeams(ctx context.Context) (int64, error) {
|
||||
teamIDs := []int64{}
|
||||
if err := db.GetEngine(ctx).Table("team").
|
||||
Select("`team`.id").
|
||||
Join("INNER", "team_unit", "`team`.id = `team_unit`.team_id").
|
||||
Where("`team`.lower_name = ?", strings.ToLower(OwnerTeamName)).
|
||||
GroupBy("`team_unit`.team_id").
|
||||
Having("SUM(`team_unit`.access_mode) = 0").
|
||||
Find(&teamIDs); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if err := db.Iterate(ctx, builder.In("team_id", teamIDs), func(ctx context.Context, bean *TeamUnit) error {
|
||||
if bean.Type == unit.TypeExternalTracker || bean.Type == unit.TypeExternalWiki {
|
||||
bean.AccessMode = perm.AccessModeRead
|
||||
} else {
|
||||
bean.AccessMode = perm.AccessModeOwner
|
||||
}
|
||||
_, err := db.GetEngine(ctx).ID(bean.ID).Table("team_unit").Cols("access_mode").Update(bean)
|
||||
return err
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int64(len(teamIDs)), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue