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
2 changes: 1 addition & 1 deletion backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4887,7 +4887,7 @@ class Meta:
# risk_matrix = self.risk_assessment.risk_matrix.parse_json()
# return [(k, v) for k, v in risk_matrix.fields[field].items()]

def get_folder_full_path(self, include_root: bool = False) -> list[Folder]:
def get_folder_full_path(self, *, include_root: bool = False) -> list[Folder]:
return self.risk_assessment.get_folder_full_path(include_root=include_root)

@property
Expand Down
4 changes: 2 additions & 2 deletions backend/iam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def get_parent_folders(self) -> Generator[Self, None, None]:
while (current_folder := current_folder.parent_folder) is not None:
yield current_folder

def get_folder_full_path(self, include_root: bool = False) -> list[Self]:
def get_folder_full_path(self, *, include_root: bool = False) -> list[Self]:
"""
Get the full path of the folder including its parents.
If include_root is True, the root folder is included in the path.
Expand Down Expand Up @@ -328,7 +328,7 @@ class FolderMixin(models.Model):
default=Folder.get_root_folder_id,
)

def get_folder_full_path(self, include_root: bool = False) -> list[Folder]:
def get_folder_full_path(self, *, include_root: bool = False) -> list[Folder]:
folders = ([self.folder] + [f for f in self.folder.get_parent_folders()])[::-1]
if include_root:
return folders
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lib/components/Forms/ModelForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
taintedMessage?: string | boolean;
model: ModelInfo;
context?: string;
origin?: string | null;
caching?: boolean;
closeModal?: boolean;
parent?: any;
Expand All @@ -113,6 +114,7 @@
taintedMessage = m.taintedFormMessage(),
model,
context = 'default',
origin = null,
caching = false,
closeModal = false,
parent = {},
Expand Down Expand Up @@ -374,6 +376,7 @@
{cacheLocks}
{formDataCache}
{schema}
{origin}
{initialData}
{context}
{...rest}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
cacheLocks?: Record<string, CacheLock>;
formDataCache?: Record<string, any>;
schema?: any;
origin?: string | null;
initialData?: Record<string, any>;
context?: string;
rest?: Record<string, any>;
Expand All @@ -37,6 +38,7 @@
cacheLocks = {},
formDataCache = $bindable({}),
schema = {},
origin = null,
initialData = {},
context = 'default'
}: Props = $props();
Expand Down Expand Up @@ -438,10 +440,12 @@
<AutocompleteSelect
{form}
optionsEndpoint="folders?content_type=DO&content_type=GL"
optionsDetailedUrlParameters={origin === 'requirement-assessments'
? [['scope_folder_id', initialData.folder]]
: []}
Comment on lines +443 to +445
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 | 🔴 Critical

Guard against undefined initialData.folder to prevent invalid query parameters.

When origin === 'requirement-assessments' but initialData.folder is undefined, the URL parameter becomes scope_folder_id=undefined, which produces an invalid API request.

Apply this diff to add a guard condition:

-	optionsDetailedUrlParameters={origin === 'requirement-assessments'
-		? [['scope_folder_id', initialData.folder]]
-		: []}
+	optionsDetailedUrlParameters={origin === 'requirement-assessments' && initialData.folder
+		? [['scope_folder_id', initialData.folder]]
+		: []}
📝 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
optionsDetailedUrlParameters={origin === 'requirement-assessments'
? [['scope_folder_id', initialData.folder]]
: []}
optionsDetailedUrlParameters={origin === 'requirement-assessments' && initialData.folder
? [['scope_folder_id', initialData.folder]]
: []}
🤖 Prompt for AI Agents
In frontend/src/lib/components/Forms/ModelForm/AppliedControlPolicyForm.svelte
around lines 443 to 445, the ternary builds optionsDetailedUrlParameters without
guarding initialData.folder so when origin === 'requirement-assessments' and
initialData.folder is undefined you end up sending scope_folder_id=undefined;
change the condition to require both origin === 'requirement-assessments' AND
initialData.folder !== undefined (or truthy) before returning the array,
otherwise return an empty array; ensure you use the actual folder value only
when present to avoid creating an invalid query parameter.

field="folder"
pathField="path"
cacheLock={cacheLocks['folder']}
bind:cachedValue={formDataCache['folder']}
label={m.domain()}
hidden={initialData.folder}
/>
3 changes: 3 additions & 0 deletions frontend/src/lib/components/Modals/CreateModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
invalidateAll?: boolean; // set to false to keep form data using muliple forms on a page
formAction?: string;
context?: string;
origin?: string | null;
additionalInitialData?: any;
suggestions?: { [key: string]: any };
taintedMessage?: string | boolean;
Expand All @@ -43,6 +44,7 @@
invalidateAll = true,
formAction = '?/create',
context = 'create',
origin = null,
additionalInitialData = {},
suggestions = {},
taintedMessage = false,
Expand Down Expand Up @@ -87,6 +89,7 @@
{model}
{closeModal}
{context}
{origin}
{duplicate}
{taintedMessage}
caching={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
model: data.measureModel,
debug: false,
invalidateAll: false,
origin: 'requirement-assessments',
suggestions: { reference_control: reference_controls }
}
};
Expand Down
Loading