mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-05 01:45:22 +02:00
[API] Delete Token accept names too (#12366)
* Delete Token accept names too * better description Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
parent
eb1bf2377b
commit
d5b6931dbe
7 changed files with 77 additions and 20 deletions
|
@ -82,16 +82,27 @@ func AccessTokenByNameExists(token *AccessToken) (bool, error) {
|
|||
return x.Table("access_token").Where("name = ?", token.Name).And("uid = ?", token.UID).Exist()
|
||||
}
|
||||
|
||||
// ListAccessTokensOptions contain filter options
|
||||
type ListAccessTokensOptions struct {
|
||||
ListOptions
|
||||
Name string
|
||||
UserID int64
|
||||
}
|
||||
|
||||
// ListAccessTokens returns a list of access tokens belongs to given user.
|
||||
func ListAccessTokens(uid int64, listOptions ListOptions) ([]*AccessToken, error) {
|
||||
sess := x.
|
||||
Where("uid=?", uid).
|
||||
Desc("id")
|
||||
func ListAccessTokens(opts ListAccessTokensOptions) ([]*AccessToken, error) {
|
||||
sess := x.Where("uid=?", opts.UserID)
|
||||
|
||||
if listOptions.Page != 0 {
|
||||
sess = listOptions.setSessionPagination(sess)
|
||||
if len(opts.Name) != 0 {
|
||||
sess = sess.Where("name=?", opts.Name)
|
||||
}
|
||||
|
||||
tokens := make([]*AccessToken, 0, listOptions.PageSize)
|
||||
sess = sess.Desc("id")
|
||||
|
||||
if opts.Page != 0 {
|
||||
sess = opts.setSessionPagination(sess)
|
||||
|
||||
tokens := make([]*AccessToken, 0, opts.PageSize)
|
||||
return tokens, sess.Find(&tokens)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue