Skip to content

UNIFICATION: get_current_organization don't assume single Organization - #785

Merged
bryanlandia merged 4 commits into
appsembler/tahoe/developfrom
bryan/tahoe-standalone-compat-multiple-site-orgs
Dec 29, 2020
Merged

UNIFICATION: get_current_organization don't assume single Organization#785
bryanlandia merged 4 commits into
appsembler/tahoe/developfrom
bryan/tahoe-standalone-compat-multiple-site-orgs

Conversation

@bryanlandia

Copy link
Copy Markdown

Return the first instead to keep from failing outside of Tahoe SaaS
when we may have more than one Organization per Site

I know this needs tests. but putting this out there for discussion. It's the one known blocker I have for using the Tahoe edx-platform branch without changes for DHIS2 standalone. DHIS2 uses multiple course orgs. They and PSU and other enterprise customers use the course org to show who is offering / who created the course; for DHIS2, it's various different NGO partners; for PSU, it's various colleges at the university.

Obviously, it's a function that's very central to how Tahoe handles multitenancy and user management by Org.

@OmarIthawi OmarIthawi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@bryanlandia Thanks for jumping into this. This is a hairy subject 😅 and we honestly still haven't figured out how to do Tahoe orgs/site link properly 🤷🏼‍♂️

The .get() was done so it fails explicitly, which was a way to ensure our sites/orgs are properly linked and avoid None has no properly short_name coming out of nowhere.

I understand this is meant for Tahoe Enterprise setup, so this shouldn't make it into Tahoe at all, otherwise it would cause some errors that are hard to debug especially in the context of Multi-Tenant Emails i.e. make our lives a bit harder.

In such cases my suggestion is to use feature flags as explained in the code. Feature flags are not free and they cost a lot of maintenance cost and some features don't work at unless in certain combinations. Nevertheless, I find it more affordable than having separate branches.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In general we'd like to keep SaaS/Enterprise veery close together. So if it's a must, we can do something like this:

Suggested change
current_org = current_site.organizations.first()
if settings.FEATURES['TAHOE_ENABLE_MULTI_ORGS_PER_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()

Also, it needs to be tested so this code needs probably two tests in order to be covered.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the review @OmarIthawi . I was thinking more about it and agree we should try with a feature flag. The major goal here is definitely to avoid having separate branches. That's the whole reason we are going down the more difficult road of using the Tahoe branch for DHIS2's Hawthorn upgrade. I'll update the PR with tests and feature flag approach.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks Bryan! This is exciting. In theory it could be a single feature which says TAHOE_STANDALONE_MODE: True that enables a bunch of features, but I don't prefer huge features, so it could even be something like TAHOE_STANDALONE_MULTI_ORGS_PER_SITE: True to denote the context of this feature should be used only in STANDALONE sites.

I've been a bit lax on having large feature flag names, you're welcome to suggest a better one 😃

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I actually like the simpler one you suggested TAHOE_ENABLE_MULTI_ORGS_PER_SITE and agree we shouldn't do a big THIS IS STANDALONE switch to enable a bunch of things. I think I'll have some updated code with tests later today.

@bryanlandia bryanlandia Dec 18, 2020

Copy link
Copy Markdown
Author

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

@bryanlandia
bryanlandia force-pushed the bryan/tahoe-standalone-compat-multiple-site-orgs branch from ad8d4ed to 8ad35ee Compare December 18, 2020 00:59
@bryanlandia
bryanlandia marked this pull request as ready for review December 18, 2020 01:00
@bryanlandia

Copy link
Copy Markdown
Author

@OmarIthawi I'm taking this out of Draft as I've added (passing) tests

@bryanlandia
bryanlandia force-pushed the bryan/tahoe-standalone-compat-multiple-site-orgs branch from 8ad35ee to eb0febc Compare December 18, 2020 01:34
@bryanlandia

Copy link
Copy Markdown
Author

Huh... somehow I messed up rebasing and lost a commit that would fix what's breaking in Travis. Moving back to Draft until fixed.

@bryanlandia
bryanlandia marked this pull request as draft December 18, 2020 17:58
@bryanlandia
bryanlandia force-pushed the bryan/tahoe-standalone-compat-multiple-site-orgs branch from eb0febc to d298926 Compare December 22, 2020 08:36
@bryanlandia
bryanlandia marked this pull request as ready for review December 22, 2020 09:55

@OmarIthawi OmarIthawi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM! Thanks @bryanlandia!

@bryanlandia
bryanlandia merged commit 0eae98c into appsembler/tahoe/develop Dec 29, 2020
@bryanlandia
bryanlandia deleted the bryan/tahoe-standalone-compat-multiple-site-orgs branch December 29, 2020 21:18
'organization for site `{}`'.format(repr(current_site))
)
else:
current_org = current_site.organizations.get()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to note that this will fail with a MultipleObjectsReturned if there happen to be multiple orgs for a site in the deployment that has TAHOE_ENABLE_MULTI_ORGS_PER_SITE=True So we probably want to log this somewhere. Would it get automatically thrown to Sentry?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think you mean if TAHOE_ENABLE_MULTI_ORGS_PER_SITE=False. Agreed, would probably be good to catch that and generally log the exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants