Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

org.go 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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. import (
  6. "errors"
  7. "fmt"
  8. "os"
  9. "strings"
  10. "github.com/Unknwon/com"
  11. "github.com/go-xorm/builder"
  12. "github.com/go-xorm/xorm"
  13. )
  14. var (
  15. // ErrTeamNotExist team does not exist
  16. ErrTeamNotExist = errors.New("Team does not exist")
  17. )
  18. // IsOwnedBy returns true if given user is in the owner team.
  19. func (org *User) IsOwnedBy(uid int64) bool {
  20. return IsOrganizationOwner(org.ID, uid)
  21. }
  22. // IsOrgMember returns true if given user is member of organization.
  23. func (org *User) IsOrgMember(uid int64) bool {
  24. return org.IsOrganization() && IsOrganizationMember(org.ID, uid)
  25. }
  26. func (org *User) getTeam(e Engine, name string) (*Team, error) {
  27. return getTeam(e, org.ID, name)
  28. }
  29. // GetTeam returns named team of organization.
  30. func (org *User) GetTeam(name string) (*Team, error) {
  31. return org.getTeam(x, name)
  32. }
  33. func (org *User) getOwnerTeam(e Engine) (*Team, error) {
  34. return org.getTeam(e, ownerTeamName)
  35. }
  36. // GetOwnerTeam returns owner team of organization.
  37. func (org *User) GetOwnerTeam() (*Team, error) {
  38. return org.getOwnerTeam(x)
  39. }
  40. func (org *User) getTeams(e Engine) error {
  41. return e.
  42. Where("org_id=?", org.ID).
  43. OrderBy("CASE WHEN name LIKE '" + ownerTeamName + "' THEN '' ELSE name END").
  44. Find(&org.Teams)
  45. }
  46. // GetTeams returns all teams that belong to organization.
  47. func (org *User) GetTeams() error {
  48. return org.getTeams(x)
  49. }
  50. // GetMembers returns all members of organization.
  51. func (org *User) GetMembers() error {
  52. ous, err := GetOrgUsersByOrgID(org.ID)
  53. if err != nil {
  54. return err
  55. }
  56. var ids = make([]int64, len(ous))
  57. for i, ou := range ous {
  58. ids[i] = ou.UID
  59. }
  60. org.Members, err = GetUsersByIDs(ids)
  61. return err
  62. }
  63. // AddMember adds new member to organization.
  64. func (org *User) AddMember(uid int64) error {
  65. return AddOrgUser(org.ID, uid)
  66. }
  67. // RemoveMember removes member from organization.
  68. func (org *User) RemoveMember(uid int64) error {
  69. return RemoveOrgUser(org.ID, uid)
  70. }
  71. func (org *User) removeOrgRepo(e Engine, repoID int64) error {
  72. return removeOrgRepo(e, org.ID, repoID)
  73. }
  74. // RemoveOrgRepo removes all team-repository relations of organization.
  75. func (org *User) RemoveOrgRepo(repoID int64) error {
  76. return org.removeOrgRepo(x, repoID)
  77. }
  78. // CreateOrganization creates record of a new organization.
  79. func CreateOrganization(org, owner *User) (err error) {
  80. if !owner.CanCreateOrganization() {
  81. return ErrUserNotAllowedCreateOrg{}
  82. }
  83. if err = IsUsableUsername(org.Name); err != nil {
  84. return err
  85. }
  86. isExist, err := IsUserExist(0, org.Name)
  87. if err != nil {
  88. return err
  89. } else if isExist {
  90. return ErrUserAlreadyExist{org.Name}
  91. }
  92. org.LowerName = strings.ToLower(org.Name)
  93. if org.Rands, err = GetUserSalt(); err != nil {
  94. return err
  95. }
  96. if org.Salt, err = GetUserSalt(); err != nil {
  97. return err
  98. }
  99. org.UseCustomAvatar = true
  100. org.MaxRepoCreation = -1
  101. org.NumTeams = 1
  102. org.NumMembers = 1
  103. org.Type = UserTypeOrganization
  104. sess := x.NewSession()
  105. defer sess.Close()
  106. if err = sess.Begin(); err != nil {
  107. return err
  108. }
  109. if _, err = sess.Insert(org); err != nil {
  110. return fmt.Errorf("insert organization: %v", err)
  111. }
  112. if err = org.generateRandomAvatar(sess); err != nil {
  113. return fmt.Errorf("generate random avatar: %v", err)
  114. }
  115. // Add initial creator to organization and owner team.
  116. if _, err = sess.Insert(&OrgUser{
  117. UID: owner.ID,
  118. OrgID: org.ID,
  119. IsOwner: true,
  120. NumTeams: 1,
  121. }); err != nil {
  122. return fmt.Errorf("insert org-user relation: %v", err)
  123. }
  124. // Create default owner team.
  125. t := &Team{
  126. OrgID: org.ID,
  127. LowerName: strings.ToLower(ownerTeamName),
  128. Name: ownerTeamName,
  129. Authorize: AccessModeOwner,
  130. NumMembers: 1,
  131. UnitTypes: allRepUnitTypes,
  132. }
  133. if _, err = sess.Insert(t); err != nil {
  134. return fmt.Errorf("insert owner team: %v", err)
  135. }
  136. if _, err = sess.Insert(&TeamUser{
  137. UID: owner.ID,
  138. OrgID: org.ID,
  139. TeamID: t.ID,
  140. }); err != nil {
  141. return fmt.Errorf("insert team-user relation: %v", err)
  142. }
  143. if err = os.MkdirAll(UserPath(org.Name), os.ModePerm); err != nil {
  144. return fmt.Errorf("create directory: %v", err)
  145. }
  146. return sess.Commit()
  147. }
  148. // GetOrgByName returns organization by given name.
  149. func GetOrgByName(name string) (*User, error) {
  150. if len(name) == 0 {
  151. return nil, ErrOrgNotExist{0, name}
  152. }
  153. u := &User{
  154. LowerName: strings.ToLower(name),
  155. Type: UserTypeOrganization,
  156. }
  157. has, err := x.Get(u)
  158. if err != nil {
  159. return nil, err
  160. } else if !has {
  161. return nil, ErrOrgNotExist{0, name}
  162. }
  163. return u, nil
  164. }
  165. // CountOrganizations returns number of organizations.
  166. func CountOrganizations() int64 {
  167. count, _ := x.
  168. Where("type=1").
  169. Count(new(User))
  170. return count
  171. }
  172. // DeleteOrganization completely and permanently deletes everything of organization.
  173. func DeleteOrganization(org *User) (err error) {
  174. sess := x.NewSession()
  175. defer sess.Close()
  176. if err = sess.Begin(); err != nil {
  177. return err
  178. }
  179. if err = deleteOrg(sess, org); err != nil {
  180. if IsErrUserOwnRepos(err) {
  181. return err
  182. } else if err != nil {
  183. return fmt.Errorf("deleteOrg: %v", err)
  184. }
  185. }
  186. return sess.Commit()
  187. }
  188. func deleteOrg(e *xorm.Session, u *User) error {
  189. if !u.IsOrganization() {
  190. return fmt.Errorf("You can't delete none organization user: %s", u.Name)
  191. }
  192. // Check ownership of repository.
  193. count, err := getRepositoryCount(e, u)
  194. if err != nil {
  195. return fmt.Errorf("GetRepositoryCount: %v", err)
  196. } else if count > 0 {
  197. return ErrUserOwnRepos{UID: u.ID}
  198. }
  199. if err := deleteBeans(e,
  200. &Team{OrgID: u.ID},
  201. &OrgUser{OrgID: u.ID},
  202. &TeamUser{OrgID: u.ID},
  203. ); err != nil {
  204. return fmt.Errorf("deleteBeans: %v", err)
  205. }
  206. if _, err = e.ID(u.ID).Delete(new(User)); err != nil {
  207. return fmt.Errorf("Delete: %v", err)
  208. }
  209. // FIXME: system notice
  210. // Note: There are something just cannot be roll back,
  211. // so just keep error logs of those operations.
  212. path := UserPath(u.Name)
  213. if err := os.RemoveAll(path); err != nil {
  214. return fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
  215. }
  216. if len(u.Avatar) > 0 {
  217. avatarPath := u.CustomAvatarPath()
  218. if com.IsExist(avatarPath) {
  219. if err := os.Remove(avatarPath); err != nil {
  220. return fmt.Errorf("Failed to remove %s: %v", avatarPath, err)
  221. }
  222. }
  223. }
  224. return nil
  225. }
  226. // ________ ____ ___
  227. // \_____ \_______ ____ | | \______ ___________
  228. // / | \_ __ \/ ___\| | / ___// __ \_ __ \
  229. // / | \ | \/ /_/ > | /\___ \\ ___/| | \/
  230. // \_______ /__| \___ /|______//____ >\___ >__|
  231. // \/ /_____/ \/ \/
  232. // OrgUser represents an organization-user relation.
  233. type OrgUser struct {
  234. ID int64 `xorm:"pk autoincr"`
  235. UID int64 `xorm:"INDEX UNIQUE(s)"`
  236. OrgID int64 `xorm:"INDEX UNIQUE(s)"`
  237. IsPublic bool `xorm:"INDEX"`
  238. IsOwner bool
  239. NumTeams int
  240. }
  241. // IsOrganizationOwner returns true if given user is in the owner team.
  242. func IsOrganizationOwner(orgID, uid int64) bool {
  243. has, _ := x.
  244. Where("is_owner=?", true).
  245. And("uid=?", uid).
  246. And("org_id=?", orgID).
  247. Get(new(OrgUser))
  248. return has
  249. }
  250. // IsOrganizationMember returns true if given user is member of organization.
  251. func IsOrganizationMember(orgID, uid int64) bool {
  252. has, _ := x.
  253. Where("uid=?", uid).
  254. And("org_id=?", orgID).
  255. Get(new(OrgUser))
  256. return has
  257. }
  258. // IsPublicMembership returns true if given user public his/her membership.
  259. func IsPublicMembership(orgID, uid int64) bool {
  260. has, _ := x.
  261. Where("uid=?", uid).
  262. And("org_id=?", orgID).
  263. And("is_public=?", true).
  264. Get(new(OrgUser))
  265. return has
  266. }
  267. func getOrgsByUserID(sess *xorm.Session, userID int64, showAll bool) ([]*User, error) {
  268. orgs := make([]*User, 0, 10)
  269. if !showAll {
  270. sess.And("`org_user`.is_public=?", true)
  271. }
  272. return orgs, sess.
  273. And("`org_user`.uid=?", userID).
  274. Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").
  275. Asc("`user`.name").
  276. Find(&orgs)
  277. }
  278. // GetOrgsByUserID returns a list of organizations that the given user ID
  279. // has joined.
  280. func GetOrgsByUserID(userID int64, showAll bool) ([]*User, error) {
  281. sess := x.NewSession()
  282. defer sess.Close()
  283. return getOrgsByUserID(sess, userID, showAll)
  284. }
  285. func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
  286. orgs := make([]*User, 0, 10)
  287. return orgs, sess.
  288. Where("`org_user`.uid=?", userID).
  289. And("`org_user`.is_owner=?", true).
  290. Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").
  291. Asc("`user`.name").
  292. Find(&orgs)
  293. }
  294. // GetOwnedOrgsByUserID returns a list of organizations are owned by given user ID.
  295. func GetOwnedOrgsByUserID(userID int64) ([]*User, error) {
  296. sess := x.NewSession()
  297. defer sess.Close()
  298. return getOwnedOrgsByUserID(sess, userID)
  299. }
  300. // GetOwnedOrgsByUserIDDesc returns a list of organizations are owned by
  301. // given user ID, ordered descending by the given condition.
  302. func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
  303. return getOwnedOrgsByUserID(x.Desc(desc), userID)
  304. }
  305. // GetOrgUsersByUserID returns all organization-user relations by user ID.
  306. func GetOrgUsersByUserID(uid int64, all bool) ([]*OrgUser, error) {
  307. ous := make([]*OrgUser, 0, 10)
  308. sess := x.
  309. Join("LEFT", "user", "`org_user`.org_id=`user`.id").
  310. Where("`org_user`.uid=?", uid)
  311. if !all {
  312. // Only show public organizations
  313. sess.And("is_public=?", true)
  314. }
  315. err := sess.
  316. Asc("`user`.name").
  317. Find(&ous)
  318. return ous, err
  319. }
  320. // GetOrgUsersByOrgID returns all organization-user relations by organization ID.
  321. func GetOrgUsersByOrgID(orgID int64) ([]*OrgUser, error) {
  322. ous := make([]*OrgUser, 0, 10)
  323. err := x.
  324. Where("org_id=?", orgID).
  325. Find(&ous)
  326. return ous, err
  327. }
  328. // ChangeOrgUserStatus changes public or private membership status.
  329. func ChangeOrgUserStatus(orgID, uid int64, public bool) error {
  330. ou := new(OrgUser)
  331. has, err := x.
  332. Where("uid=?", uid).
  333. And("org_id=?", orgID).
  334. Get(ou)
  335. if err != nil {
  336. return err
  337. } else if !has {
  338. return nil
  339. }
  340. ou.IsPublic = public
  341. _, err = x.ID(ou.ID).Cols("is_public").Update(ou)
  342. return err
  343. }
  344. // AddOrgUser adds new user to given organization.
  345. func AddOrgUser(orgID, uid int64) error {
  346. if IsOrganizationMember(orgID, uid) {
  347. return nil
  348. }
  349. sess := x.NewSession()
  350. defer sess.Close()
  351. if err := sess.Begin(); err != nil {
  352. return err
  353. }
  354. ou := &OrgUser{
  355. UID: uid,
  356. OrgID: orgID,
  357. }
  358. if _, err := sess.Insert(ou); err != nil {
  359. sess.Rollback()
  360. return err
  361. } else if _, err = sess.Exec("UPDATE `user` SET num_members = num_members + 1 WHERE id = ?", orgID); err != nil {
  362. sess.Rollback()
  363. return err
  364. }
  365. return sess.Commit()
  366. }
  367. // RemoveOrgUser removes user from given organization.
  368. func RemoveOrgUser(orgID, userID int64) error {
  369. ou := new(OrgUser)
  370. has, err := x.
  371. Where("uid=?", userID).
  372. And("org_id=?", orgID).
  373. Get(ou)
  374. if err != nil {
  375. return fmt.Errorf("get org-user: %v", err)
  376. } else if !has {
  377. return nil
  378. }
  379. org, err := GetUserByID(orgID)
  380. if err != nil {
  381. return fmt.Errorf("GetUserByID [%d]: %v", orgID, err)
  382. }
  383. // Check if the user to delete is the last member in owner team.
  384. if IsOrganizationOwner(orgID, userID) {
  385. t, err := org.GetOwnerTeam()
  386. if err != nil {
  387. return err
  388. }
  389. if t.NumMembers == 1 {
  390. return ErrLastOrgOwner{UID: userID}
  391. }
  392. }
  393. sess := x.NewSession()
  394. defer sess.Close()
  395. if err := sess.Begin(); err != nil {
  396. return err
  397. }
  398. if _, err := sess.ID(ou.ID).Delete(ou); err != nil {
  399. return err
  400. } else if _, err = sess.Exec("UPDATE `user` SET num_members=num_members-1 WHERE id=?", orgID); err != nil {
  401. return err
  402. }
  403. // Delete all repository accesses and unwatch them.
  404. env, err := org.AccessibleReposEnv(userID)
  405. if err != nil {
  406. return fmt.Errorf("AccessibleReposEnv: %v", err)
  407. }
  408. repoIDs, err := env.RepoIDs(1, org.NumRepos)
  409. if err != nil {
  410. return fmt.Errorf("GetUserRepositories [%d]: %v", userID, err)
  411. }
  412. for _, repoID := range repoIDs {
  413. if err = watchRepo(sess, userID, repoID, false); err != nil {
  414. return err
  415. }
  416. }
  417. if len(repoIDs) > 0 {
  418. if _, err = sess.
  419. Where("user_id = ?", userID).
  420. In("repo_id", repoIDs).
  421. Delete(new(Access)); err != nil {
  422. return err
  423. }
  424. }
  425. // Delete member in his/her teams.
  426. teams, err := getUserTeams(sess, org.ID, userID)
  427. if err != nil {
  428. return err
  429. }
  430. for _, t := range teams {
  431. if err = removeTeamMember(sess, t, userID); err != nil {
  432. return err
  433. }
  434. }
  435. return sess.Commit()
  436. }
  437. func removeOrgRepo(e Engine, orgID, repoID int64) error {
  438. teamRepos := make([]*TeamRepo, 0, 10)
  439. if err := e.Find(&teamRepos, &TeamRepo{OrgID: orgID, RepoID: repoID}); err != nil {
  440. return err
  441. }
  442. if len(teamRepos) == 0 {
  443. return nil
  444. }
  445. if _, err := e.Delete(&TeamRepo{
  446. OrgID: orgID,
  447. RepoID: repoID,
  448. }); err != nil {
  449. return err
  450. }
  451. teamIDs := make([]int64, len(teamRepos))
  452. for i, teamRepo := range teamRepos {
  453. teamIDs[i] = teamRepo.TeamID
  454. }
  455. _, err := e.Decr("num_repos").In("id", teamIDs).Update(new(Team))
  456. return err
  457. }
  458. func (org *User) getUserTeams(e Engine, userID int64, cols ...string) ([]*Team, error) {
  459. teams := make([]*Team, 0, org.NumTeams)
  460. return teams, e.
  461. Where("`team_user`.org_id = ?", org.ID).
  462. Join("INNER", "team_user", "`team_user`.team_id = team.id").
  463. Join("INNER", "user", "`user`.id=team_user.uid").
  464. And("`team_user`.uid = ?", userID).
  465. Asc("`user`.name").
  466. Cols(cols...).
  467. Find(&teams)
  468. }
  469. func (org *User) getUserTeamIDs(e Engine, userID int64) ([]int64, error) {
  470. teamIDs := make([]int64, 0, org.NumTeams)
  471. return teamIDs, e.
  472. Table("team").
  473. Cols("team.id").
  474. Where("`team_user`.org_id = ?", org.ID).
  475. Join("INNER", "team_user", "`team_user`.team_id = team.id").
  476. And("`team_user`.uid = ?", userID).
  477. Find(&teamIDs)
  478. }
  479. // TeamsWithAccessToRepo returns all teamsthat have given access level to the repository.
  480. func (org *User) TeamsWithAccessToRepo(repoID int64, mode AccessMode) ([]*Team, error) {
  481. return GetTeamsWithAccessToRepo(org.ID, repoID, mode)
  482. }
  483. // GetUserTeamIDs returns of all team IDs of the organization that user is member of.
  484. func (org *User) GetUserTeamIDs(userID int64) ([]int64, error) {
  485. return org.getUserTeamIDs(x, userID)
  486. }
  487. // GetUserTeams returns all teams that belong to user,
  488. // and that the user has joined.
  489. func (org *User) GetUserTeams(userID int64) ([]*Team, error) {
  490. return org.getUserTeams(x, userID)
  491. }
  492. // AccessibleReposEnvironment operations involving the repositories that are
  493. // accessible to a particular user
  494. type AccessibleReposEnvironment interface {
  495. CountRepos() (int64, error)
  496. RepoIDs(page, pageSize int) ([]int64, error)
  497. Repos(page, pageSize int) ([]*Repository, error)
  498. MirrorRepos() ([]*Repository, error)
  499. }
  500. type accessibleReposEnv struct {
  501. org *User
  502. userID int64
  503. teamIDs []int64
  504. }
  505. // AccessibleReposEnv an AccessibleReposEnvironment for the repositories in `org`
  506. // that are accessible to the specified user.
  507. func (org *User) AccessibleReposEnv(userID int64) (AccessibleReposEnvironment, error) {
  508. teamIDs, err := org.GetUserTeamIDs(userID)
  509. if err != nil {
  510. return nil, err
  511. }
  512. return &accessibleReposEnv{org: org, userID: userID, teamIDs: teamIDs}, nil
  513. }
  514. func (env *accessibleReposEnv) cond() builder.Cond {
  515. var cond builder.Cond = builder.Eq{
  516. "`repository`.owner_id": env.org.ID,
  517. "`repository`.is_private": false,
  518. }
  519. if len(env.teamIDs) > 0 {
  520. cond = cond.Or(builder.In("team_repo.team_id", env.teamIDs))
  521. }
  522. return cond
  523. }
  524. func (env *accessibleReposEnv) CountRepos() (int64, error) {
  525. repoCount, err := x.
  526. Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id").
  527. Where(env.cond()).
  528. Distinct("`repository`.id").
  529. Count(&Repository{})
  530. if err != nil {
  531. return 0, fmt.Errorf("count user repositories in organization: %v", err)
  532. }
  533. return repoCount, nil
  534. }
  535. func (env *accessibleReposEnv) RepoIDs(page, pageSize int) ([]int64, error) {
  536. if page <= 0 {
  537. page = 1
  538. }
  539. repoIDs := make([]int64, 0, pageSize)
  540. return repoIDs, x.
  541. Table("repository").
  542. Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id").
  543. Where(env.cond()).
  544. GroupBy("`repository`.id,`repository`.updated_unix").
  545. OrderBy("updated_unix DESC").
  546. Limit(pageSize, (page-1)*pageSize).
  547. Cols("`repository`.id").
  548. Find(&repoIDs)
  549. }
  550. func (env *accessibleReposEnv) Repos(page, pageSize int) ([]*Repository, error) {
  551. repoIDs, err := env.RepoIDs(page, pageSize)
  552. if err != nil {
  553. return nil, fmt.Errorf("GetUserRepositoryIDs: %v", err)
  554. }
  555. repos := make([]*Repository, 0, len(repoIDs))
  556. if len(repoIDs) <= 0 {
  557. return repos, nil
  558. }
  559. return repos, x.
  560. In("`repository`.id", repoIDs).
  561. Find(&repos)
  562. }
  563. func (env *accessibleReposEnv) MirrorRepoIDs() ([]int64, error) {
  564. repoIDs := make([]int64, 0, 10)
  565. return repoIDs, x.
  566. Table("repository").
  567. Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id AND `repository`.is_mirror=?", true).
  568. Where(env.cond()).
  569. GroupBy("`repository`.id, `repository`.updated_unix").
  570. OrderBy("updated_unix DESC").
  571. Cols("`repository`.id").
  572. Find(&repoIDs)
  573. }
  574. func (env *accessibleReposEnv) MirrorRepos() ([]*Repository, error) {
  575. repoIDs, err := env.MirrorRepoIDs()
  576. if err != nil {
  577. return nil, fmt.Errorf("MirrorRepoIDs: %v", err)
  578. }
  579. repos := make([]*Repository, 0, len(repoIDs))
  580. if len(repoIDs) <= 0 {
  581. return repos, nil
  582. }
  583. return repos, x.
  584. In("`repository`.id", repoIDs).
  585. Find(&repos)
  586. }