code.gitea.io/gitea@v1.22.3/models/auth/oauth2_list.go (about)

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