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

[#929] Refactor contacts #348

Merged
merged 13 commits into from
Dec 6, 2022
Merged

[#929] Refactor contacts #348

merged 13 commits into from
Dec 6, 2022

Conversation

vaszig
Copy link
Contributor

@vaszig vaszig commented Nov 24, 2022

  • Removes Contact model
  • Adds user_contacts and contacts_for_approval (field for invitations) to the User model
  • Removes phonenumber from contact creation and the ability to modify a contact

@vaszig vaszig marked this pull request as draft November 24, 2022 16:02
@alextreme
Copy link
Member

Nice refactor! Went over it early to ensure we're on the same page, think this is going in the right direction 👍

@vaszig vaszig force-pushed the task-929-remove-contact-model branch 2 times, most recently from 194c656 to 42c61ff Compare November 29, 2022 11:49
@vaszig vaszig marked this pull request as ready for review November 29, 2022 12:08
Copy link
Member

@alextreme alextreme left a comment

Choose a reason for hiding this comment

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

Nice work! Big PR but this was imho as discussed, only a few minor comments

src/open_inwoner/accounts/views/contacts.py Outdated Show resolved Hide resolved
src/open_inwoner/plans/admin.py Outdated Show resolved Hide resolved
return self.filter(
Q(contacts__contact_user=user) | Q(contacts__created_by=user)
).distinct()
return self.filter(Q(created_by=user) | Q(plan_contacts__id=user.id)).distinct()
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it makes sense to auto-add the creating user also to plan_contacts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with Alex, it will simplify code in several places

@vaszig
Copy link
Contributor Author

vaszig commented Nov 29, 2022

I have processed @alextreme 's reccomendations and I will push the changes as soon as the other guys have reviewed as well (I don't want to push new commits in case they have started their reviews).

@alextreme can I have a bit of explanation for the third comment?About adding the creating user to the plan_contacts

@alextreme
Copy link
Member

@alextreme can I have a bit of explanation for the third comment?About adding the creating user to the plan_contacts

Well, if we want to simplify the Plans further we could make it so that the User creating the Plan is both registered in created_by and in the plan_contacts M2M. This way you no longer would need to check both the created_by FK and the plan_contacts M2M, you would only have to check plan_contacts.

Up to you, Bart and Anna to determine if this makes sense, but as we're refactoring the Plans significantly it would make sense to also do this if you three agree with me. Otherwise you can leave it as-is.

@Bartvaderkin
Copy link
Contributor

@vaszig I haven't started on this today so I don't mind new commits.

@codecov-commenter
Copy link

codecov-commenter commented Nov 30, 2022

Codecov Report

Merging #348 (b89f152) into develop (348165a) will increase coverage by 0.06%.
The diff coverage is 99.78%.

@@             Coverage Diff             @@
##           develop     #348      +/-   ##
===========================================
+ Coverage    96.38%   96.45%   +0.06%     
===========================================
  Files          442      451       +9     
  Lines        13917    13906      -11     
===========================================
- Hits         13414    13413       -1     
+ Misses         503      493      -10     
Impacted Files Coverage Δ
src/open_inwoner/accounts/managers.py 88.88% <ø> (+2.35%) ⬆️
src/open_inwoner/accounts/urls.py 100.00% <ø> (ø)
..._inwoner/plans/management/commands/plans_expire.py 100.00% <ø> (ø)
src/open_inwoner/utils/tests/test_migrations.py 95.23% <95.23%> (ø)
src/open_inwoner/accounts/admin.py 92.06% <100.00%> (-0.59%) ⬇️
src/open_inwoner/accounts/forms.py 98.86% <100.00%> (+1.02%) ⬆️
...ner/accounts/migrations/0047_auto_20221130_1609.py 100.00% <100.00%> (ø)
...ner/accounts/migrations/0048_auto_20221130_1610.py 100.00% <100.00%> (ø)
...ner/accounts/migrations/0049_auto_20221130_1614.py 100.00% <100.00%> (ø)
..._0047_action_is_deleted_0049_auto_20221130_1614.py 100.00% <100.00%> (ø)
... and 29 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@Bartvaderkin Bartvaderkin left a comment

Choose a reason for hiding this comment

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

I've added some code style feedback.

But the most important thing I'm missing is a test for the significant data migration.

Here you can find a base class TestMigrations and some usage examples for a migration test: https://github.com/open-formulieren/open-forms/search?q=TestMigrations

Also I ran the migrations on my local database and I get some styling issues (but note the names were messy test data so the gaps might not mean anything)

Screenshot from 2022-11-30 11-04-46

src/open_inwoner/utils/tests/test_timeline_logger.py Outdated Show resolved Hide resolved
src/open_inwoner/accounts/models.py Outdated Show resolved Hide resolved
src/open_inwoner/accounts/models.py Outdated Show resolved Hide resolved
src/open_inwoner/accounts/query.py Outdated Show resolved Hide resolved
src/open_inwoner/accounts/tests/test_auth.py Outdated Show resolved Hide resolved
src/open_inwoner/utils/tests/test_timeline_logger.py Outdated Show resolved Hide resolved
src/open_inwoner/utils/tests/test_timeline_logger.py Outdated Show resolved Hide resolved
src/open_inwoner/accounts/tests/test_contact_views.py Outdated Show resolved Hide resolved
@vaszig vaszig changed the title [#929] Refactor contacts [WIP][#929] Refactor contacts Nov 30, 2022
@vaszig
Copy link
Contributor Author

vaszig commented Nov 30, 2022

  • Changes according to comments have been made
  • Tests for data migrations have been added but one is failing, I will investigate this with @Bartvaderkin
  • Concerning the styling, since we don't have a design for the creator's contactlist page, I am only showing the contacts' data (first name, last name) if they have been approved.

@vaszig vaszig force-pushed the task-929-remove-contact-model branch from 098274b to 8afd4f0 Compare December 1, 2022 07:23
@vaszig vaszig changed the title [WIP][#929] Refactor contacts [#929] Refactor contacts Dec 1, 2022
Copy link
Contributor

@annashamray annashamray left a comment

Choose a reason for hiding this comment

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

Good job!
It's much neater and more readable when before! The simplified querysets have brought a joy to my heart :)

src/open_inwoner/accounts/models.py Outdated Show resolved Hide resolved
src/open_inwoner/accounts/views/contacts.py Outdated Show resolved Hide resolved
src/open_inwoner/accounts/views/contacts.py Show resolved Hide resolved
src/open_inwoner/accounts/models.py Outdated Show resolved Hide resolved
src/open_inwoner/accounts/query.py Show resolved Hide resolved
return self.filter(
Q(contacts__contact_user=user) | Q(contacts__created_by=user)
).distinct()
return self.filter(Q(created_by=user) | Q(plan_contacts__id=user.id)).distinct()
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with Alex, it will simplify code in several places

src/open_inwoner/plans/forms.py Show resolved Hide resolved
Copy link
Contributor

@Bartvaderkin Bartvaderkin left a comment

Choose a reason for hiding this comment

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

Noticed this was waiting for me.

@alextreme alextreme dismissed annashamray’s stale review December 6, 2022 17:54

Comments have been resolved and this makes our life easier

@alextreme alextreme merged commit 14b8735 into develop Dec 6, 2022
@alextreme alextreme deleted the task-929-remove-contact-model branch December 6, 2022 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants