From 0183863fb8d5ca0d45ea0b67aa175258f0f9ff08 Mon Sep 17 00:00:00 2001 From: Luke Heath Date: Thu, 11 Nov 2021 17:31:47 -0600 Subject: [PATCH] Fix team admin and team maintainer team settings display (#2897) --- changes/fix-2881-team-admin-maintainer | 1 + .../AuthAnyAdminRoutes/AuthAnyAdminRoutes.tsx | 15 +++++++++++++-- .../components/side_panels/SiteTopNav/navItems.js | 5 ++++- 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 changes/fix-2881-team-admin-maintainer diff --git a/changes/fix-2881-team-admin-maintainer b/changes/fix-2881-team-admin-maintainer new file mode 100644 index 000000000..551a8c1b6 --- /dev/null +++ b/changes/fix-2881-team-admin-maintainer @@ -0,0 +1 @@ +* Fix team admin and team maintainer team settings display \ No newline at end of file diff --git a/frontend/components/AuthAnyAdminRoutes/AuthAnyAdminRoutes.tsx b/frontend/components/AuthAnyAdminRoutes/AuthAnyAdminRoutes.tsx index 9313f84a4..0ecce79a2 100644 --- a/frontend/components/AuthAnyAdminRoutes/AuthAnyAdminRoutes.tsx +++ b/frontend/components/AuthAnyAdminRoutes/AuthAnyAdminRoutes.tsx @@ -33,9 +33,20 @@ const AuthAnyAdminRoutes = ({ return null; } + const teamId = Number(children.props.params.team_id) || null; + let allowAccess; + + if (teamId && user.teams) { + const userAdminTeams = user.teams.filter( + (thisTeam) => thisTeam.role === "admin" + ); + allowAccess = userAdminTeams.some((thisTeam) => thisTeam.id === teamId); + } + if ( - !permissionUtils.isGlobalAdmin(user) && - !permissionUtils.isAnyTeamAdmin(user) + (!permissionUtils.isGlobalAdmin(user) && + !permissionUtils.isAnyTeamAdmin(user)) || + (!permissionUtils.isGlobalAdmin(user) && !allowAccess) ) { dispatch(push(HOME)); dispatch(renderFlash("error", "You do not have permissions for that page")); diff --git a/frontend/components/side_panels/SiteTopNav/navItems.js b/frontend/components/side_panels/SiteTopNav/navItems.js index 4a7d0ec43..5d7473c7e 100644 --- a/frontend/components/side_panels/SiteTopNav/navItems.js +++ b/frontend/components/side_panels/SiteTopNav/navItems.js @@ -61,6 +61,9 @@ export default (currentUser) => { permissionUtils.isAnyTeamAdmin(currentUser) || permissionUtils.isGlobalAdmin(currentUser) ) { + const userAdminTeams = currentUser.teams.filter( + (thisTeam) => thisTeam.role === "admin" + ); const adminNavItems = [ { icon: "settings", @@ -71,7 +74,7 @@ export default (currentUser) => { pathname: currentUser.global_role === "admin" ? PATHS.ADMIN_SETTINGS - : `${PATHS.ADMIN_TEAMS}/${currentUser.teams[0].id}/members`, + : `${PATHS.ADMIN_TEAMS}/${userAdminTeams[0].id}/members`, }, }, ];