@@ -355,6 +355,71 @@ func (h *OrgHandler) GetOrganization(c echo.Context) error {
355355 })
356356}
357357
358+ // GetMyOrganizations handles GET /internal/orgs/user
359+ // Returns organizations for the current user (no org context required)
360+ // Requires: X-User-ID and X-Email headers with webhook secret authentication
361+ func (h * OrgHandler ) GetMyOrganizations (c echo.Context ) error {
362+ ctx := c .Request ().Context ()
363+
364+ // Get user context from webhook middleware
365+ userID := c .Get ("user_id" )
366+ if userID == nil {
367+ return c .JSON (http .StatusBadRequest , map [string ]string {
368+ "error" : "user context required" ,
369+ })
370+ }
371+
372+ userIDStr , ok := userID .(string )
373+ if ! ok || userIDStr == "" {
374+ return c .JSON (http .StatusInternalServerError , map [string ]string {
375+ "error" : "invalid user context" ,
376+ })
377+ }
378+
379+ // Get all organizations
380+ allOrgs , err := h .orgRepo .List (ctx )
381+ if err != nil {
382+ slog .Error ("Failed to list organizations for user" , "userID" , userIDStr , "error" , err )
383+ return c .JSON (http .StatusInternalServerError , map [string ]string {
384+ "error" : "failed to list organizations" ,
385+ })
386+ }
387+
388+ // Filter to orgs where user has roles (if RBAC is enabled)
389+ var userOrgs []* domain.Organization
390+ if h .rbacManager != nil {
391+ for _ , org := range allOrgs {
392+ // Check if user has any roles in this org
393+ orgCtx := domain .ContextWithOrg (ctx , org .ID )
394+ hasAccess , _ := h .rbacManager .IsEnabled (orgCtx )
395+ if hasAccess {
396+ userOrgs = append (userOrgs , org )
397+ }
398+ }
399+ } else {
400+ // No RBAC - return all orgs
401+ userOrgs = allOrgs
402+ }
403+
404+ // Convert to response format
405+ response := make ([]CreateOrgResponse , len (userOrgs ))
406+ for i , org := range userOrgs {
407+ response [i ] = CreateOrgResponse {
408+ ID : org .ID ,
409+ Name : org .Name ,
410+ DisplayName : org .DisplayName ,
411+ ExternalOrgID : org .ExternalOrgID ,
412+ CreatedBy : org .CreatedBy ,
413+ CreatedAt : org .CreatedAt .Format ("2006-01-02T15:04:05Z07:00" ),
414+ }
415+ }
416+
417+ return c .JSON (http .StatusOK , map [string ]interface {}{
418+ "organizations" : response ,
419+ "count" : len (response ),
420+ })
421+ }
422+
358423// ListOrganizations handles GET /internal/orgs
359424func (h * OrgHandler ) ListOrganizations (c echo.Context ) error {
360425 ctx := c .Request ().Context ()
0 commit comments