Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move common functionality to destination base class #936

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hmpf
Copy link
Contributor

@hmpf hmpf commented Nov 11, 2024

Best reviewed per file.

@hmpf hmpf requested review from johannaengland, stveit and a team November 11, 2024 14:24
@hmpf hmpf changed the title move common functionality to base class Move common functionality to destination base class Nov 11, 2024
@hmpf hmpf self-assigned this Nov 12, 2024
@hmpf hmpf added the refactor label Nov 12, 2024
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from c39d564 to 55a2ff0 Compare November 13, 2024 09:23
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from 55a2ff0 to 5989b0a Compare December 2, 2024 12:39
@hmpf hmpf marked this pull request as ready for review December 3, 2024 08:53
@hmpf hmpf requested a review from lunkwill42 December 3, 2024 08:53
@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 69.82249% with 51 lines in your changes missing coverage. Please review.

Project coverage is 78.26%. Comparing base (a3311e0) to head (304367b).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/argus/notificationprofile/media/base.py 62.10% 36 Missing ⚠️
src/argus/notificationprofile/media/email.py 80.95% 8 Missing ⚠️
src/argus/notificationprofile/media/__init__.py 42.85% 4 Missing ⚠️
src/argus/notificationprofile/serializers.py 89.47% 2 Missing ⚠️
...rc/argus/notificationprofile/media/sms_as_email.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #936      +/-   ##
==========================================
- Coverage   78.48%   78.26%   -0.22%     
==========================================
  Files         141      141              
  Lines        5442     5512      +70     
==========================================
+ Hits         4271     4314      +43     
- Misses       1171     1198      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hmpf hmpf requested a review from stveit December 3, 2024 12:25
src/argus/notificationprofile/media/base.py Show resolved Hide resolved
src/argus/notificationprofile/media/base.py Outdated Show resolved Hide resolved
src/argus/notificationprofile/media/base.py Outdated Show resolved Hide resolved
src/argus/notificationprofile/media/email.py Outdated Show resolved Hide resolved
src/argus/notificationprofile/media/base.py Outdated Show resolved Hide resolved
src/argus/notificationprofile/media/base.py Outdated Show resolved Hide resolved
src/argus/notificationprofile/media/base.py Outdated Show resolved Hide resolved
src/argus/notificationprofile/serializers.py Outdated Show resolved Hide resolved
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from 3b78212 to 7b8826c Compare December 4, 2024 06:51
@hmpf hmpf requested a review from johannaengland December 4, 2024 10:44
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from 0e23752 to 3131826 Compare December 4, 2024 13:52
Copy link

sonarqubecloud bot commented Dec 4, 2024

Copy link
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked and we don't have a test for trying to PATCH update with medium being empty, that should be added, I think then it would be clearer if the changes work or not

We do have tests for when trying to change the medium that that will lead to an error

src/argus/notificationprofile/media/base.py Show resolved Hide resolved
src/argus/notificationprofile/serializers.py Outdated Show resolved Hide resolved
@hmpf
Copy link
Contributor Author

hmpf commented Dec 6, 2024

I just checked and we don't have a test for trying to PATCH update with medium being empty, that should be added, I think then it would be clearer if the changes work or not

We do have tests for when trying to change the medium that that will lead to an error

We are now way out of scope for a refactor.

I guess the underlying problem is that we cannot lookup and change destinations of a specific media type directly, as part of the url of the endpoint. If we could, we would never need bother with media in the update-serializer.

@johannaengland
Copy link
Contributor

I just checked and we don't have a test for trying to PATCH update with medium being empty, that should be added, I think then it would be clearer if the changes work or not
We do have tests for when trying to change the medium that that will lead to an error

We are now way out of scope for a refactor.

Yes, I agree, I can do this in another PR, but that would have to merged before this then, because it would show if the functionality is staying the same

@hmpf
Copy link
Contributor Author

hmpf commented Dec 6, 2024

I don't think it is wise to stress with finishing this PR this week anymore, so start on the patch-PR next week.

src/argus/notificationprofile/media/base.py Outdated Show resolved Hide resolved
src/argus/notificationprofile/media/base.py Outdated Show resolved Hide resolved
@hmpf hmpf requested a review from stveit January 7, 2025 09:36
@hmpf hmpf force-pushed the cleanup-destination-plugins branch 2 times, most recently from d1eb78c to 97cc505 Compare January 7, 2025 12:55
@hmpf hmpf requested a review from johannaengland January 7, 2025 12:56
Copy link
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only comment unresolved is the one in the documentation

Copy link
Contributor

@stveit stveit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smol comment

src/argus/notificationprofile/media/email.py Outdated Show resolved Hide resolved
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from 8a84843 to d329536 Compare January 8, 2025 12:19
@hmpf
Copy link
Contributor Author

hmpf commented Jan 8, 2025

I decided to pass in the DestinationConfig instance (if any) to the clean-method so that it will have access to the currently stored settings.

@hmpf hmpf requested a review from stveit January 8, 2025 13:51
Copy link
Contributor

@stveit stveit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dos commentos

src/argus/notificationprofile/media/base.py Outdated Show resolved Hide resolved
src/argus/notificationprofile/media/base.py Outdated Show resolved Hide resolved
@hmpf
Copy link
Contributor Author

hmpf commented Jan 15, 2025

We could change the __str__ function of DestinationConfig change to use the get_label function in general. Then we can simplify this

Originally posted by @johannaengland in #1118 (comment)

@stveit
Copy link
Contributor

stveit commented Jan 15, 2025

I got stuff mostly working with this but the main problem is extracting errors to show in the related fields

@hmpf hmpf force-pushed the cleanup-destination-plugins branch from d329536 to ee9eb86 Compare January 16, 2025 07:27
@hmpf hmpf force-pushed the cleanup-destination-plugins branch 3 times, most recently from 38130e1 to 282b4d2 Compare January 24, 2025 11:01
.. also make it easioer to validate the settings-field with a django
form.
@hmpf hmpf force-pushed the cleanup-destination-plugins branch from 282b4d2 to 304367b Compare January 24, 2025 11:29
@hmpf hmpf requested review from stveit and podliashanyk January 24, 2025 11:38
Copy link
Contributor

@stveit stveit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sum comments

Comment on lines +132 to +141
if cls.has_duplicate(user.destinations, form.cleaned_data):
form.add_error(
None,
DjangoValidationError(
"This %(media)s destination already exists",
code="duplicate",
params={"media": cls.MEDIA_SLUG},
),
)
return form
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message does not specify what is a duplicate: the label, the settings value or both. When testing #1161, it was not clear what exactly the problem was when this message was shown. If this is a problem with this part of the code, or a problem the frontend elements in #1161 should fix I am not sure, but I'll just leave the comment here

@@ -67,23 +185,52 @@ def send(cls, event: Event, destinations: Iterable[DestinationConfig], **kwargs)
pass

@classmethod
def raise_if_not_deletable(cls, destination: DestinationConfig) -> NoneType:
def is_not_deletable(cls, destination: DestinationConfig) -> dict[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the value type Any? Seems like it can only ever be a str

return {}

@classmethod
def raise_if_not_deletable(cls, destination: DestinationConfig) -> NoneType:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure None should be used as return type over NoneType, but this seems to be a relic from the past and not really introduced in this PR

@johannaengland johannaengland self-requested a review January 29, 2025 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Ready for review
Development

Successfully merging this pull request may close these issues.

4 participants