Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7837,6 +7837,11 @@ def specific(self):
return self.entity
raise ValueError("Actor has no underlying instance")

@property
def _folder(self):
"""Returns the folder of the underlying instance."""
return self.specific.folder

def get_emails(self) -> list[str]:
return self.specific.get_emails()

Expand Down
7 changes: 6 additions & 1 deletion backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,11 +1208,16 @@ class Meta:

class ActorReadSerializer(BaseModelSerializer):
specific = FieldsRelatedField()
folder = serializers.SerializerMethodField()
str = serializers.CharField(source="__str__")

class Meta:
model = Actor
fields = ["id", "str", "type", "specific"]
fields = ["id", "str", "type", "specific", "folder"]

def get_folder(self, obj):
folder = obj._folder
return {"id": folder.id, "str": str(folder)} if folder else None


class TeamWriteSerializer(BaseModelSerializer):
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/lib/components/Forms/AutocompleteSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,15 @@
? append(object.ref_id, object.name || object.description)
: getNestedValue(object, optionsLabelField);
const extraParts = optionsExtraFields.map((fieldPath) => {
const value = getNestedValue(object, fieldPath[0], fieldPath[1]);
return value !== undefined ? value.toString() : '';
});
const extraParts =
object.type === 'user'
? []
: optionsExtraFields
.map((fieldPath) => {
const value = getNestedValue(object, fieldPath[0], fieldPath[1]);
return value !== undefined ? value.toString() : '';
})
.filter(Boolean);
Comment on lines +226 to +234
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

const path: string[] =
pathField && object?.[pathField]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
multiple
optionsEndpoint="actors"
optionsLabelField="str"
optionsExtraFields={[['folder', 'str']]}
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
position: 'prefix'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand All @@ -90,6 +91,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down Expand Up @@ -269,6 +270,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
{form}
optionsEndpoint="entities"
field="provider_entity"
optionsExtraFields={[['folder', 'str']]}
cacheLock={cacheLocks['provider_entity']}
bind:cachedValue={formDataCache['provider_entity']}
label={m.providerEntity()}
Expand All @@ -88,6 +89,7 @@
{form}
optionsEndpoint="entities"
field="beneficiary_entity"
optionsExtraFields={[['folder', 'str']]}
cacheLock={cacheLocks['beneficiary_entity']}
bind:cachedValue={formDataCache['beneficiary_entity']}
label={m.beneficiaryEntity()}
Expand Down Expand Up @@ -130,6 +132,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
multiple
{form}
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand All @@ -164,6 +165,7 @@
multiple
{form}
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand All @@ -194,6 +195,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand All @@ -104,6 +105,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down Expand Up @@ -252,6 +253,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand All @@ -148,6 +149,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
{form}
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
label={m.entity()}
hidden={initialData.entity}
helpText={m.stakeholderEntityHelpText()}
optionsExtraFields={[['folder', 'str']]}
includeAllOptionFields={true}
optionsInfoFields={{
fields: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
baseClass="flex-1"
multiple
optionsEndpoint="actors"
optionsExtraFields={[['folder', 'str']]}
optionsLabelField="str"
optionsInfoFields={{
fields: [{ field: 'type', translate: true }],
Expand Down
Loading