(tx *storage.Connection, token string, forUpdate bool)
| 694 | } |
| 695 | |
| 696 | func findUserWithLegacyRefreshToken(tx *storage.Connection, token string, forUpdate bool) (*User, any, *Session, error) { |
| 697 | refreshToken := &RefreshToken{} |
| 698 | |
| 699 | if forUpdate { |
| 700 | // pop does not provide us with a way to execute FOR UPDATE |
| 701 | // queries which lock the rows affected by the query from |
| 702 | // being accessed by any other transaction that also uses FOR |
| 703 | // UPDATE |
| 704 | if err := tx.RawQuery(fmt.Sprintf("SELECT * FROM %q WHERE token = ? LIMIT 1 FOR UPDATE SKIP LOCKED;", refreshToken.TableName()), token).First(refreshToken); err != nil { |
| 705 | if errors.Cause(err) == sql.ErrNoRows { |
| 706 | return nil, nil, nil, RefreshTokenNotFoundError{} |
| 707 | } |
| 708 | |
| 709 | return nil, nil, nil, errors.Wrap(err, "error finding refresh token for update") |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | // once the rows are locked (if forUpdate was true), we can query again using pop |
| 714 | if err := tx.Where("token = ?", token).First(refreshToken); err != nil { |
| 715 | if errors.Cause(err) == sql.ErrNoRows { |
| 716 | return nil, nil, nil, RefreshTokenNotFoundError{} |
| 717 | } |
| 718 | return nil, nil, nil, errors.Wrap(err, "error finding refresh token") |
| 719 | } |
| 720 | |
| 721 | user, err := FindUserByID(tx, refreshToken.UserID) |
| 722 | if err != nil { |
| 723 | return nil, nil, nil, err |
| 724 | } |
| 725 | |
| 726 | var session *Session |
| 727 | |
| 728 | if refreshToken.SessionId != nil { |
| 729 | sessionId := *refreshToken.SessionId |
| 730 | |
| 731 | if sessionId != uuid.Nil { |
| 732 | session, err = FindSessionByID(tx, sessionId, forUpdate) |
| 733 | if err != nil { |
| 734 | if forUpdate { |
| 735 | return nil, nil, nil, err |
| 736 | } |
| 737 | |
| 738 | if !IsNotFoundError(err) { |
| 739 | return nil, nil, nil, errors.Wrap(err, "error finding session from refresh token") |
| 740 | } |
| 741 | |
| 742 | // otherwise, there's no session for this refresh token |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | return user, refreshToken, session, nil |
| 748 | } |
| 749 | |
| 750 | // FindUsersInAudience finds users with the matching audience. |
| 751 | func FindUsersInAudience(tx *storage.Connection, aud string, pageParams *Pagination, sortParams *SortParams, filter string) ([]*User, error) { |
no test coverage detected