|
| 1 | +// Copyright The Linux Foundation and each contributor to LFX. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +// Package enrichers provides data enrichment functionality for different object types. |
| 5 | +package enrichers |
| 6 | + |
| 7 | +import ( |
| 8 | + "fmt" |
| 9 | + |
| 10 | + "github.com/linuxfoundation/lfx-v2-indexer-service/internal/domain/contracts" |
| 11 | + "github.com/linuxfoundation/lfx-v2-indexer-service/pkg/constants" |
| 12 | +) |
| 13 | + |
| 14 | +// PastMeetingTranscriptEnricher handles past meeting transcript-specific enrichment logic |
| 15 | +type PastMeetingTranscriptEnricher struct { |
| 16 | + defaultEnricher Enricher |
| 17 | +} |
| 18 | + |
| 19 | +// ObjectType returns the object type this enricher handles. |
| 20 | +func (e *PastMeetingTranscriptEnricher) ObjectType() string { |
| 21 | + return e.defaultEnricher.ObjectType() |
| 22 | +} |
| 23 | + |
| 24 | +// EnrichData enriches past meeting transcript-specific data |
| 25 | +func (e *PastMeetingTranscriptEnricher) EnrichData(body *contracts.TransactionBody, transaction *contracts.LFXTransaction) error { |
| 26 | + return e.defaultEnricher.EnrichData(body, transaction) |
| 27 | +} |
| 28 | + |
| 29 | +// setAccessControl provides past meeting transcript-specific access control logic |
| 30 | +func (e *PastMeetingTranscriptEnricher) setAccessControl(body *contracts.TransactionBody, data map[string]any, objectType, objectID string) { |
| 31 | + pastMeetingTranscriptLevelPermission := func(data map[string]any) string { |
| 32 | + if value, ok := data["past_meeting_transcript_uid"]; ok { |
| 33 | + if pastMeetingTranscriptUID, ok := value.(string); ok { |
| 34 | + return fmt.Sprintf("%s:%s", constants.ObjectTypePastMeetingTranscript, pastMeetingTranscriptUID) |
| 35 | + } |
| 36 | + } |
| 37 | + return fmt.Sprintf("%s:%s", objectType, objectID) |
| 38 | + } |
| 39 | + |
| 40 | + // Build access control values |
| 41 | + var accessObject, accessRelation string |
| 42 | + var historyObject, historyRelation string |
| 43 | + |
| 44 | + // Set access control with past meeting transcript-specific logic |
| 45 | + // Only apply defaults when fields are completely missing from data |
| 46 | + if accessCheckObject, ok := data["accessCheckObject"].(string); ok { |
| 47 | + accessObject = accessCheckObject |
| 48 | + } else if _, exists := data["accessCheckObject"]; !exists { |
| 49 | + accessObject = pastMeetingTranscriptLevelPermission(data) |
| 50 | + } |
| 51 | + |
| 52 | + if accessCheckRelation, ok := data["accessCheckRelation"].(string); ok { |
| 53 | + accessRelation = accessCheckRelation |
| 54 | + } else if _, exists := data["accessCheckRelation"]; !exists { |
| 55 | + accessRelation = "viewer" |
| 56 | + } |
| 57 | + |
| 58 | + if historyCheckObject, ok := data["historyCheckObject"].(string); ok { |
| 59 | + historyObject = historyCheckObject |
| 60 | + } else if _, exists := data["historyCheckObject"]; !exists { |
| 61 | + historyObject = pastMeetingTranscriptLevelPermission(data) |
| 62 | + } |
| 63 | + |
| 64 | + if historyCheckRelation, ok := data["historyCheckRelation"].(string); ok { |
| 65 | + historyRelation = historyCheckRelation |
| 66 | + } else if _, exists := data["historyCheckRelation"]; !exists { |
| 67 | + historyRelation = "writer" |
| 68 | + } |
| 69 | + |
| 70 | + // Assign to body fields (deprecated fields) |
| 71 | + body.AccessCheckObject = accessObject |
| 72 | + body.AccessCheckRelation = accessRelation |
| 73 | + body.HistoryCheckObject = historyObject |
| 74 | + body.HistoryCheckRelation = historyRelation |
| 75 | + |
| 76 | + // Build and assign the query strings |
| 77 | + if accessObject != "" && accessRelation != "" { |
| 78 | + body.AccessCheckQuery = contracts.JoinFgaQuery(accessObject, accessRelation) |
| 79 | + } |
| 80 | + if historyObject != "" && historyRelation != "" { |
| 81 | + body.HistoryCheckQuery = contracts.JoinFgaQuery(historyObject, historyRelation) |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +// NewPastMeetingTranscriptEnricher creates a new past meeting transcript enricher |
| 86 | +func NewPastMeetingTranscriptEnricher() Enricher { |
| 87 | + enricher := &PastMeetingTranscriptEnricher{} |
| 88 | + enricher.defaultEnricher = newDefaultEnricher( |
| 89 | + constants.ObjectTypePastMeetingTranscript, |
| 90 | + WithAccessControl(enricher.setAccessControl), |
| 91 | + ) |
| 92 | + return enricher |
| 93 | +} |
0 commit comments