|
21 | 21 | from rest_framework import serializers |
22 | 22 | from rest_framework.exceptions import NotFound |
23 | 23 | from rest_framework.exceptions import ValidationError as RestFrameworkValidationError |
24 | | -from rest_framework.fields import DictField, MultipleChoiceField |
| 24 | +from rest_framework.fields import DictField |
25 | 25 |
|
26 | 26 | import dojo.finding.helper as finding_helper |
27 | 27 | import dojo.jira_link.helper as jira_helper |
|
42 | 42 | from dojo.importers.default_reimporter import DefaultReImporter |
43 | 43 | from dojo.location.models import Location, LocationFindingReference |
44 | 44 | from dojo.models import ( |
45 | | - DEFAULT_NOTIFICATION, |
46 | 45 | IMPORT_ACTIONS, |
47 | | - NOTIFICATION_CHOICES, |
48 | 46 | SEVERITIES, |
49 | 47 | SEVERITY_CHOICES, |
50 | 48 | STATS_FIELDS, |
|
84 | 82 | Note_Type, |
85 | 83 | NoteHistory, |
86 | 84 | Notes, |
87 | | - Notification_Webhooks, |
88 | | - Notifications, |
89 | 85 | Product, |
90 | 86 | Product_API_Scan_Configuration, |
91 | 87 | Product_Group, |
@@ -3138,110 +3134,7 @@ class FindingNoteSerializer(serializers.Serializer): |
3138 | 3134 | note_id = serializers.IntegerField() |
3139 | 3135 |
|
3140 | 3136 |
|
3141 | | -class NotificationsSerializer(serializers.ModelSerializer): |
3142 | | - product = serializers.PrimaryKeyRelatedField( |
3143 | | - queryset=Product.objects.all(), |
3144 | | - required=False, |
3145 | | - default=None, |
3146 | | - allow_null=True, |
3147 | | - ) |
3148 | | - user = serializers.PrimaryKeyRelatedField( |
3149 | | - queryset=Dojo_User.objects.all(), |
3150 | | - required=False, |
3151 | | - default=None, |
3152 | | - allow_null=True, |
3153 | | - ) |
3154 | | - product_type_added = MultipleChoiceField( |
3155 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3156 | | - ) |
3157 | | - product_added = MultipleChoiceField( |
3158 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3159 | | - ) |
3160 | | - engagement_added = MultipleChoiceField( |
3161 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3162 | | - ) |
3163 | | - test_added = MultipleChoiceField( |
3164 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3165 | | - ) |
3166 | | - scan_added = MultipleChoiceField( |
3167 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3168 | | - ) |
3169 | | - jira_update = MultipleChoiceField( |
3170 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3171 | | - ) |
3172 | | - upcoming_engagement = MultipleChoiceField( |
3173 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3174 | | - ) |
3175 | | - stale_engagement = MultipleChoiceField( |
3176 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3177 | | - ) |
3178 | | - auto_close_engagement = MultipleChoiceField( |
3179 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3180 | | - ) |
3181 | | - close_engagement = MultipleChoiceField( |
3182 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3183 | | - ) |
3184 | | - user_mentioned = MultipleChoiceField( |
3185 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3186 | | - ) |
3187 | | - code_review = MultipleChoiceField( |
3188 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3189 | | - ) |
3190 | | - review_requested = MultipleChoiceField( |
3191 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3192 | | - ) |
3193 | | - other = MultipleChoiceField( |
3194 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3195 | | - ) |
3196 | | - sla_breach = MultipleChoiceField( |
3197 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3198 | | - ) |
3199 | | - sla_breach_combined = MultipleChoiceField( |
3200 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3201 | | - ) |
3202 | | - risk_acceptance_expiration = MultipleChoiceField( |
3203 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3204 | | - ) |
3205 | | - template = serializers.BooleanField(default=False) |
3206 | | - |
3207 | | - class Meta: |
3208 | | - model = Notifications |
3209 | | - fields = "__all__" |
3210 | | - |
3211 | | - def validate(self, data): |
3212 | | - user = None |
3213 | | - product = None |
3214 | | - template = False |
3215 | | - |
3216 | | - if self.instance is not None: |
3217 | | - user = self.instance.user |
3218 | | - product = self.instance.product |
3219 | | - |
3220 | | - if "user" in data: |
3221 | | - user = data.get("user") |
3222 | | - if "product" in data: |
3223 | | - product = data.get("product") |
3224 | | - if "template" in data: |
3225 | | - template = data.get("template") |
3226 | | - |
3227 | | - if ( |
3228 | | - template |
3229 | | - and Notifications.objects.filter(template=True).count() > 0 |
3230 | | - ): |
3231 | | - msg = "Notification template already exists" |
3232 | | - raise ValidationError(msg) |
3233 | | - if ( |
3234 | | - self.instance is None |
3235 | | - or user != self.instance.user |
3236 | | - or product != self.instance.product |
3237 | | - ): |
3238 | | - notifications = Notifications.objects.filter( |
3239 | | - user=user, product=product, template=template, |
3240 | | - ).count() |
3241 | | - if notifications > 0: |
3242 | | - msg = "Notification for user and product already exists" |
3243 | | - raise ValidationError(msg) |
3244 | | - return data |
| 3137 | +from dojo.notifications.api.serializer import NotificationsSerializer # noqa: E402, F401 -- backward compat |
3245 | 3138 |
|
3246 | 3139 |
|
3247 | 3140 | class EngagementPresetsSerializer(serializers.ModelSerializer): |
@@ -3418,7 +3311,4 @@ def create(self, validated_data): |
3418 | 3311 | raise |
3419 | 3312 |
|
3420 | 3313 |
|
3421 | | -class NotificationWebhooksSerializer(serializers.ModelSerializer): |
3422 | | - class Meta: |
3423 | | - model = Notification_Webhooks |
3424 | | - fields = "__all__" |
| 3314 | +from dojo.notifications.api.serializer import NotificationWebhooksSerializer # noqa: E402, F401 -- backward compat |
0 commit comments