From 490aaedb48d2f6bbe34e5795fc71f439ac7d988b Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Fri, 16 May 2025 23:11:22 +0530 Subject: [PATCH] fix: update activity log types to use agent prefixes for consistency --- .../src/composables/useActivityLogFilters.js | 20 +++++++++---------- internal/activity_log/activity_log.go | 10 +++++----- internal/activity_log/models/models.go | 11 +++++----- internal/migrations/v0.6.0.go | 3 ++- schema.sql | 3 ++- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/frontend/src/composables/useActivityLogFilters.js b/frontend/src/composables/useActivityLogFilters.js index 89d572e..5a179b5 100644 --- a/frontend/src/composables/useActivityLogFilters.js +++ b/frontend/src/composables/useActivityLogFilters.js @@ -16,20 +16,20 @@ export function useActivityLogFilters () { type: FIELD_TYPE.SELECT, operators: FIELD_OPERATORS.SELECT, options: [{ - label: 'Login', - value: 'login' + label: 'User login', + value: 'agent_login' }, { - label: 'Logout', - value: 'logout' + label: 'User logout', + value: 'agent_logout' }, { - label: 'Away', - value: 'away' + label: 'User away', + value: 'agent_away' }, { - label: 'Away Reassigned', - value: 'away_reassigned' + label: 'User away reassigned', + value: 'agent_away_reassigned' }, { - label: 'Online', - value: 'online' + label: 'User online', + value: 'agent_online' }] }, })) diff --git a/internal/activity_log/activity_log.go b/internal/activity_log/activity_log.go index 0b2356a..4094e68 100644 --- a/internal/activity_log/activity_log.go +++ b/internal/activity_log/activity_log.go @@ -95,7 +95,7 @@ func (m *Manager) Create(activityType, activityDescription string, actorID int, // Login records a login event for the given user. func (al *Manager) Login(userID int, email, ip string) error { return al.Create( - models.Login, + models.AgentLogin, fmt.Sprintf("%s (#%d) logged in", email, userID), userID, umodels.UserModel, @@ -107,7 +107,7 @@ func (al *Manager) Login(userID int, email, ip string) error { // Logout records a logout event for the given user. func (al *Manager) Logout(userID int, email, ip string) error { return al.Create( - models.Logout, + models.AgentLogout, fmt.Sprintf("%s (#%d) logged out", email, userID), userID, umodels.UserModel, @@ -125,7 +125,7 @@ func (al *Manager) Away(actorID int, actorEmail, ip string, targetID int, target description = fmt.Sprintf("%s (#%d) is away", actorEmail, actorID) } return al.Create( - models.Away, /* activity type*/ + models.AgentAway, /* activity type*/ description, actorID, /*actor_id*/ umodels.UserModel, /*target_model_type*/ @@ -143,7 +143,7 @@ func (al *Manager) AwayReassigned(actorID int, actorEmail, ip string, targetID i description = fmt.Sprintf("%s (#%d) is away and reassigning", actorEmail, actorID) } return al.Create( - models.AwayReassigned, /* activity type*/ + models.AgentAwayReassigned, /* activity type*/ description, actorID, /*actor_id*/ umodels.UserModel, /*target_model_type*/ @@ -161,7 +161,7 @@ func (al *Manager) Online(actorID int, actorEmail, ip string, targetID int, targ description = fmt.Sprintf("%s (#%d) is online", actorEmail, actorID) } return al.Create( - models.Online, /* activity type*/ + models.AgentOnline, /* activity type*/ description, actorID, /*actor_id*/ umodels.UserModel, /*target_model_type*/ diff --git a/internal/activity_log/models/models.go b/internal/activity_log/models/models.go index 773e3e7..3b1f72d 100644 --- a/internal/activity_log/models/models.go +++ b/internal/activity_log/models/models.go @@ -5,12 +5,11 @@ import ( ) const ( - Login = "login" - Logout = "logout" - Away = "away" - AwayManual = "away_manual" - AwayReassigned = "away_reassigned" - Online = "online" + AgentLogin = "agent_login" + AgentLogout = "agent_logout" + AgentAway = "agent_away" + AgentAwayReassigned = "agent_away_reassigned" + AgentOnline = "agent_online" ) type ActivityLog struct { diff --git a/internal/migrations/v0.6.0.go b/internal/migrations/v0.6.0.go index a898233..e1b26db 100644 --- a/internal/migrations/v0.6.0.go +++ b/internal/migrations/v0.6.0.go @@ -167,7 +167,7 @@ func V0_6_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error { IF NOT EXISTS ( SELECT 1 FROM pg_type WHERE typname = 'activity_log_type' ) THEN - CREATE TYPE activity_log_type AS ENUM ('login', 'logout', 'away', 'away_reassigned', 'online'); + CREATE TYPE activity_log_type AS ENUM ('agent_login', 'agent_logout', 'agent_away', 'agent_away_reassigned', 'agent_online'); END IF; END $$; @@ -191,6 +191,7 @@ func V0_6_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error { ); CREATE INDEX IF NOT EXISTS index_activity_logs_on_actor_id ON activity_logs (actor_id); CREATE INDEX IF NOT EXISTS index_activity_logs_on_activity_type ON activity_logs (activity_type); + CREATE INDEX IF NOT EXISTS index_activity_logs_on_created_at ON activity_logs (created_at); `) if err != nil { return err diff --git a/schema.sql b/schema.sql index 200e966..6fbe799 100644 --- a/schema.sql +++ b/schema.sql @@ -17,7 +17,7 @@ DROP TYPE IF EXISTS "user_availability_status" CASCADE; CREATE TYPE "user_availa DROP TYPE IF EXISTS "applied_sla_status" CASCADE; CREATE TYPE "applied_sla_status" AS ENUM ('pending', 'breached', 'met', 'partially_met'); DROP TYPE IF EXISTS "sla_metric" CASCADE; CREATE TYPE "sla_metric" AS ENUM ('first_response', 'resolution'); DROP TYPE IF EXISTS "sla_notification_type" CASCADE; CREATE TYPE "sla_notification_type" AS ENUM ('warning', 'breach'); -DROP TYPE IF EXISTS "activity_log_type" CASCADE; CREATE TYPE "activity_log_type" AS ENUM ('login', 'logout', 'away', 'away_reassigned', 'online'); +DROP TYPE IF EXISTS "activity_log_type" CASCADE; CREATE TYPE "activity_log_type" AS ENUM ('agent_login', 'agent_logout', 'agent_away', 'agent_away_reassigned', 'agent_online'); -- Sequence to generate reference number for conversations. DROP SEQUENCE IF EXISTS conversation_reference_number_sequence; CREATE SEQUENCE conversation_reference_number_sequence START 100; @@ -546,6 +546,7 @@ CREATE TABLE activity_logs ( ); CREATE INDEX IF NOT EXISTS index_activity_logs_on_actor_id ON activity_logs (actor_id); CREATE INDEX IF NOT EXISTS index_activity_logs_on_activity_type ON activity_logs (activity_type); +CREATE INDEX IF NOT EXISTS index_activity_logs_on_created_at ON activity_logs (created_at); INSERT INTO ai_providers ("name", provider, config, is_default)