|
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.risk_acceptance.helper as ra_helper |
|
52 | 52 | from dojo.jira import services as jira_services |
53 | 53 | from dojo.location.models import Location, LocationFindingReference |
54 | 54 | from dojo.models import ( |
55 | | - DEFAULT_NOTIFICATION, |
56 | 55 | IMPORT_ACTIONS, |
57 | | - NOTIFICATION_CHOICES, |
58 | 56 | SEVERITIES, |
59 | 57 | SEVERITY_CHOICES, |
60 | 58 | STATS_FIELDS, |
|
89 | 87 | Note_Type, |
90 | 88 | NoteHistory, |
91 | 89 | Notes, |
92 | | - Notification_Webhooks, |
93 | | - Notifications, |
94 | 90 | Product, |
95 | 91 | Product_API_Scan_Configuration, |
96 | 92 | Product_Type, |
@@ -3071,110 +3067,7 @@ class FindingNoteSerializer(serializers.Serializer): |
3071 | 3067 | note_id = serializers.IntegerField() |
3072 | 3068 |
|
3073 | 3069 |
|
3074 | | -class NotificationsSerializer(serializers.ModelSerializer): |
3075 | | - product = serializers.PrimaryKeyRelatedField( |
3076 | | - queryset=Product.objects.all(), |
3077 | | - required=False, |
3078 | | - default=None, |
3079 | | - allow_null=True, |
3080 | | - ) |
3081 | | - user = serializers.PrimaryKeyRelatedField( |
3082 | | - queryset=Dojo_User.objects.all(), |
3083 | | - required=False, |
3084 | | - default=None, |
3085 | | - allow_null=True, |
3086 | | - ) |
3087 | | - product_type_added = MultipleChoiceField( |
3088 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3089 | | - ) |
3090 | | - product_added = MultipleChoiceField( |
3091 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3092 | | - ) |
3093 | | - engagement_added = MultipleChoiceField( |
3094 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3095 | | - ) |
3096 | | - test_added = MultipleChoiceField( |
3097 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3098 | | - ) |
3099 | | - scan_added = MultipleChoiceField( |
3100 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3101 | | - ) |
3102 | | - jira_update = MultipleChoiceField( |
3103 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3104 | | - ) |
3105 | | - upcoming_engagement = MultipleChoiceField( |
3106 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3107 | | - ) |
3108 | | - stale_engagement = MultipleChoiceField( |
3109 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3110 | | - ) |
3111 | | - auto_close_engagement = MultipleChoiceField( |
3112 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3113 | | - ) |
3114 | | - close_engagement = MultipleChoiceField( |
3115 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3116 | | - ) |
3117 | | - user_mentioned = MultipleChoiceField( |
3118 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3119 | | - ) |
3120 | | - code_review = MultipleChoiceField( |
3121 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3122 | | - ) |
3123 | | - review_requested = MultipleChoiceField( |
3124 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3125 | | - ) |
3126 | | - other = MultipleChoiceField( |
3127 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3128 | | - ) |
3129 | | - sla_breach = MultipleChoiceField( |
3130 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3131 | | - ) |
3132 | | - sla_breach_combined = MultipleChoiceField( |
3133 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3134 | | - ) |
3135 | | - risk_acceptance_expiration = MultipleChoiceField( |
3136 | | - choices=NOTIFICATION_CHOICES, default=DEFAULT_NOTIFICATION, |
3137 | | - ) |
3138 | | - template = serializers.BooleanField(default=False) |
3139 | | - |
3140 | | - class Meta: |
3141 | | - model = Notifications |
3142 | | - fields = "__all__" |
3143 | | - |
3144 | | - def validate(self, data): |
3145 | | - user = None |
3146 | | - product = None |
3147 | | - template = False |
3148 | | - |
3149 | | - if self.instance is not None: |
3150 | | - user = self.instance.user |
3151 | | - product = self.instance.product |
3152 | | - |
3153 | | - if "user" in data: |
3154 | | - user = data.get("user") |
3155 | | - if "product" in data: |
3156 | | - product = data.get("product") |
3157 | | - if "template" in data: |
3158 | | - template = data.get("template") |
3159 | | - |
3160 | | - if ( |
3161 | | - template |
3162 | | - and Notifications.objects.filter(template=True).count() > 0 |
3163 | | - ): |
3164 | | - msg = "Notification template already exists" |
3165 | | - raise ValidationError(msg) |
3166 | | - if ( |
3167 | | - self.instance is None |
3168 | | - or user != self.instance.user |
3169 | | - or product != self.instance.product |
3170 | | - ): |
3171 | | - notifications = Notifications.objects.filter( |
3172 | | - user=user, product=product, template=template, |
3173 | | - ).count() |
3174 | | - if notifications > 0: |
3175 | | - msg = "Notification for user and product already exists" |
3176 | | - raise ValidationError(msg) |
3177 | | - return data |
| 3070 | +from dojo.notifications.api.serializer import NotificationsSerializer # noqa: E402, F401 -- backward compat |
3178 | 3071 |
|
3179 | 3072 |
|
3180 | 3073 | class EngagementPresetsSerializer(serializers.ModelSerializer): |
@@ -3351,7 +3244,4 @@ def create(self, validated_data): |
3351 | 3244 | raise |
3352 | 3245 |
|
3353 | 3246 |
|
3354 | | -class NotificationWebhooksSerializer(serializers.ModelSerializer): |
3355 | | - class Meta: |
3356 | | - model = Notification_Webhooks |
3357 | | - fields = "__all__" |
| 3247 | +from dojo.notifications.api.serializer import NotificationWebhooksSerializer # noqa: E402, F401 -- backward compat |
0 commit comments