Add session handling for user list

This commit is contained in:
kolaente 2020-12-23 01:06:54 +01:00
parent 662593d4fd
commit 79731d66ed
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 7 additions and 4 deletions

View File

@ -20,6 +20,7 @@ package models
import (
"code.vikunja.io/api/pkg/user"
"xorm.io/builder"
"xorm.io/xorm"
)
// ListUIDs hold all kinds of user IDs from accounts who have somehow access to a list
@ -33,11 +34,11 @@ type ListUIDs struct {
}
// ListUsersFromList returns a list with all users who have access to a list, regardless of the method which gave them access
func ListUsersFromList(l *List, search string) (users []*user.User, err error) {
func ListUsersFromList(s *xorm.Session, l *List, search string) (users []*user.User, err error) {
userids := []*ListUIDs{}
err = x.
err = s.
Select(`l.owner_id as listOwner,
un.user_id as unID,
ul.user_id as ulID,
@ -97,7 +98,7 @@ func ListUsersFromList(l *List, search string) (users []*user.User, err error) {
}
// Get all users
err = x.
err = s.
Table("users").
Select("*").
In("id", uids).

View File

@ -201,8 +201,10 @@ func TestListUsersFromList(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := x.NewSession()
defer s.Close()
gotUsers, err := ListUsersFromList(tt.args.l, tt.args.search)
gotUsers, err := ListUsersFromList(s, tt.args.l, tt.args.search)
if (err != nil) != tt.wantErr {
t.Errorf("ListUsersFromList() error = %v, wantErr %v", err, tt.wantErr)
return