Giving admin/owner/viewer access to all sites (in bulk) #2658
-
Hi, First of all, thank you for such a great product. I really love it and I'm happy I left GA4 for Plausible :) I'm migrating about 45 websites to a self-hosted instance. I'm aware of https://plausible.io/docs/users-roles, but I can't figure out if there is a way, how to add a second owner/admin/viewer to all sites without setting it up for each site specifically. I need to give access to ~10 users to 45 sites, that's a looot of clicking... :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
👋 @Tony-MF I'm not sure if there is an API endpoint for this, but you can probably do this by connecting to the running container (if you are using containers) and calling a few functions. $ cd hosting
$ docker compose exec -ti plausible bin/plausible remote iex> import Ecto.Query
iex> alias Plausible.{Site, Repo, Auth}
# this code is untested
iex> add_members = fn role, emails, sites ->
Repo.transaction(fn ->
sites = Site |> where([s], s.domain in ^sites) |> Repo.all()
users = Auth.User |> where([u], u.email in ^emails) |> Repo.all()
for site <- sites, user <- users do
IO.puts("giving #{user.email} #{role} access in #{site.domain}")
Repo.insert!(%Site.Membership{role: role, user_id: user.id, site_id: site.id})
end
end)
end
iex> sites = ["example.com", "dummy.site"]
iex> emails = ["[email protected]", "[email protected]"]
iex> add_members.(:admin, emails, sites) |
Beta Was this translation helpful? Give feedback.
-
this is not currently supported. there's a feature request thread here #1350 |
Beta Was this translation helpful? Give feedback.
-
Here is an updated code that skips users who already have access to the site (otherwise it returns an error and stops).
|
Beta Was this translation helpful? Give feedback.
👋 @Tony-MF
I'm not sure if there is an API endpoint for this, but you can probably do this by connecting to the running container (if you are using containers) and calling a few functions.