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.

fixture_generation.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "fmt"
  7. "strings"
  8. "code.gitea.io/gitea/models/db"
  9. access_model "code.gitea.io/gitea/models/perm/access"
  10. repo_model "code.gitea.io/gitea/models/repo"
  11. )
  12. // GetYamlFixturesAccess returns a string containing the contents
  13. // for the access table, as recalculated using repo.RecalculateAccesses()
  14. func GetYamlFixturesAccess() (string, error) {
  15. repos := make([]*repo_model.Repository, 0, 50)
  16. if err := db.GetEngine(db.DefaultContext).Find(&repos); err != nil {
  17. return "", err
  18. }
  19. for _, repo := range repos {
  20. repo.MustOwner()
  21. if err := access_model.RecalculateAccesses(db.DefaultContext, repo); err != nil {
  22. return "", err
  23. }
  24. }
  25. var b strings.Builder
  26. accesses := make([]*access_model.Access, 0, 200)
  27. if err := db.GetEngine(db.DefaultContext).OrderBy("user_id, repo_id").Find(&accesses); err != nil {
  28. return "", err
  29. }
  30. for i, a := range accesses {
  31. fmt.Fprintf(&b, "-\n")
  32. fmt.Fprintf(&b, " id: %d\n", i+1)
  33. fmt.Fprintf(&b, " user_id: %d\n", a.UserID)
  34. fmt.Fprintf(&b, " repo_id: %d\n", a.RepoID)
  35. fmt.Fprintf(&b, " mode: %d\n", a.Mode)
  36. fmt.Fprintf(&b, "\n")
  37. }
  38. return b.String(), nil
  39. }