Master user token can not update/destroy a global false multi-tenancy resource

Hi sorry, I think have a mistake in using actions Imagine you are a master user (has who has not tenancy ) , now you want to update a a global false multi-tenancy resource record! So because it is master user and has no tenancy i created :get_any action, my code set tenancy nil for master user on plug level
archive do
# base_filter? false
exclude_read_actions [:archived, :get_any, :get_archived]
exclude_destroy_actions [:permanent_destroy]
end

read :get_any do
get? true
multitenancy :bypass
end
archive do
# base_filter? false
exclude_read_actions [:archived, :get_any, :get_archived]
exclude_destroy_actions [:permanent_destroy]
end

read :get_any do
get? true
multitenancy :bypass
end
and inside router
patch :update, route: "/:id", read_action: :get_any
patch :update, route: "/:id", read_action: :get_any
but with master user which his tenancy is nil , this patch dose not allow me to touch update action even, I mean before calling update it returns something like this error
Queries against the MishkaCms.Runtime.ErrorPage resource require a tenant to be specified
(ash 3.5.34) lib/ash/error/invalid/tenant_required.ex:4: Ash.Error.Invalid.TenantRequired.exception/1
(ash 3.5.34) lib/ash/actions/update/bulk.ex:937: Ash.Actions.Update.Bulk.validate_multitenancy/2
(ash 3.5.34) lib/ash/actions/update/bulk.ex:1124: Ash.Actions.Update.Bulk.do_run/8
(ash 3.5.34) lib/ash/actions/update/bulk.ex:494: Ash.Actions.Update.Bulk.run/6
(ash 3.5.34) lib/ash/actions/update/bulk.ex:137: Ash.Actions.Update.Bulk.run/6
(ash_json_api 1.4.40) lib/ash_json_api/controllers/helpers.ex:400: anonymous fn/2
Queries against the MishkaCms.Runtime.ErrorPage resource require a tenant to be specified
(ash 3.5.34) lib/ash/error/invalid/tenant_required.ex:4: Ash.Error.Invalid.TenantRequired.exception/1
(ash 3.5.34) lib/ash/actions/update/bulk.ex:937: Ash.Actions.Update.Bulk.validate_multitenancy/2
(ash 3.5.34) lib/ash/actions/update/bulk.ex:1124: Ash.Actions.Update.Bulk.do_run/8
(ash 3.5.34) lib/ash/actions/update/bulk.ex:494: Ash.Actions.Update.Bulk.run/6
(ash 3.5.34) lib/ash/actions/update/bulk.ex:137: Ash.Actions.Update.Bulk.run/6
(ash_json_api 1.4.40) lib/ash_json_api/controllers/helpers.ex:400: anonymous fn/2
so it forces me to use generic action, for example something like this https://gist.github.com/shahryarjb/f08e29615d5eed3b2ff2d9c87f314af1 to circumvent the problem This is the way? or is there better way to do this? Thank you in advance
Solution:
You'll have to use generic actions for a lot of things in that setup
Jump to solution
4 Replies
ZachDaniel
ZachDaniel2mo ago
Can you not set a tenant when the global user goes to delete something? Set it to the tenant of the thing that is being deleted? You could use a header for example to set the tenant i.e x-tenant
Shahryar
ShahryarOP2mo ago
Hi dear Zach
Can you not set a tenant when the global user goes to delete something?
So the other parts are not global false (i mean global true) have problems. i have some resource global true some resource global false
You could use a header for example to set the tenant
The master user dose not know this resource for what tenant in api, so it should let me to read and set tenant to master user (the problem is , it prevents me to update or destroy function, before it return error, so i do not know the record side_id to set x-tenant --- For making it clear You are master user in the system so you can - Change anything in any website - Can create some global stuff to other tenant user to use (for example create global gallery component and let user use in website a, but the button of website b can not be used in a)
ZachDaniel
ZachDaniel2mo ago
Honestly multitenancy was not built with that in mind.
Solution
ZachDaniel
ZachDaniel2mo ago
You'll have to use generic actions for a lot of things in that setup

Did you find this page helpful?