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.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. )
  10. // GetYamlFixturesAccess returns a string containing the contents
  11. // for the access table, as recalculated using repo.RecalculateAccesses()
  12. func GetYamlFixturesAccess() (string, error) {
  13. repos := make([]*Repository, 0, 50)
  14. if err := db.GetEngine(db.DefaultContext).Find(&repos); err != nil {
  15. return "", err
  16. }
  17. for _, repo := range repos {
  18. repo.MustOwner()
  19. if err := repo.RecalculateAccesses(); err != nil {
  20. return "", err
  21. }
  22. }
  23. var b strings.Builder
  24. accesses := make([]*Access, 0, 200)
  25. if err := db.GetEngine(db.DefaultContext).OrderBy("user_id, repo_id").Find(&accesses); err != nil {
  26. return "", err
  27. }
  28. for i, a := range accesses {
  29. fmt.Fprintf(&b, "-\n")
  30. fmt.Fprintf(&b, " id: %d\n", i+1)
  31. fmt.Fprintf(&b, " user_id: %d\n", a.UserID)
  32. fmt.Fprintf(&b, " repo_id: %d\n", a.RepoID)
  33. fmt.Fprintf(&b, " mode: %d\n", a.Mode)
  34. fmt.Fprintf(&b, "\n")
  35. }
  36. return b.String(), nil
  37. }