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