Skip to content
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

fix: target frameworks filtered to the supported ones only when applying a mapping #1523

Merged
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: 2 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,8 @@ class ComplianceAssessment(Assessment):
)
show_documentation_score = models.BooleanField(default=False)

fields_to_check = ["name", "version"]

class Meta:
verbose_name = _("Compliance assessment")
verbose_name_plural = _("Compliance assessments")
Expand Down
26 changes: 25 additions & 1 deletion backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3113,13 +3113,37 @@ def get_composer_data(request):
# Compliance Assessment


class FrameworkFilter(df.FilterSet):
baseline = df.ModelChoiceFilter(
queryset=ComplianceAssessment.objects.all(),
method="filter_framework",
label="Baseline",
)

def filter_framework(self, queryset, name, value):
if not value:
return queryset
source_framework = value.framework
target_framework_ids = list(
RequirementMappingSet.objects.filter(
source_framework=source_framework
).values_list("target_framework__id", flat=True)
)
target_framework_ids.append(source_framework.id)
return queryset.filter(id__in=target_framework_ids)

class Meta:
model = Framework
fields = ["folder", "baseline"]


class FrameworkViewSet(BaseModelViewSet):
"""
API endpoint that allows frameworks to be viewed or edited.
"""

model = Framework
filterset_fields = ["folder"]
filterset_class = FrameworkFilter
search_fields = ["name", "description"]
ordering_fields = ["name", "description"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
{form}
disabled={object.id}
optionsEndpoint="frameworks"
optionsDetailedUrlParameters={[['baseline', initialData.baseline]]}
field="framework"
cacheLock={cacheLocks['framework']}
bind:cachedValue={formDataCache['framework']}
Expand Down
Loading