mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-09 23:48:24 +01:00
Handle user lastLogin null time
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
parent
0207a326dc
commit
9ee234ac35
@ -789,7 +789,7 @@ func (am *DefaultAccountManager) lookupUserInCache(ctx context.Context, userID s
|
||||
if user.Issued == types.UserIssuedIntegration {
|
||||
continue
|
||||
}
|
||||
users[user.Id] = userLoggedInOnce(!user.LastLogin.IsZero())
|
||||
users[user.Id] = userLoggedInOnce(!user.LastLogin.Time.IsZero())
|
||||
}
|
||||
log.WithContext(ctx).Debugf("looking up user %s of account %s in cache", userID, account.Id)
|
||||
userData, err := am.lookupCache(ctx, users, account.Id)
|
||||
|
@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"database/sql"
|
||||
b64 "encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@ -1096,7 +1097,7 @@ func genUsers(p string, n int) map[string]*types.User {
|
||||
users[fmt.Sprintf("%s-%d", p, i)] = &types.User{
|
||||
Id: fmt.Sprintf("%s-%d", p, i),
|
||||
Role: types.UserRoleAdmin,
|
||||
LastLogin: now,
|
||||
LastLogin: sql.NullTime{Time: now, Valid: !now.IsZero()},
|
||||
CreatedAt: now,
|
||||
Issued: "api",
|
||||
AutoGroups: []string{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"},
|
||||
|
@ -2,6 +2,7 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -900,7 +901,7 @@ func (s *SqlStore) SaveUserLastLogin(ctx context.Context, accountID, userID stri
|
||||
}
|
||||
return status.NewGetUserFromStoreError()
|
||||
}
|
||||
user.LastLogin = lastLogin
|
||||
user.LastLogin = sql.NullTime{Time: lastLogin, Valid: !lastLogin.IsZero()}
|
||||
|
||||
return s.db.Save(&user).Error
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@ -84,7 +85,7 @@ type User struct {
|
||||
// Blocked indicates whether the user is blocked. Blocked users can't use the system.
|
||||
Blocked bool
|
||||
// LastLogin is the last time the user logged in to IdP
|
||||
LastLogin time.Time `gorm:"type:TIMESTAMP;null;default:null"`
|
||||
LastLogin sql.NullTime
|
||||
// CreatedAt records the time the user was created
|
||||
CreatedAt time.Time
|
||||
|
||||
@ -100,7 +101,7 @@ func (u *User) IsBlocked() bool {
|
||||
}
|
||||
|
||||
func (u *User) LastDashboardLoginChanged(LastLogin time.Time) bool {
|
||||
return LastLogin.After(u.LastLogin) && !u.LastLogin.IsZero()
|
||||
return LastLogin.After(u.LastLogin.Time) && !u.LastLogin.Time.IsZero()
|
||||
}
|
||||
|
||||
// HasAdminPower returns true if the user has admin or owner roles, false otherwise
|
||||
@ -143,7 +144,7 @@ func (u *User) ToUserInfo(userData *idp.UserData, settings *Settings) (*UserInfo
|
||||
Status: string(UserStatusActive),
|
||||
IsServiceUser: u.IsServiceUser,
|
||||
IsBlocked: u.Blocked,
|
||||
LastLogin: u.LastLogin,
|
||||
LastLogin: u.LastLogin.Time,
|
||||
Issued: u.Issued,
|
||||
Permissions: UserPermissions{
|
||||
DashboardView: dashboardViewPermissions,
|
||||
@ -168,7 +169,7 @@ func (u *User) ToUserInfo(userData *idp.UserData, settings *Settings) (*UserInfo
|
||||
Status: string(userStatus),
|
||||
IsServiceUser: u.IsServiceUser,
|
||||
IsBlocked: u.Blocked,
|
||||
LastLogin: u.LastLogin,
|
||||
LastLogin: u.LastLogin.Time,
|
||||
Issued: u.Issued,
|
||||
Permissions: UserPermissions{
|
||||
DashboardView: dashboardViewPermissions,
|
||||
|
@ -880,7 +880,7 @@ func (am *DefaultAccountManager) GetUsersFromAccount(ctx context.Context, accoun
|
||||
continue
|
||||
}
|
||||
if !user.IsServiceUser {
|
||||
users[user.Id] = userLoggedInOnce(!user.LastLogin.IsZero())
|
||||
users[user.Id] = userLoggedInOnce(!user.LastLogin.Time.IsZero())
|
||||
}
|
||||
}
|
||||
queriedUsers, err = am.lookupCache(ctx, users, accountID)
|
||||
|
@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
@ -328,7 +329,7 @@ func TestUser_Copy(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Blocked: false,
|
||||
LastLogin: time.Now().UTC(),
|
||||
LastLogin: sql.NullTime{Time: time.Now().UTC(), Valid: true},
|
||||
CreatedAt: time.Now().UTC(),
|
||||
Issued: "test",
|
||||
IntegrationReference: integration_reference.IntegrationReference{
|
||||
|
Loading…
Reference in New Issue
Block a user