-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Adding global email model #5913
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from __future__ import absolute_import | ||
|
|
||
| from django.db import models | ||
| from django.utils import timezone | ||
| from django.utils.translation import ugettext_lazy as _ | ||
|
|
||
| from sentry.db.models import Model, sane_repr | ||
| from sentry.db.models import CIEmailField | ||
|
|
||
|
|
||
| class Email(Model): | ||
| """ | ||
| Email represents a unique email. Email settings (unsubscribe state) should be associated here. | ||
| UserEmail represents whether a given user account has access to that email. | ||
| """ | ||
| __core__ = True | ||
|
|
||
| email = CIEmailField(_('email address'), unique=True) | ||
| date_added = models.DateTimeField(default=timezone.now) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't need an index on this now, we'll probably need to add one later if we try to do anything with this table regarding cleanup.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to punt on this because I'm unsure when we'd need to do such a cleanup. |
||
|
|
||
| class Meta: | ||
| app_label = 'sentry' | ||
| db_table = 'sentry_email' | ||
|
|
||
| __repr__ = sane_repr('email') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from __future__ import absolute_import | ||
|
|
||
| from django.db import IntegrityError, transaction | ||
| from django.db.models.signals import post_delete, post_save | ||
|
|
||
| from sentry.models import Email, UserEmail | ||
|
|
||
|
|
||
| def create_email(instance, created, **kwargs): | ||
| if created: | ||
| try: | ||
| with transaction.atomic(): | ||
| Email.objects.create(email=instance.email) | ||
| except IntegrityError: | ||
| pass | ||
|
|
||
|
|
||
| def delete_email(instance, **kwargs): | ||
| if UserEmail.objects.filter(email=instance.email).exists(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to note here, that this might be slightly inaccurate due to this not being a case insensitive lookup. You should do
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point: #6070 |
||
| return | ||
|
|
||
| Email.objects.filter(email=instance.email).delete() | ||
|
|
||
|
|
||
| post_save.connect(create_email, sender=UserEmail, dispatch_uid="create_email", weak=False) | ||
| post_delete.connect(delete_email, sender=UserEmail, dispatch_uid="delete_email", weak=False) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a date_added field here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added