File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 44
55package models
66
7+ import (
8+ "fmt"
9+ )
10+
711//UserList is a list of user.
812// This type provide valuable methods to retrieve information for a group of users efficiently.
913type UserList []* User
@@ -29,9 +33,31 @@ func (users UserList) IsUserOrgOwner(orgID int64) map[int64]bool {
2933// GetTwoFaStatus return state of 2FA enrollement
3034func (users UserList ) GetTwoFaStatus () map [int64 ]bool {
3135 results := make (map [int64 ]bool , len (users ))
32- //TODO use directly xorm
33- for _ , u := range users {
34- results [u .ID ] = u .IsTwoFaEnrolled ()
36+ for _ , user := range users {
37+ results [user .ID ] = false //Set default to false
38+ }
39+ tokenMaps , err := users .loadTwoFactorStatus (x )
40+ if err == nil {
41+ for _ , token := range tokenMaps {
42+ results [token .UID ] = true
43+ }
3544 }
45+
3646 return results
3747}
48+
49+ func (users UserList ) loadTwoFactorStatus (e Engine ) (map [int64 ]* TwoFactor , error ) {
50+ if len (users ) == 0 {
51+ return nil , nil
52+ }
53+
54+ userIDs := users .getUserIDs ()
55+ tokenMaps := make (map [int64 ]* TwoFactor , len (userIDs ))
56+ err := e .
57+ In ("uid" , userIDs ).
58+ Find (& tokenMaps )
59+ if err != nil {
60+ return nil , fmt .Errorf ("find two factor: %v" , err )
61+ }
62+ return tokenMaps , nil
63+ }
Original file line number Diff line number Diff line change @@ -76,10 +76,10 @@ func TestUserListIsTwoFaEnrolled(t *testing.T) {
7676 })
7777 }
7878}
79+
7980func testUserListIsTwoFaEnrolled (t * testing.T , orgID int64 , expected map [int64 ]bool ) {
8081 org , err := GetUserByID (orgID )
8182 assert .NoError (t , err )
8283 assert .NoError (t , org .GetMembers ())
8384 assert .Equal (t , expected , org .Members .GetTwoFaStatus ())
84-
8585}
You can’t perform that action at this time.
0 commit comments