Skip to content
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

feat: Multi-tenancy / Add support for multiple tenants #561

Merged
merged 40 commits into from
May 20, 2024

Conversation

mkleszcz
Copy link
Contributor

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce?

Closes #382
Add multi tenancy feature to SB. Feature is described in issue #382

Does this PR introduce a breaking change?

Yes.

wojcikmat and others added 30 commits March 7, 2024 09:06
* Add multitenancy app with some basic model configuration

* Add creation of signup tenant and add it in currentUser query schema.

* Add tests

* Add short documentation for multi tenancy manager

* PR fixes & linter fix

* Add migration

* Documentation grammar
* feat: Add crud for Tenants & middleware for current tenant and user role

* Add missing migration

* Add documentation

* Reformat docs

* Add batch creation of tenants to tests

* Change the omitting rule for test coverage

* PR fixes

* Slug generation refactor

* Refactor tenant model tests
* Working invitation flow

* Add migration

* Fix existing tests

* Add tests and connect existing invitations to newly created memberships

* Add tenants queries with permission specific fields

* Fix & add tests

* Add invitation token & tests

* Add some basic documentation

* Handle invitation accepted at date

* PR fixes
* Add first name, last name, email and avatar to TenantMembershipType

* Add mutations for update/delete tenant membership. Introduce validation for having at least one owner in tenant, and block inviting to default type tenant
* Change subscribtion customer model to Tenant

* Fix tests

* Add billing model
* Fix enum type converter

* Remove type for role field, make it default

* Add migration

* Fix migrations conflict
* Make tenant dependent example CRUD demo item model

* Remove redundant function

* Possibly fix test

* Send notifictions about CRUD item changes to tenant owners
* feat: allow the user to change membership role

* chore: update tenant membership graphql adjustments

* chore: update unit tests

* chore: membership entry test refactor

* chore: MembershipEntry tests refactor

* feat: add onCompleted handler

* chore: add toast test

* chore: refactor membership entry tests

* feat: add fil message, update tests

* chore: snapshot update
* Add notifications for created, accepted and declined invitation

* Make tenantId required
* feat: multi tenancy subscription plan adjustments

* chore: refactor tests

* chore: Modify `webapp-finances` rendering utils to include tenant providers

* chore: adjust routing, tests fixes

* chore: fix type error

---------

Co-authored-by: Michal Kleszcz <[email protected]>
Add TenantRoleAccess component, fix subscriptions routing, add Subscription tab to tenant settings page
* feat: add a danger zone into General Settings of the organization with removal mutation

---------

Co-authored-by: Michal Kleszcz <[email protected]>
* Add delete tenant validation and subscription cancellation to mutation

* Add test for tenant with free plan (nothing to cancel)
# Conflicts:
#	packages/webapp-libs/webapp-finances/src/utils/storybook.tsx
#	packages/webapp/package.json
#	pnpm-lock.yaml
@mkleszcz mkleszcz added this to the 3.0.0 milestone May 17, 2024
@mkleszcz mkleszcz requested a review from pziemkowski May 17, 2024 13:52
mkleszcz and others added 2 commits May 20, 2024 10:07
# Conflicts:
#	packages/webapp-libs/webapp-core/package.json
#	pnpm-lock.yaml
@@ -8,7 +8,7 @@
"postinstall": "node packages/internal/cli/scripts/build.js"
},
"devDependencies": {
"@apollo/client": "^3.8.8",
"@apollo/client": "^3.9.6",
Copy link
Contributor

@sdrejkarz sdrejkarz May 20, 2024

Choose a reason for hiding this comment

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

Is this update on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm... Interesting. I think it should go with the newer version

const { data, loading } = useQuery(editCrudDemoItemQuery, { variables: { id: id ?? '' } });
const { data, loading } = useQuery(editCrudDemoItemQuery, {
variables: { id: id ?? '', tenantId: currentTenant?.id ?? '' },
skip: !currentTenant,
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it should be skipped also when !id


const successDeleteMessage = intl.formatMessage({
id: 'Tenant form / DeleteTenant / Success message',
defaultMessage: '🎉 Tenant deleted successfully!',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use Organization here, same for failed


const successMessage = intl.formatMessage({
id: 'Tenant form / AddTenant / Success message',
defaultMessage: '🎉 Tenant added successfully!',
Copy link
Contributor

Choose a reason for hiding this comment

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

Organization copy


const successMessage = intl.formatMessage({
id: 'Tenant form / UpdateTenant / Success message',
defaultMessage: '🎉 Tenant updated successfully!',
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking about it because it can be triggered inside of organization and personal account. Maybe we could notify without this tenant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. The copy could be better

Copy link
Contributor

@sdrejkarz sdrejkarz May 20, 2024

Choose a reason for hiding this comment

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

I'm thinking of leaving it as an Organization, as there are a lot of copies inside of this settings suggesting its organization.
@mkleszcz

const navigate = useNavigate();
const isPersonal = useCurrentTenant().data?.type === TenantType.PERSONAL;

const handleLastInvitationClick = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I've made a typo before. It should be handleNewTenantClick

@mkleszcz mkleszcz merged commit 0ff33d9 into master May 20, 2024
54 of 56 checks passed
@mkleszcz mkleszcz deleted the feat/multi-tenancy branch May 20, 2024 14:35
mkleszcz added a commit that referenced this pull request May 22, 2024
BREAKING CHANGE: Important migration instructions

Before running the multi-tenancy migrations on your existing codebase or database, it is crucial to follow these steps to avoid any issues:
1. Remove or comment `DJSTRIPE_SUBSCRIBER_MODEL` setting
2. Run the migrations
3. Revert the change: After the migrations have successfully completed, revert the change by uncommenting or re-adding the `DJSTRIPE_SUBSCRIBER_MODEL` setting.
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.

Multi-tenancy / Add support for multiple tenants in SaaS Boilerplate web app
4 participants