-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implement support for multiple team owners and multiple teams per user #5008
Conversation
1a9aac5
to
4472c5b
Compare
a978a90
to
66c2123
Compare
4472c5b
to
181c547
Compare
|
f7d9ee5
to
5fb8b28
Compare
1598169
to
0354cc4
Compare
@@ -90,17 +90,30 @@ defmodule Plausible.HelpScout do | |||
plan = Billing.Plans.get_subscription_plan(team.subscription) | |||
{team, team.subscription, plan} | |||
|
|||
{:error, :multiple_teams} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case will be handled better on further iterations. For now we just fall back on first team the user owns.
{:error, :no_team} -> | ||
{nil, nil, nil} | ||
end | ||
|
||
status_link = | ||
if team do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If user does not own any team yet, we fall back on linking directly to the User CRM
|
||
case Sites.create(user, params) do | ||
case Sites.create(user, params, team) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sites(user, params, nil)
will preserve the current behavior of adding the site to the existing implicit team or creating one.
@@ -73,6 +74,20 @@ defmodule PlausibleWeb.Api.ExternalSitesController do | |||
"Your account has reached the limit of #{limit} sites. To unlock more sites, please upgrade your subscription." | |||
}) | |||
|
|||
{:error, _, :permission_denied, _} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new error cases will only occur on explicit team selection or once user is an owner of more than one team at once.
22e91db
to
adfa9d2
Compare
This PR addresses enabling support for following across the whole application:
Summary of changes:
AuthorizeSiteAccess
calls instead of implicit translation of legacyAdmin
in the input roles toEditor
team_id
(required though if user is an owner on more than one team already). If the argument is not passed, an implicit team is used or created if there isn't one already. In case of adding a website from the dashboard, a currently selected team is used. The controller action has an option to accept "team_id" but it's not exposed in the UI yet; This leads to a problematic corner case mentioned belowAuthPlug
andAuthContext
-my_team
(existing),current_team
andmultiple_teams?
;multiple_teams?
is a flag used to determine whether to show the team switcher in the upper menu;current_team
is a team set via team switcher and stored undercurrent_team_id
in session cookie; if there's none set, it falls back tomy_team
;my_team
is either the same ascurrent_team
is user's team role isowner
or the first found team where the user is an owner otherwise - they may differteam_id
parameterThere still is a number of corner cases to consider, most likely in a follow-up:
when a user has their own implicit team and gets added as a team member to another team, when switched to their team, they still see CTA option and can't access team member management until they complete it. It feels a bit weird but maybe it's fine?Leaving it as is for now.the /sites view still lists all sites the user has access to, regardless of which team they are switched to; the view will probably be scoped to the currently switched team, though the Sites API endpoint should probably still list everything, with an optional team ID parameter?Addedadd ability to choose team to transfer ownership to in CRMTODO
is_autocreated
tofalse
either on role downgrade or team membership upsert where role is downgraded (or at least double-check the implications of leaving it on)Changes
Depends on #5004
Tests