Skip to content

Commit

Permalink
Merge pull request #157 from monzo/unique-external-id
Browse files Browse the repository at this point in the history
Prevent duplicate external user records for the same app
  • Loading branch information
Chris authored Sep 27, 2019
2 parents f574f2f + e6d958d commit 7699f14
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion response/core/models/user_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def update_or_create_slack(self, *args, **kwargs):

class ExternalUser(models.Model):
class Meta:
unique_together = ("owner", "app_id")
unique_together = ("owner", "app_id", "external_id")

owner = models.ForeignKey(User, on_delete=models.PROTECT, null=True, blank=True)
app_id = models.CharField(max_length=50, blank=False, null=False)
Expand Down
18 changes: 18 additions & 0 deletions response/migrations/0011_auto_20190927_1339.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.3 on 2019-09-27 13:39

from django.conf import settings
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("response", "0010_incident_report_only"),
]

operations = [
migrations.AlterUniqueTogether(
name="externaluser", unique_together={("owner", "app_id", "external_id")}
)
]

0 comments on commit 7699f14

Please sign in to comment.