diff --git a/service/controllers/pco_webhook.go b/service/controllers/pco_webhook.go index ae982fe..b6cfc27 100644 --- a/service/controllers/pco_webhook.go +++ b/service/controllers/pco_webhook.go @@ -226,10 +226,11 @@ func ScheduleBroadcastFromWebhook(c *gin.Context, body *webhooks.EventDelivery) //Save audit point eventRecievedAudit := &models.EventRecieved{ - UserId: *uid, - VendorName: models.PCO_VENDOR_NAME, - VendorId: body.ID, - Type: body.Name, + UserId: *uid, + VendorName: models.PCO_VENDOR_NAME, + VendorId: body.ID, + CorrelationId: payload.Id, + Type: body.Name, } if err := mongo.SaveModel(eventRecievedAudit); err != nil { @@ -274,6 +275,7 @@ func ScheduleBroadcastFromWebhook(c *gin.Context, body *webhooks.EventDelivery) UserId: *uid, TriggeringEvent: eventRecievedAudit.MongoId(), Result: result, + CorrelationId: payload.Id, VendorName: models.YOUTUBE_VENDOR_NAME, } diff --git a/ui/controllers/components.go b/ui/controllers/components.go index 72dcd60..0d01147 100644 --- a/ui/controllers/components.go +++ b/ui/controllers/components.go @@ -1,6 +1,8 @@ package controllers import ( + "fmt" + "git.preston-baxter.com/Preston_PLB/capstone/frontend-service/templates" "github.com/gin-gonic/gin" "golang.org/x/text/language" @@ -90,12 +92,15 @@ func eventsRecievedMetricFunction(c *gin.Context) *DashboardMetric { } p := message.NewPrinter(language.English) - return &DashboardMetric{ - Title: "Events Recieved", - PrimaryValue: p.Sprintf("%d", totalEvents), - SecondaryValue: "", - Subtitle: p.Sprintf("Most events came from: %s", events[biggestVendor].Name), + metric := &DashboardMetric{ + Title: "Events Recieved", + PrimaryValue: p.Sprintf("%d", totalEvents), } + if len(events) > 0 { + metric.Subtitle = fmt.Sprintf("Most events from: %s", events[biggestVendor].Name) + } + + return metric } func streamsScheduledMetricFunction(c *gin.Context) *DashboardMetric { diff --git a/ui/controllers/controllers.go b/ui/controllers/controllers.go index bae1c7c..ebd1163 100644 --- a/ui/controllers/controllers.go +++ b/ui/controllers/controllers.go @@ -28,7 +28,7 @@ func BuildRouter(r *gin.Engine) { r.Use(cors.Default()) - r.Static("/static", "./dist") + r.Static("/static", "/var/capstone/dist") //mainpage r.GET("/", AuthMiddleware(false), LandingPage) diff --git a/ui/controllers/event_components.go b/ui/controllers/event_components.go index 8fde41f..157d384 100644 --- a/ui/controllers/event_components.go +++ b/ui/controllers/event_components.go @@ -60,7 +60,7 @@ func eventsForUserTableData(c *gin.Context) templates.TableData { table := make([][]string, len(events)+1) index := 1 for _, event := range events { - arr := []string{event.CreatedAt.Format(time.Stamp), strings.ToUpper(event.VendorName), event.VendorId, event.Type} + arr := []string{event.CreatedAt.Format(time.Stamp), strings.ToUpper(event.VendorName), event.CorrelationId, event.Type} if filter_exists { //if the filter exists loop through the row. Check if anything meets the filter @@ -77,8 +77,8 @@ func eventsForUserTableData(c *gin.Context) templates.TableData { //We either had no filter or passed the filter check. Add to the pool table[index] = arr index += 1 - table[0] = []string{"Timestamp", "Vendor", "Id", "Event Type"} } + table[0] = []string{"Timestamp", "Vendor", "Id", "Event Type"} return table[0:index] } @@ -99,7 +99,7 @@ func actionsForUserTableData(c *gin.Context) templates.TableData { index := 1 table := make([][]string, len(actions)+1) for _, action := range actions { - arr := []string{action.CreatedAt.Format(time.RFC1123), action.VendorName, action.CorrelationId, action.Result} + arr := []string{action.CreatedAt.Format(time.Stamp), action.VendorName, action.CorrelationId, action.Result} if filter_exists { //if the filter exists loop through the row. Check if anything meets the filter pass := false @@ -112,7 +112,7 @@ func actionsForUserTableData(c *gin.Context) templates.TableData { continue } } - table[index] = []string{action.CreatedAt.Format(time.RFC1123), action.VendorName, action.CorrelationId, action.Result} + table[index] = arr index += 1 } table[0] = []string{"Timestamp", "Vendor", "Id", "Result"} diff --git a/ui/db/models/audit.go b/ui/db/models/audit.go index e27f24c..5352468 100644 --- a/ui/db/models/audit.go +++ b/ui/db/models/audit.go @@ -18,6 +18,7 @@ type EventRecieved struct { UserId primitive.ObjectID `bson:"user_id,omitempty"` //what user is this associated too VendorName string `bson:"vendor_name,omitempty"` //Vendor name of who sent us the event VendorId string `bson:"vendor_id,omitempty"` + CorrelationId string `bson:"correlation_id,omitempty"` //list of entities effected or created from action Type string `bson:"type,omitempty"` //type of event } @@ -34,7 +35,7 @@ func (obj *EventRecieved) UpdateObjectInfo() { now := time.Now() if obj.CommonFields == nil { obj.CommonFields = new(CommonFields) - obj.EntityType = ACTION_TAKEN_TYPE + obj.EntityType = EVENT_RECIEVED_TYPE obj.CreatedAt = now } obj.UpdatedAt = now @@ -64,7 +65,7 @@ func (obj *ActionTaken) UpdateObjectInfo() { now := time.Now() if obj.CommonFields == nil { obj.CommonFields = new(CommonFields) - obj.EntityType = EVENT_RECIEVED_TYPE + obj.EntityType = ACTION_TAKEN_TYPE obj.CreatedAt = now } obj.UpdatedAt = now diff --git a/ui/db/token_source.go b/ui/db/token_source.go index c4b54aa..6843811 100644 --- a/ui/db/token_source.go +++ b/ui/db/token_source.go @@ -132,5 +132,21 @@ func (ts *VendorTokenSource) waitForToken(tl *models.TokenLock) error { } } + + //We waited to long check if its refreshed and carry on + res :=col.FindOne(context.Background(), bson.M{"token_id": tl.TokenId}) + if res.Err() != nil { + return errors.Join(TokenWaitExpired, res.Err()) + } + + err = res.Decode(tl) + if err != nil { + return errors.Join(TokenWaitExpired, res.Err()) + } + + if tl.Refreshed { + return nil + } + return TokenWaitExpired } diff --git a/ui/templates/dashboard_page.templ b/ui/templates/dashboard_page.templ index 2987cd3..f1f29ef 100644 --- a/ui/templates/dashboard_page.templ +++ b/ui/templates/dashboard_page.templ @@ -464,7 +464,7 @@ templ DashboardActionsWidget(actions []models.ActionMapping) { Event Source - Event Action + Action Destination Action @@ -488,10 +488,9 @@ templ DashboardActionsWidget(actions []models.ActionMapping) { { action.SourceEvent.Key } - { action.Action.VendorName }: { action.Action.Type } + { action.Action.VendorName } - - @DashboardActionEditButton(&action) + { action.Action.Type } } diff --git a/versions.json b/versions.json index 560d068..3b35ae8 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,4 @@ { - "webhook_version": "0.0.61", - "frontend_version": "0.0.42" + "webhook_version": "0.1.8", + "frontend_version": "0.1.8" }