-
Notifications
You must be signed in to change notification settings - Fork 583
fix: add domain to teams or entities on actors #3233
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughAutocompleteSelect now omits assembling extra label parts for objects with type "user"; for other types it builds and filters extraParts from Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Autocomplete as AutocompleteSelect
participant API as Backend API (ActorRead)
participant DB as Database/Model
Client->>Autocomplete: open dropdown / type query
Autocomplete->>API: GET /actors?fields=...&extra_fields=folder
API->>DB: fetch Actor(s) including specific and folder
DB-->>API: Actor record(s) with specific.folder
API-->>Autocomplete: serialized Actor objects (id,str,type,specific,folder)
Autocomplete->>Autocomplete: for each obj: if obj.type == "user" skip extraParts else build extraParts from optionsExtraFields and filter falsy
Autocomplete-->>Client: render option labels (joined parts)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@frontend/src/lib/components/Forms/AutocompleteSelect.svelte`:
- Around line 226-234: The extraParts construction can throw if getNestedValue
returns null because it checks only !== undefined and then calls toString();
update the conditional to guard against nullish values (use a nullish check such
as value != null or value !== null && value !== undefined) before calling
toString(), or coerce with the nullish coalescing operator so the map in
AutocompleteSelect.svelte (referencing extraParts, getNestedValue,
optionsExtraFields, and object.type) only calls toString() on non-null values
and filters out empty results.
| const extraParts = | ||
| object.type === 'user' | ||
| ? [] | ||
| : optionsExtraFields | ||
| .map((fieldPath) => { | ||
| const value = getNestedValue(object, fieldPath[0], fieldPath[1]); | ||
| return value !== undefined ? value.toString() : ''; | ||
| }) | ||
| .filter(Boolean); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential runtime error when nested value is null.
The condition value !== undefined passes when value is null, causing null.toString() to throw a TypeError. Consider using a nullish check instead.
🐛 Proposed fix
const extraParts =
object.type === 'user'
? []
: optionsExtraFields
.map((fieldPath) => {
const value = getNestedValue(object, fieldPath[0], fieldPath[1]);
- return value !== undefined ? value.toString() : '';
+ return value != null ? value.toString() : '';
})
.filter(Boolean);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const extraParts = | |
| object.type === 'user' | |
| ? [] | |
| : optionsExtraFields | |
| .map((fieldPath) => { | |
| const value = getNestedValue(object, fieldPath[0], fieldPath[1]); | |
| return value !== undefined ? value.toString() : ''; | |
| }) | |
| .filter(Boolean); | |
| const extraParts = | |
| object.type === 'user' | |
| ? [] | |
| : optionsExtraFields | |
| .map((fieldPath) => { | |
| const value = getNestedValue(object, fieldPath[0], fieldPath[1]); | |
| return value != null ? value.toString() : ''; | |
| }) | |
| .filter(Boolean); |
🤖 Prompt for AI Agents
In `@frontend/src/lib/components/Forms/AutocompleteSelect.svelte` around lines 226
- 234, The extraParts construction can throw if getNestedValue returns null
because it checks only !== undefined and then calls toString(); update the
conditional to guard against nullish values (use a nullish check such as value
!= null or value !== null && value !== undefined) before calling toString(), or
coerce with the nullish coalescing operator so the map in
AutocompleteSelect.svelte (referencing extraParts, getNestedValue,
optionsExtraFields, and object.type) only calls toString() on non-null values
and filters out empty results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (5)
frontend/src/lib/components/Forms/ModelForm/FindingForm.svelte (1)
114-123: Remove invalidfolderextra field from actors endpointThe Actor model and endpoint do not expose a
folderfield. The ActorReadSerializer only returnsid,str,type, andspecific. RemoveoptionsExtraFields={[['folder', 'str']]}or replace it with a valid field if context is needed for the label.frontend/src/lib/components/Forms/ModelForm/ComplianceAssessmentForm.svelte (1)
269-278: Update actor optionsExtraFields to match actual domain modelThe actor endpoint does not expose a
folderfield directly. TheActormodel relates toUser,Team, orEntityvia OneToOneFields, and those related objects have thefolderfield throughFolderMixin. However, the folder field is not available on the serialized actor response (which includesid,str,type,specific), sooptionsExtraFields={[['folder', 'str']]}will not work and the field will not display.Unlike the
evidencesendpoint above, which usesEvidencemodel with directFolderMixininheritance, the actor model requires a different approach. Remove this extra field configuration or restructure if folder information from the related object is necessary.frontend/src/lib/components/Forms/ModelForm/MetricInstanceForm.svelte (1)
84-93: FixoptionsExtraFieldsfor actors endpoint—folder field not exposedThe
folderfield is not exposed in theActorReadSerializer(which only includes["id", "str", "type", "specific"]). The component attempts to accessobject['folder']['str']but this will fail since the actors endpoint response does not include thefolderfield. Either addfoldertoActorReadSerializerfields, or use an alternative field that is exposed in the serializer response (such as accessing folder through thespecificobject if it's a Team or Entity).frontend/src/lib/components/Forms/ModelForm/ContractForm.svelte (1)
128-139: Remove invalidfolderfield from actor options configurationThe
optionsExtraFields={[['folder', 'str']]}configuration references a field that doesn't exist on the Actor model. Actor has no directfolderproperty—only its underlying types (Team, User, Entity) may have folder relationships that aren't exposed through the Actor API serialization. This configuration will fail silently or return undefined values.This pattern is used consistently across 23+ form files with the actors endpoint. Remove the
optionsExtraFieldsprop or identify the correct field to expose (if additional context is needed).frontend/src/lib/components/Forms/ModelForm/FindingsAssessmentForm.svelte (1)
77-91: RemoveoptionsExtraFields={[['folder', 'str']]}from the actors autocomplete—the field doesn't exist.The Actor model has no
folderfield (only User, Team, and Entity are linked to Actor), andActorReadSerializerexposes only["id", "str", "type", "specific"]. Requestingfolderas an extra field will result in undefined values that get filtered out, leaving no metadata to display.
|
we lost the serialized folder that we need to bring back |
adding:
optionsExtraFields={[['folder', 'str']]}where relevant but adjusting the component to skip it for User
Summary by CodeRabbit
Bug Fixes
New Features
✏️ Tip: You can customize this high-level summary in your review settings.