Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

org.go 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2014 The Gogs 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. type AuthorizeType int
  6. const (
  7. ORG_READABLE AuthorizeType = iota + 1
  8. ORG_WRITABLE
  9. ORG_ADMIN
  10. )
  11. const OWNER_TEAM = "Owner"
  12. // Team represents a organization team.
  13. type Team struct {
  14. Id int64
  15. OrgId int64 `xorm:"INDEX"`
  16. Name string
  17. Description string
  18. Authorize AuthorizeType
  19. RepoIds string `xorm:"TEXT"`
  20. NumMembers int
  21. NumRepos int
  22. }
  23. // NewTeam creates a record of new team.
  24. func NewTeam(t *Team) error {
  25. _, err := x.Insert(t)
  26. return err
  27. }
  28. func UpdateTeam(t *Team) error {
  29. if len(t.Description) > 255 {
  30. t.Description = t.Description[:255]
  31. }
  32. _, err := x.Id(t.Id).AllCols().Update(t)
  33. return err
  34. }
  35. // ________ ____ ___
  36. // \_____ \_______ ____ | | \______ ___________
  37. // / | \_ __ \/ ___\| | / ___// __ \_ __ \
  38. // / | \ | \/ /_/ > | /\___ \\ ___/| | \/
  39. // \_______ /__| \___ /|______//____ >\___ >__|
  40. // \/ /_____/ \/ \/
  41. // OrgUser represents an organization-user relation.
  42. type OrgUser struct {
  43. Id int64
  44. Uid int64 `xorm:"INDEX"`
  45. OrgId int64 `xorm:"INDEX"`
  46. IsPublic bool
  47. IsOwner bool
  48. NumTeam int
  49. }
  50. // GetOrgUsersByUserId returns all organization-user relations by user ID.
  51. func GetOrgUsersByUserId(uid int64) ([]*OrgUser, error) {
  52. ous := make([]*OrgUser, 0, 10)
  53. err := x.Where("uid=?", uid).Find(&ous)
  54. return ous, err
  55. }
  56. // GetOrgUsersByOrgId returns all organization-user relations by organization ID.
  57. func GetOrgUsersByOrgId(orgId int64) ([]*OrgUser, error) {
  58. ous := make([]*OrgUser, 0, 10)
  59. err := x.Where("org_id=?", orgId).Find(&ous)
  60. return ous, err
  61. }
  62. // ___________ ____ ___
  63. // \__ ___/___ _____ _____ | | \______ ___________
  64. // | |_/ __ \\__ \ / \| | / ___// __ \_ __ \
  65. // | |\ ___/ / __ \| Y Y \ | /\___ \\ ___/| | \/
  66. // |____| \___ >____ /__|_| /______//____ >\___ >__|
  67. // \/ \/ \/ \/ \/
  68. // TeamUser represents an team-user relation.
  69. type TeamUser struct {
  70. Id int64
  71. Uid int64
  72. OrgId int64 `xorm:"INDEX"`
  73. TeamId int64
  74. }
  75. // GetTeamMembers returns all members in given team of organization.
  76. func GetTeamMembers(orgId, teamId int64) ([]*User, error) {
  77. tus := make([]*TeamUser, 0, 10)
  78. err := x.Where("org_id=?", orgId).And("team_id=?", teamId).Find(&tus)
  79. if err != nil {
  80. return nil, err
  81. }
  82. us := make([]*User, len(tus))
  83. for i, tu := range tus {
  84. us[i], err = GetUserById(tu.Uid)
  85. if err != nil {
  86. return nil, err
  87. }
  88. }
  89. return us, nil
  90. }