Skip to content

Commit 9e0c55b

Browse files
author
Laurie T. Malau
committed
Redirect when not owner
1 parent 56e7069 commit 9e0c55b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

components/dashboard/src/Menu.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ export default function Menu() {
108108
];
109109
}
110110
// Team menu
111-
if (team) {
112-
const currentUserInTeam = teamMembers[team.id];
111+
if (team && teamMembers && teamMembers[team.id]) {
112+
const currentUserInTeam = teamMembers[team.id].find(m => m.userId === user?.id);
113113

114114
const teamSettingsList = [
115115
{
@@ -126,7 +126,7 @@ export default function Menu() {
126126
link: `/t/${team.slug}/members`
127127
}
128128
];
129-
if (currentUserInTeam && currentUserInTeam[0].role === "owner") {
129+
if (currentUserInTeam?.role === "owner") {
130130
teamSettingsList.push({
131131
title: 'Settings',
132132
link: `/t/${team.slug}/settings`,

components/dashboard/src/teams/TeamSettings.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { useContext, useState } from "react";
8-
import { useLocation } from "react-router";
8+
import { Redirect, useLocation } from "react-router";
99
import ConfirmationModal from "../components/ConfirmationModal";
1010
import { PageWithSubMenu } from "../components/PageWithSubMenu";
1111
import { getGitpodService, gitpodHostUrl } from "../service/service";
@@ -37,6 +37,18 @@ export default function TeamSettings() {
3737
}
3838
]
3939

40+
const userIsOwner = async () => {
41+
if (!team) return;
42+
43+
const members = await getGitpodService().server.getTeamMembers(team.id);
44+
const currentUserInTeam = members.find(member => member.userId === user?.id);
45+
return currentUserInTeam?.role === 'owner';
46+
}
47+
48+
if (!userIsOwner) {
49+
return <Redirect to="/"/>
50+
}
51+
4052
return <>
4153
<PageWithSubMenu subMenu={settingsMenu} title='General' subtitle='Manage general team settings.'>
4254
<h3>Delete Team</h3>

0 commit comments

Comments
 (0)