-
Notifications
You must be signed in to change notification settings - Fork 15
UNIFICATION: get_current_organization don't assume single Organization #785
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
1542a0c
b5ab596
2d216b6
d298926
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 |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| from django.conf import settings | ||
| from django.contrib.auth.models import User | ||
| from django.contrib.sites.models import Site | ||
| from django.core.exceptions import ImproperlyConfigured | ||
| from django.db.models.query import Q | ||
| from provider.oauth2.models import AccessToken, RefreshToken, Client | ||
| from django.utils.text import slugify | ||
|
|
@@ -233,10 +234,22 @@ def get_current_organization(failure_return_none=False): | |
| ) | ||
| else: | ||
| try: | ||
| # TODO: Using `get` is expected to fail when multiple-orgs found for a site. | ||
| # Maybe catch MultipleObjectsReturned? | ||
| current_org = current_site.organizations.get() | ||
| except Organization.DoesNotExist: | ||
| if settings.FEATURES.get('TAHOE_ENABLE_MULTI_ORGS_PER_SITE', False): | ||
| if settings.FEATURES.get('APPSEMBLER_MULTI_TENANT_EMAILS', False): | ||
| raise ImproperlyConfigured( | ||
| 'TAHOE_ENABLE_MULTI_ORGS_PER_SITE and ' | ||
| 'APPSEMBLER_MULTI_TENANT_EMAILS are incompatible as ' | ||
| 'we are not able to determine the exact Org when more than one ' | ||
| 'is associated with a Site.') | ||
| current_org = current_site.organizations.first() | ||
| if not current_org: | ||
| raise Organization.DoesNotExist( | ||
| 'TAHOE_ENABLE_MULTI_ORGS_PER_SITE: Could not find current ' | ||
| 'organization for site `{}`'.format(repr(current_site)) | ||
| ) | ||
| else: | ||
| current_org = current_site.organizations.get() | ||
|
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. Just to note that this will fail with a
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 think you mean if |
||
| except (Organization.DoesNotExist, ImproperlyConfigured): | ||
| if not failure_return_none: | ||
| raise # Re-raise the exception | ||
| else: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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't import directly from factory. This was breaking tests