Last active
March 23, 2022 01:15
-
-
Save sminnee/c0d1def6baa6dcd56d371a5f1950534a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/server/integrations/models.py b/server/integrations/models.py | |
index 56dfbcbc1..e837b237a 100644 | |
--- a/server/integrations/models.py | |
+++ b/server/integrations/models.py | |
@@ -43,7 +43,7 @@ class Integration(models.Model): | |
class Meta: | |
ordering = ["organization", "type"] | |
- unique_together = [["organization", "type", "domain"]] | |
+ unique_together = [["organization", "type", "domain", "owner"]] | |
def __str__(self): | |
return f"{self.organization.name} - {self.type.name}" | |
diff --git a/server/integrations/views.py b/server/integrations/views.py | |
index 01841fa1f..1a920b3c7 100644 | |
--- a/server/integrations/views.py | |
+++ b/server/integrations/views.py | |
@@ -8,7 +8,7 @@ from .serializers import IntegrationSerializer | |
class IntegrationsViewSet(GenericViewSet, ListModelMixin, RetrieveModelMixin): | |
serializer_class = IntegrationSerializer | |
lookup_field = "type__code" | |
- queryset = Integration.objects.all() | |
+ queryset = Integration.objects.all().select_related("type") | |
def filter_queryset(self, queryset): | |
return queryset.filter(organization=self.request.organization, owner__isnull=True) | |
diff --git a/server/simpro/api/auth.py b/server/simpro/api/auth.py | |
index 06e44655d..f5ed282f2 100644 | |
--- a/server/simpro/api/auth.py | |
+++ b/server/simpro/api/auth.py | |
@@ -60,7 +60,7 @@ def save_user_auth( | |
) -> IntegrationUser: | |
integration_type = IntegrationType.objects.get(code=INTEGRATION_TYPE) | |
integration = Integration.objects.filter( | |
- organization=organization, domain=build_domain, type=integration_type | |
+ organization=organization, domain=build_domain, type=integration_type, owner__isnull=True | |
).first() | |
if not integration: | |
integration = Integration.objects.create(organization=organization, type=integration_type, domain=build_domain) | |
diff --git a/server/simpro/views/auth.py b/server/simpro/views/auth.py | |
index aab53a18a..01e9b6953 100644 | |
--- a/server/simpro/views/auth.py | |
+++ b/server/simpro/views/auth.py | |
@@ -47,5 +47,6 @@ class AccessCodeURLView(views.APIView): | |
auth_data = authenticate(build_domain, access_code) | |
except AuthenticationFailed as ex: | |
raise ValidationError("Invalid credentials: " + str(ex)) | |
+ logger.info("Adding SimPRO integration for ", request.organization.name) | |
save_user_auth(request.user, request.organization, build_domain, auth_data[0], auth_data[1], auth_data[2]) | |
return Response(status=HTTP_204_NO_CONTENT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment