ex_admin
ex_admin copied to clipboard
Different Repo Prefixes (Postgres Schemas)
Hi there,
I'm leveraging postgres schemas for a multi-tenant database via Ecto's built-in support for different query prefixes.
Is there a way to get this to work properly with ex_admin? Or a way to make a drop-down list / button with some kind of custom action to switch prefixes?
I have no experience with the new Ecto query prefixes so I can't comment on that.
There is no way of adding a global button or drop down at this time. However, you can add a custom action per resource. this could be customized to do a drop down.
You could add something to the dashboard, or add a custom page to do the selection.
Is there a way to customize the function calls that ex admin uses to query for the resources on the show and index pages ?
On Sat, Nov 26, 2016 at 11:03 PM Steve Pallen [email protected] wrote:
I have no experience with the new Ecto query prefixes so I can't comment on that.
There is no way of adding a global button or drop down at this time. However, you can add a custom action per resource. this could be customized to do a drop down.
You could add something to the dashboard, or add a custom page to do the selection.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/smpallen99/ex_admin/issues/239#issuecomment-263104319, or mute the thread https://github.com/notifications/unsubscribe-auth/ABN86vB8mvnr5hfKjijz89JaSzH7uJeoks5rCR1JgaJpZM4K8qvq .
Yes. Look at the Authorization protocol. If you implement this protocol, you get access to the query before the Repo fetch. Normally, this is used to filter resources based on some access control rules, but nothing says it has to be used for authorization.
Checkout this wiki entry for more information.
Steve
Thanks! I'll have a look when I get to the admin part of my project and see if I can get it to work w/ the tenants. On Sun, Nov 27, 2016 at 3:24 PM Steve Pallen [email protected] wrote:
Yes. Look at the Authorization protocol https://github.com/smpallen99/ex_admin/blob/master/lib/ex_admin/authentication.ex. If you implement this protocol, you get access to the query before the Repo fetch. Normally, this is used to filter resources based on some access control rules, but nothing says it has to be used for authorization.
Checkout this wiki entry https://github.com/smpallen99/ex_admin/wiki/Add-authorization for more information.
Steve
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/smpallen99/ex_admin/issues/239#issuecomment-263152191, or mute the thread https://github.com/notifications/unsubscribe-auth/ABN86jKlLHpDQDuuh8dJp7JUmWI-PV_5ks5rCgMygaJpZM4K8qvq .
FYI @brandonparsons, Ecto 2.1 will allow you to pass the prefix as a keyword parameter to Repo actions. If you're using anything prior to that, you'll have to alter the queryable itself.
See https://github.com/promptworks/tenantex/blob/master/lib/tenantex/queryable.ex to see how I've been doing that so far.
@jeffdeville @smpallen99 Any idea how to install ex_admin with ecto 2.1-rc ? I get a dependency clash
I'm sorry @benrom - I haven't tried it. Perhaps the overrided keyword can help? https://hexdocs.pm/mix/Mix.Tasks.Deps.html
@jeffdeville I tried that, but didn't manage to get it working. The scrivener dependency also has a fixed postgrex dependency (the postgrex version compatible with Ecto 2.1-rc is 1.0-rc).
@brandonparsons , did you succeed ? @smpallen99 any update on this issue, seems that many of us are using multi-tenant architecture.
Any progress with this? :)
https://github.com/promptworks/tenantex/pull/16 might help
I apologize that the code isn't merged and cleaned up yet. I've got a lot going on right now, but you can take a look at the PR for tenantex.
Briefly: TenantEx is a multi-tenant library that just wraps a repo, and ensures that any call made is properly prefixed. But this new PR adds a new wrinkle. Now you can set the prefix in the process dictionary using a plug, and then any command sent through the repo will automatically be prefixed just before it's executed. So ex_admin should never even realize what's going on. (The repo method signatures are not changed)
The code is ugly, but the tests are (I hope) thorough. I am on a node project right now though, so I don't have the time/project to put this PR through it's paces. I was hoping to get some feedback and then try and polish things up as soon as my world calms a bit.
Oh, one other distinction. You can create migrations for tenanted models separately from untenanted models. That's different from other multi-tenant libraries I've used where your schema is the same everywhere. That always felt unsafe to me. check the available mix tasks.
NOTE Ecto 2.2 changed some undocumented methods and so my specs there are failing. Another thing I'll get to, once I can get paying clients sorted out.