From 6fb964852fa8807485d87817b93919742fff5ef9 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Fri, 13 Mar 2026 18:31:43 +0000 Subject: [PATCH] Allow sudo to send structured SSEs --- html/template/sync/sudo.html | 28 ++++++++++++++++++++++++---- platform/event.go | 10 ++++++---- platform/event/event.go | 19 +++++++++++++++++++ sync/sudo.go | 6 ++++-- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/html/template/sync/sudo.html b/html/template/sync/sudo.html index 1a605d83..3b765268 100644 --- a/html/template/sync/sudo.html +++ b/html/template/sync/sudo.html @@ -218,16 +218,36 @@ value="{{ .Organization.ID }}" /> +
+ + +
- + +
+
+ +
diff --git a/platform/event.go b/platform/event.go index 715085d6..f7b84056 100644 --- a/platform/event.go +++ b/platform/event.go @@ -3,6 +3,7 @@ package platform import ( "time" + "github.com/Gleipnir-Technology/nidus-sync/config" "github.com/Gleipnir-Technology/nidus-sync/platform/event" ) @@ -14,13 +15,14 @@ const EventTypeHeartbeat = event.EventTypeHeartbeat func SetEventChannel(chan_events chan<- Envelope) { event.SetEventChannel(chan_events) } -func SudoEvent(org_id int32, content string) { +func SudoEvent(org_id int32, resource, type_, uri_path string) { + event_type := event.EventTypeFromString(type_) go event.Send(event.Envelope{ Event: Event{ - Resource: "sudo", + Resource: resource, Time: time.Now(), - Type: event.EventTypeSudo, - URI: content, + Type: event_type, + URI: config.MakeURLNidus(uri_path), }, OrganizationID: org_id, }) diff --git a/platform/event/event.go b/platform/event/event.go index e3e0c436..66f27915 100644 --- a/platform/event/event.go +++ b/platform/event/event.go @@ -30,6 +30,7 @@ const ( EventTypeDeleted EventTypeHeartbeat EventTypeSudo + EventTypeUnknown EventTypeUpdated ) @@ -43,11 +44,29 @@ func (et EventType) String() string { return "heartbeat" case EventTypeSudo: return "sudo" + case EventTypeUnknown: + return "unknown" case EventTypeUpdated: return "updated" } return "unknown" } +func EventTypeFromString(s string) EventType { + switch s { + case "created": + return EventTypeCreated + case "deleted": + return EventTypeDeleted + case "heartbeat": + return EventTypeHeartbeat + case "sudo": + return EventTypeSudo + case "updated": + return EventTypeUpdated + default: + return EventTypeUnknown + } +} type ResourceType int diff --git a/sync/sudo.go b/sync/sudo.go index 180dc0bc..1b9f2190 100644 --- a/sync/sudo.go +++ b/sync/sudo.go @@ -86,8 +86,10 @@ func postSudoSMS(ctx context.Context, r *http.Request, u platform.User, sms Form } type FormSSE struct { - Content string `schema:"content"` OrganizationID int32 `schema:"organizationID"` + Resource string `schema:"resource"` + Type string `schema:"type"` + URIPath string `schema:"uriPath"` } func postSudoSSE(ctx context.Context, r *http.Request, u platform.User, sse FormSSE) (string, *nhttp.ErrorWithStatus) { @@ -97,6 +99,6 @@ func postSudoSSE(ctx context.Context, r *http.Request, u platform.User, sse Form Status: http.StatusForbidden, } } - platform.SudoEvent(sse.OrganizationID, sse.Content) + platform.SudoEvent(sse.OrganizationID, sse.Resource, sse.Type, sse.URIPath) return "/sudo", nil }