-
Notifications
You must be signed in to change notification settings - Fork 2
[LFXV2-684] Add meeting RSVP data enricher #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+137
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| // Package enrichers provides data enrichment functionality for different object types. | ||
| package enrichers | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "regexp" | ||
| "strings" | ||
|
|
||
| "github.com/linuxfoundation/lfx-v2-indexer-service/internal/domain/contracts" | ||
| "github.com/linuxfoundation/lfx-v2-indexer-service/pkg/constants" | ||
| ) | ||
|
|
||
| // MeetingRSVPEnricher handles meeting-rsvp-specific enrichment logic | ||
| type MeetingRSVPEnricher struct { | ||
| defaultEnricher Enricher | ||
| } | ||
|
|
||
| // ObjectType returns the object type this enricher handles. | ||
| func (e *MeetingRSVPEnricher) ObjectType() string { | ||
| return e.defaultEnricher.ObjectType() | ||
| } | ||
|
|
||
| // EnrichData enriches meeting-rsvp-specific data | ||
| func (e *MeetingRSVPEnricher) EnrichData(body *contracts.TransactionBody, transaction *contracts.LFXTransaction) error { | ||
| return e.defaultEnricher.EnrichData(body, transaction) | ||
| } | ||
|
|
||
| // setAccessControl provides meeting-rsvp-specific access control logic | ||
| // RSVP objects inherit permissions from their parent meeting | ||
| func (e *MeetingRSVPEnricher) setAccessControl(body *contracts.TransactionBody, data map[string]any, objectType, objectID string) { | ||
| meetingLevelPermission := func(data map[string]any) string { | ||
| if value, ok := data["meeting_uid"]; ok { | ||
| if meetingUID, ok := value.(string); ok { | ||
| return fmt.Sprintf("%s:%s", constants.ObjectTypeMeeting, meetingUID) | ||
| } | ||
| } | ||
| return fmt.Sprintf("%s:%s", objectType, objectID) | ||
| } | ||
|
|
||
| // Build access control values | ||
| var accessObject, accessRelation string | ||
| var historyObject, historyRelation string | ||
|
|
||
| // Set access control with meeting-rsvp-specific logic | ||
| // Only apply defaults when fields are completely missing from data | ||
| if accessCheckObject, ok := data["accessCheckObject"].(string); ok { | ||
| // Field exists in data (even if empty) - use data value | ||
| accessObject = accessCheckObject | ||
| } else if _, exists := data["accessCheckObject"]; !exists { | ||
| // Field doesn't exist in data - use computed default with objectType prefix | ||
| accessObject = meetingLevelPermission(data) | ||
| } | ||
| // If field exists but is not a string, leave empty (no override) | ||
|
|
||
| if accessCheckRelation, ok := data["accessCheckRelation"].(string); ok { | ||
| accessRelation = accessCheckRelation | ||
| } else if _, exists := data["accessCheckRelation"]; !exists { | ||
| accessRelation = "auditor" | ||
| } | ||
|
|
||
| if historyCheckObject, ok := data["historyCheckObject"].(string); ok { | ||
| historyObject = historyCheckObject | ||
| } else if _, exists := data["historyCheckObject"]; !exists { | ||
| historyObject = meetingLevelPermission(data) | ||
| } | ||
|
|
||
| if historyCheckRelation, ok := data["historyCheckRelation"].(string); ok { | ||
| historyRelation = historyCheckRelation | ||
| } else if _, exists := data["historyCheckRelation"]; !exists { | ||
| historyRelation = "writer" | ||
| } | ||
|
|
||
| // Assign to body fields (deprecated fields) | ||
| body.AccessCheckObject = accessObject | ||
| body.AccessCheckRelation = accessRelation | ||
| body.HistoryCheckObject = historyObject | ||
| body.HistoryCheckRelation = historyRelation | ||
|
|
||
| // Build and assign the query strings | ||
| if accessObject != "" && accessRelation != "" { | ||
| body.AccessCheckQuery = contracts.JoinFgaQuery(accessObject, accessRelation) | ||
| } | ||
| if historyObject != "" && historyRelation != "" { | ||
| body.HistoryCheckQuery = contracts.JoinFgaQuery(historyObject, historyRelation) | ||
| } | ||
| } | ||
|
|
||
| // extractSortName extracts the sort name from the meeting RSVP data | ||
| func (e *MeetingRSVPEnricher) extractSortName(data map[string]any) string { | ||
| if value, ok := data["email"]; ok { | ||
| if strValue, isString := value.(string); isString && strValue != "" { | ||
| return strings.TrimSpace(strValue) | ||
| } | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // extractNameAndAliases extracts the name and aliases from the meeting RSVP data | ||
| func (e *MeetingRSVPEnricher) extractNameAndAliases(data map[string]any) []string { | ||
| var nameAndAliases []string | ||
| seen := make(map[string]bool) // Deduplicate names | ||
|
|
||
| // Compile regex pattern for name-like fields | ||
| aliasRegex := regexp.MustCompile(`(?i)^(username|email)$`) | ||
andrest50 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Collect all name-like fields using regex pattern | ||
| for key, value := range data { | ||
| if aliasRegex.MatchString(key) { | ||
| if strValue, ok := value.(string); ok && strValue != "" { | ||
| trimmed := strings.TrimSpace(strValue) | ||
| if trimmed != "" && !seen[trimmed] { | ||
| nameAndAliases = append(nameAndAliases, trimmed) | ||
| seen[trimmed] = true | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nameAndAliases | ||
| } | ||
|
|
||
| // NewMeetingRSVPEnricher creates a new meeting RSVP enricher | ||
| func NewMeetingRSVPEnricher() Enricher { | ||
| enricher := &MeetingRSVPEnricher{} | ||
| enricher.defaultEnricher = newDefaultEnricher( | ||
| constants.ObjectTypeMeetingRSVP, | ||
| WithAccessControl(enricher.setAccessControl), | ||
| WithNameAndAliases(enricher.extractNameAndAliases), | ||
| WithSortName(enricher.extractSortName), | ||
| ) | ||
| return enricher | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.