diff --git a/pkg/models/user_list.go b/pkg/models/user_list.go index cc1509980..505524143 100644 --- a/pkg/models/user_list.go +++ b/pkg/models/user_list.go @@ -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). diff --git a/pkg/models/users_list_test.go b/pkg/models/users_list_test.go index 16201aa0d..8fbde649e 100644 --- a/pkg/models/users_list_test.go +++ b/pkg/models/users_list_test.go @@ -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