forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: change historical and engagement exclusions #746
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
Open
iralgarc
wants to merge
4
commits into
trunk
Choose a base branch
from
feature/findingexclusions-status-historical
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+432
−35
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
43 changes: 43 additions & 0 deletions
43
dojo/db_migrations/0269_findingexclusion_engagements_and_more.py
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,43 @@ | ||
| # Generated by Django 5.1.14 on 2025-12-08 22:40 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('dojo', '0267_risk_acceptance_long_term_acceptance'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='findingexclusion', | ||
| name='engagements', | ||
| field=models.ManyToManyField(blank=True, to='dojo.engagement'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='findingexclusion', | ||
| name='product', | ||
| field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='dojo.product'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='findingexclusion', | ||
| name='product_type', | ||
| field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='dojo.product_type'), | ||
| ), | ||
| migrations.CreateModel( | ||
| name='FindingExclusionLog', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('previous_status', models.CharField(blank=True, choices=[('Accepted', 'Accepted'), ('Pending', 'Pending'), ('Reviewed', 'Reviewed'), ('Rejected', 'Rejected'), ('Expired', 'Expired')], default='Pending', max_length=8)), | ||
| ('current_status', models.CharField(blank=True, choices=[('Accepted', 'Accepted'), ('Pending', 'Pending'), ('Reviewed', 'Reviewed'), ('Rejected', 'Rejected'), ('Expired', 'Expired')], default='Pending', max_length=8)), | ||
| ('changed_at', models.DateTimeField(auto_now_add=True)), | ||
| ('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dojo.dojo_user')), | ||
| ('finding_exclusion', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='logs', to='dojo.findingexclusion')), | ||
| ], | ||
| options={ | ||
| 'db_table': 'dojo_finding_exclusion_log', | ||
| }, | ||
| ), | ||
| ] |
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 |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| from django import forms | ||
| from dojo.templatetags.authorization_tags import is_in_reviewer_group | ||
| from dojo.engine_tools.models import FindingExclusion, FindingExclusionDiscussion | ||
| from dojo.models import Product, Product_Type, Engagement | ||
| from dojo.engine_tools.helpers import Constants | ||
|
|
||
|
|
||
|
|
@@ -19,16 +21,74 @@ class CreateFindingExclusionForm(forms.ModelForm): | |
| label="Practice Origin Exclusion", | ||
| help_text="practice where exclusion originates",) | ||
|
|
||
| scope = forms.ChoiceField( | ||
| choices=[('all', 'All Engagements'), ('specific', 'Specific Engagements')], | ||
| widget=forms.RadioSelect, | ||
| initial='all', | ||
| label="Scope" | ||
| ) | ||
|
|
||
| product_type = forms.ModelChoiceField( | ||
| queryset=Product_Type.objects.all().order_by('name'), | ||
| required=False, | ||
| label="Product Type" | ||
| ) | ||
|
|
||
| product = forms.ModelChoiceField( | ||
| queryset=Product.objects.none(), | ||
| required=False, | ||
| label="Product" | ||
| ) | ||
|
|
||
| engagements = forms.ModelMultipleChoiceField( | ||
| queryset=Engagement.objects.none(), | ||
| required=False, | ||
| label="Engagements" | ||
| ) | ||
|
|
||
| class Meta: | ||
| model = FindingExclusion | ||
| fields = ["type", "unique_id_from_tool", "reason", "practice"] | ||
| fields = ["type", "unique_id_from_tool", "reason", "practice", "scope", "product_type", "product", "engagements"] | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| def __init__(self, user, *args, **kwargs): | ||
| self.user = user | ||
| super().__init__(*args, **kwargs) | ||
|
|
||
| if self.initial.get("practice"): | ||
| self.fields.pop("practice") | ||
|
|
||
| if 'product_type' in self.data: | ||
| try: | ||
| product_type_id = int(self.data.get('product_type')) | ||
| self.fields['product'].queryset = Product.objects.filter(prod_type_id=product_type_id).order_by('name') | ||
| except (ValueError, TypeError): | ||
| pass | ||
| elif self.instance.pk and self.instance.product_type: | ||
| self.fields['product'].queryset = self.instance.product_type.product_set.order_by('name') | ||
|
|
||
| if 'product' in self.data: | ||
| try: | ||
| product_id = int(self.data.get('product')) | ||
| self.fields['engagements'].queryset = Engagement.objects.filter(product_id=product_id).order_by('name') | ||
| except (ValueError, TypeError): | ||
| pass | ||
| elif self.instance.pk and self.instance.product: | ||
| self.fields['engagements'].queryset = self.instance.product.engagement_set.order_by('name') | ||
|
|
||
| def clean(self): | ||
| cleaned_data = super().clean() | ||
| scope = cleaned_data.get("scope") | ||
|
|
||
| if scope == 'specific': | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enable scope only when the user is_in_reviewer_group |
||
| if not is_in_reviewer_group(self.user): | ||
| raise forms.ValidationError("You do not have permission to create a specific engagement exclusion.") | ||
| if not cleaned_data.get("product_type"): | ||
| self.add_error('product_type', "This field is required when 'Specific Engagements' is selected.") | ||
| if not cleaned_data.get("product"): | ||
| self.add_error('product', "This field is required when 'Specific Engagements' is selected.") | ||
|
|
||
| return cleaned_data | ||
|
|
||
|
|
||
| class EditFindingExclusionForm(forms.ModelForm): | ||
|
|
||
|
|
||
iralgarc marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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.
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.
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.
please review if data is limited 25 rows