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