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

🚧 notification model and signals for wishlist feature #233

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MorganeAD
Copy link
Contributor

@MorganeAD MorganeAD commented Feb 28, 2023

This PR is the second part of the issue #196 (feature user course wishlist)

This PR adds:

  • model Notification which represents a user notification about a subject according an action on a related object
  • three signals: post_save on CourseRun, post_save on ProductTargetCourseRelation and m2m_changed post_add on Product.target_courses. the signal generate a notification entity that need to be sent

It's related to the comment on this PR #207 (comment)

@MorganeAD MorganeAD force-pushed the issue-196_morgane_course_user_wishlist branch from 1aa2177 to d280c9d Compare February 28, 2023 16:08
@MorganeAD MorganeAD force-pushed the issue-196_morgane_course_user_wishlist_part2 branch from c0d43e7 to b173631 Compare February 28, 2023 16:08
@MorganeAD MorganeAD force-pushed the issue-196_morgane_course_user_wishlist branch 2 times, most recently from f9b6bc4 to 06f3ee7 Compare March 1, 2023 08:09
.gitignore Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Comment on lines +90 to +95
notif_type = models.CharField(
_("Type of notification"),
choices=NOTIF_TYPES,
max_length=10,
default=NOTIF_TYPE_EMAIL
)
Copy link
Member

Choose a reason for hiding this comment

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

In case where user asks to be notified by email and via the interface, two notifications items will be created ?

Copy link
Contributor Author

@MorganeAD MorganeAD Mar 7, 2023

Choose a reason for hiding this comment

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

Yes, I think it's better to separate it in two different notification instance because it's not the same process behind and it can be notified at different datetime. Also it's easier if a User when to be notified by the interface and not by email and vice versa.
What do you think ?

Comment on lines +60 to +81
notif_subject_ctype_limit = models.Q(app_label='core', model='coursewish') \
| models.Q(app_label='core', model='enrollment')
notif_subject_ctype = models.ForeignKey(
ContentType,
on_delete=models.CASCADE,
related_name="subject_ctype_of_notifications",
limit_choices_to=notif_subject_ctype_limit
)
notif_subject_id = models.UUIDField()
notif_subject = GenericForeignKey('notif_subject_ctype', 'notif_subject_id')

notif_object_ctype_limit = models.Q(app_label='core', model='producttargetcourserelation') \
| models.Q(app_label='core', model='courserun') \
| models.Q(app_label='core', model='product')
notif_object_ctype = models.ForeignKey(
ContentType,
on_delete=models.CASCADE,
related_name="object_ctype_of_notifications",
limit_choices_to=notif_object_ctype_limit
)
notif_object_id = models.UUIDField()
notif_object = GenericForeignKey('notif_object_ctype', 'notif_object_id')
Copy link
Member

Choose a reason for hiding this comment

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

Why do you prefix all those attributes by notif_?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I start to prefix by "notif_" to specify that is the "subject of the notification", in my opinion "subject" and "object" are too generic worlds by themselves, but if you prefer, I can remove the prefix. :)

Comment on lines +60 to +61
notif_subject_ctype_limit = models.Q(app_label='core', model='coursewish') \
| models.Q(app_label='core', model='enrollment')
Copy link
Member

Choose a reason for hiding this comment

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

In the future, external services should be able to create notifications. The kind of limit you are defining here could block this kind of feature, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, if we keep the limitation, we have to not forget to add the new authorized models for the futures external services.
I think it's better to have a limitation to correctly use the Notification model but we can also remove it.

This commit is the first part of the issue 196 (feature wishlist)
This commit add:
* model CourseWish that links a User and a Course
* endpoints to use this new model, according to the auth User
        * GET wish list (can be filtered by course_code)
        * GET a wish
        * POST a wish
        * DELETE a wish
@MorganeAD MorganeAD force-pushed the issue-196_morgane_course_user_wishlist branch 2 times, most recently from b248943 to 6417199 Compare March 7, 2023 10:26
@MorganeAD MorganeAD force-pushed the issue-196_morgane_course_user_wishlist branch from 6417199 to 88c26bc Compare March 7, 2023 10:52
@MorganeAD MorganeAD force-pushed the issue-196_morgane_course_user_wishlist_part2 branch from b173631 to 6c6e1aa Compare March 7, 2023 11:01
@sampaccoud sampaccoud force-pushed the issue-196_morgane_course_user_wishlist branch 5 times, most recently from 6c7da60 to 06b0584 Compare July 7, 2023 16:48
Base automatically changed from issue-196_morgane_course_user_wishlist to main July 7, 2023 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants