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

Adds multitenancy support #180

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zamith
Copy link
Contributor

@zamith zamith commented Nov 11, 2020

Why:

  • When building an admin dashboard is not always true that:

    1. There is only one repo
    2. The repo is not dynamic

This change addresses the need by:

  • Adding a resource level repo config that can be set when creating the
    resources list, to allow for multiple repos. It defaults to the ecto
    repo config in the env.
  • Adding a new configurable function called set_dynamic_repo, which
    takes the connection as based on that it will set the dynamic repo.
    Since the dynamic repo is set per process, this is done on every
    controller action, so that we can ensure it is set properly. An
    example of this could be by setting a cookie with the tenant, which a
    plug can assign to the connection and have the set_dynamic_repo use
    that to decide what to do.
  • Adding a new form of extension called navigation extras, which allows
    adding html to the top navigation. This can be used by, for example,
    having a select with the multiple tenants

This changes quite a few things and I don't expect you to agree with all
the decisions, but it should allow us to get the conversation going at least.
I'm not super familiar with kaffy's codebase, but I tried to leverage as much
of the existing API as possible and ensure that no existing configuration
need to change.

Tries to solve #179.

Why:

* When building an admin dashboard is not always true that:

  1. There is only one repo
  2. The repo is not dynamic

This change addresses the need by:

* Adding a resource level repo config that can be set when creating the
  resources list, to allow for multiple repos. It defaults to the ecto
  repo config in the env.
* Adding a new configurable function called `set_dynamic_repo`, which
  takes the connection as based on that it will set the dynamic repo.
  Since the dynamic repo is set per process, this is done on every
  controller action, so that we can ensure it is set properly. An
  example of this could be by setting a cookie with the tenant, which a
  plug can assign to the connection and have the `set_dynamic_repo` use
  that to decide what to do.
* Adding a new form of extension called navigation extras, which allows
  adding html to the top navigation. This can be used by, for example,
  having a select with the multiple tenants
@aesmail
Copy link
Owner

aesmail commented Nov 12, 2020

Hey @zamith
Thank you for this super effort!
This feature would put Kaffy in a great advantage and make it usable for even more projects.
I'll need a couple of days to check and test the changes and I'll get back to you.

@zamith
Copy link
Contributor Author

zamith commented Nov 12, 2020

Great to hear that you're interested. I have this working on a project already and can try to provide some examples of how the integration looks like if you need it, even though the project is private.

@ghost
Copy link

ghost commented Nov 10, 2022

hi @zamith I know it has been a while since you opened this PR. I am wondering would you be able to share examples of integration for the multi tenant application?

Some background: I opened a new question here #251 that might be related to this PR. The use case I have is a B2B startup where each team will have access to data within that organization and I also need to let team members create different environments such as Dev, Test etc.

@ghenry
Copy link
Collaborator

ghenry commented Apr 12, 2023

Hi,

Would you be so kind as to do this again to the master branch?

Thanks,
Gavin.

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.

None yet

3 participants