You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fix8312.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package doctor
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/models/db"
  8. org_model "code.gitea.io/gitea/models/organization"
  9. "code.gitea.io/gitea/models/perm"
  10. "code.gitea.io/gitea/modules/log"
  11. "xorm.io/builder"
  12. )
  13. func fixOwnerTeamCreateOrgRepo(ctx context.Context, logger log.Logger, autofix bool) error {
  14. count := 0
  15. err := db.Iterate(
  16. ctx,
  17. builder.Eq{"authorize": perm.AccessModeOwner, "can_create_org_repo": false},
  18. func(ctx context.Context, team *org_model.Team) error {
  19. team.CanCreateOrgRepo = true
  20. count++
  21. if !autofix {
  22. return nil
  23. }
  24. return models.UpdateTeam(ctx, team, false, false)
  25. },
  26. )
  27. if err != nil {
  28. logger.Critical("Unable to iterate across repounits to fix incorrect can_create_org_repo: Error %v", err)
  29. return err
  30. }
  31. if !autofix {
  32. if count == 0 {
  33. logger.Info("Found no team with incorrect can_create_org_repo")
  34. } else {
  35. logger.Warn("Found %d teams with incorrect can_create_org_repo", count)
  36. }
  37. return nil
  38. }
  39. logger.Info("Fixed %d teams with incorrect can_create_org_repo", count)
  40. return nil
  41. }
  42. func init() {
  43. Register(&Check{
  44. Title: "Check for incorrect can_create_org_repo for org owner teams",
  45. Name: "fix-owner-team-create-org-repo",
  46. IsDefault: false,
  47. Run: fixOwnerTeamCreateOrgRepo,
  48. Priority: 7,
  49. })
  50. }