@@ -19,17 +19,18 @@ package user
1919import (
2020 "context"
2121 "fmt"
22+ "net/http"
23+ "strconv"
24+ "strings"
25+ "sync"
26+ "time"
27+
2228 bean4 "github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin/bean"
2329 "github.com/devtron-labs/devtron/pkg/auth/user/adapter"
2430 userHelper "github.com/devtron-labs/devtron/pkg/auth/user/helper"
2531 adapter2 "github.com/devtron-labs/devtron/pkg/auth/user/repository/adapter"
2632 "github.com/devtron-labs/devtron/pkg/auth/user/repository/helper"
2733 util3 "github.com/devtron-labs/devtron/pkg/auth/user/util"
28- "net/http"
29- "strconv"
30- "strings"
31- "sync"
32- "time"
3334
3435 "github.com/devtron-labs/authenticator/jwt"
3536 "github.com/devtron-labs/authenticator/middleware"
@@ -1237,7 +1238,7 @@ func (impl *UserServiceImpl) GetLoggedInUser(r *http.Request) (int32, error) {
12371238 userId , userType , err := impl .GetUserByToken (r .Context (), token )
12381239 // if user is of api-token type, then update lastUsedBy and lastUsedAt
12391240 if err == nil && userType == userBean .USER_TYPE_API_TOKEN {
1240- go impl .saveUserAudit (r , userId )
1241+ go impl .updateUserAudit (r , userId )
12411242 }
12421243 return userId , err
12431244}
@@ -1664,6 +1665,15 @@ func (impl *UserServiceImpl) saveUserAudit(r *http.Request, userId int32) {
16641665 CreatedOn : time .Now (),
16651666 UpdatedOn : time .Now (),
16661667 }
1668+ impl .userAuditService .Save (userAudit )
1669+ }
1670+
1671+ func (impl * UserServiceImpl ) updateUserAudit (r * http.Request , userId int32 ) {
1672+ clientIp := util2 .GetClientIP (r )
1673+ userAudit := & UserAudit {
1674+ UserId : userId ,
1675+ ClientIp : clientIp ,
1676+ }
16671677 impl .userAuditService .Update (userAudit )
16681678}
16691679
0 commit comments