gitea源码

oauth2_list.go 743B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package auth
  4. import (
  5. "code.gitea.io/gitea/models/db"
  6. "xorm.io/builder"
  7. )
  8. type FindOAuth2ApplicationsOptions struct {
  9. db.ListOptions
  10. // OwnerID is the user id or org id of the owner of the application
  11. OwnerID int64
  12. // find global applications, if true, then OwnerID will be igonred
  13. IsGlobal bool
  14. }
  15. func (opts FindOAuth2ApplicationsOptions) ToConds() builder.Cond {
  16. conds := builder.NewCond()
  17. if opts.IsGlobal {
  18. conds = conds.And(builder.Eq{"uid": 0})
  19. } else if opts.OwnerID != 0 {
  20. conds = conds.And(builder.Eq{"uid": opts.OwnerID})
  21. }
  22. return conds
  23. }
  24. func (opts FindOAuth2ApplicationsOptions) ToOrders() string {
  25. return "id DESC"
  26. }