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

org.go 17 kB

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