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 4
4
5
5
package models
6
6
7
+ import (
8
+ "fmt"
9
+ )
10
+
7
11
//UserList is a list of user.
8
12
// This type provide valuable methods to retrieve information for a group of users efficiently.
9
13
type UserList []* User
@@ -29,9 +33,31 @@ func (users UserList) IsUserOrgOwner(orgID int64) map[int64]bool {
29
33
// GetTwoFaStatus return state of 2FA enrollement
30
34
func (users UserList ) GetTwoFaStatus () map [int64 ]bool {
31
35
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
+ }
35
44
}
45
+
36
46
return results
37
47
}
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) {
76
76
})
77
77
}
78
78
}
79
+
79
80
func testUserListIsTwoFaEnrolled (t * testing.T , orgID int64 , expected map [int64 ]bool ) {
80
81
org , err := GetUserByID (orgID )
81
82
assert .NoError (t , err )
82
83
assert .NoError (t , org .GetMembers ())
83
84
assert .Equal (t , expected , org .Members .GetTwoFaStatus ())
84
-
85
85
}
You can’t perform that action at this time.
0 commit comments