feat: store last seen date for users and present in stats and user lists, closes #9007

This commit is contained in:
Torkel Ödegaard
2017-08-09 10:36:41 +02:00
parent 26ad025705
commit e8a20643d6
15 changed files with 249 additions and 84 deletions
+7 -5
View File
@@ -103,9 +103,11 @@ type GetOrgUsersQuery struct {
// Projections and DTOs
type OrgUserDTO struct {
OrgId int64 `json:"orgId"`
UserId int64 `json:"userId"`
Email string `json:"email"`
Login string `json:"login"`
Role string `json:"role"`
OrgId int64 `json:"orgId"`
UserId int64 `json:"userId"`
Email string `json:"email"`
Login string `json:"login"`
Role string `json:"role"`
LastSeenAt time.Time `json:"lastSeenAt"`
LastSeenAtAge string `json:"lastSeenAtAge"`
}
+17 -14
View File
@@ -1,11 +1,13 @@
package models
type SystemStats struct {
DashboardCount int64
UserCount int64
OrgCount int64
PlaylistCount int64
AlertCount int64
Dashboards int64
Datasources int64
Users int64
ActiveUsers int64
Orgs int64
Playlists int64
Alerts int64
}
type DataSourceStats struct {
@@ -22,15 +24,16 @@ type GetDataSourceStatsQuery struct {
}
type AdminStats struct {
UserCount int `json:"user_count"`
OrgCount int `json:"org_count"`
DashboardCount int `json:"dashboard_count"`
DbSnapshotCount int `json:"db_snapshot_count"`
DbTagCount int `json:"db_tag_count"`
DataSourceCount int `json:"data_source_count"`
PlaylistCount int `json:"playlist_count"`
StarredDbCount int `json:"starred_db_count"`
AlertCount int `json:"alert_count"`
Users int `json:"users"`
Orgs int `json:"orgs"`
Dashboards int `json:"dashboards"`
Snapshots int `json:"snapshots"`
Tags int `json:"tags"`
Datasources int `json:"datasources"`
Playlists int `json:"playlists"`
Stars int `json:"stars"`
Alerts int `json:"alerts"`
ActiveUsers int `json:"activeUsers"`
}
type GetAdminStatsQuery struct {
+20 -7
View File
@@ -33,8 +33,9 @@ type User struct {
IsAdmin bool
OrgId int64
Created time.Time
Updated time.Time
Created time.Time
Updated time.Time
LastSeenAt time.Time
}
func (u *User) NameOrFallback() string {
@@ -127,6 +128,7 @@ type GetUserProfileQuery struct {
}
type SearchUsersQuery struct {
OrgId int64
Query string
Page int
Limit int
@@ -160,6 +162,15 @@ type SignedInUser struct {
ApiKeyId int64
IsGrafanaAdmin bool
HelpFlags1 HelpFlags1
LastSeenAt time.Time
}
func (u *SignedInUser) ShouldUpdateLastSeenAt() bool {
return u.UserId > 0 && time.Since(u.LastSeenAt) > time.Minute*5
}
type UpdateUserLastSeenAtCommand struct {
UserId int64
}
type UserProfileDTO struct {
@@ -173,11 +184,13 @@ type UserProfileDTO struct {
}
type UserSearchHitDTO struct {
Id int64 `json:"id"`
Name string `json:"name"`
Login string `json:"login"`
Email string `json:"email"`
IsAdmin bool `json:"isAdmin"`
Id int64 `json:"id"`
Name string `json:"name"`
Login string `json:"login"`
Email string `json:"email"`
IsAdmin bool `json:"isAdmin"`
LastSeenAt time.Time `json:"lastSeenAt"`
LastSeenAtAge string `json:"lastSeenAtAge"`
}
type UserIdDTO struct {