(self, **kwargs)
| 13 | fields = ("id", "channel_id", "enabled") |
| 14 | |
| 15 | def save(self, **kwargs): # type: ignore[no-untyped-def] |
| 16 | try: |
| 17 | slack_configuration = SlackConfiguration.objects.get( |
| 18 | project=kwargs.get("environment").project # type: ignore[union-attr] |
| 19 | ) |
| 20 | except ObjectDoesNotExist as e: |
| 21 | raise serializers.ValidationError( |
| 22 | "Slack api token not found. Please generate the token using oauth" |
| 23 | ) from e |
| 24 | kwargs.update(slack_configuration=slack_configuration) |
| 25 | try: |
| 26 | SlackWrapper( # type: ignore[no-untyped-call] |
| 27 | api_token=slack_configuration.api_token, |
| 28 | channel_id=self.validated_data.get("channel_id"), |
| 29 | ).join_channel() |
| 30 | except SlackChannelJoinError as e: |
| 31 | raise serializers.ValidationError(e) from e # type: ignore[arg-type] |
| 32 | return super().save(**kwargs) |
| 33 | |
| 34 | |
| 35 | class SlackChannelSerializer(serializers.Serializer): # type: ignore[type-arg] |
no test coverage detected