Skip to content
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

[Teams] Fix Teams menu rendering even when there are backend errors #6041

Merged
merged 2 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions components/dashboard/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ export default function Menu() {
(async () => {
const members: Record<string, TeamMemberInfo[]> = {};
await Promise.all(teams.map(async (team) => {
const infos = await getGitpodService().server.getTeamMembers(team.id);
members[team.id] = infos;
try {
members[team.id] = await getGitpodService().server.getTeamMembers(team.id);
} catch (error) {
console.error('Could not get members of team', team, error);
}
}));
setTeamMembers(members);
})();
Expand Down Expand Up @@ -108,8 +111,8 @@ export default function Menu() {
];
}
// Team menu
if (team && teamMembers && teamMembers[team.id]) {
const currentUserInTeam = teamMembers[team.id].find(m => m.userId === user?.id);
if (team) {
const currentUserInTeam = (teamMembers[team.id] || []).find(m => m.userId === user?.id);

const teamSettingsList = [
{
Expand Down
12 changes: 10 additions & 2 deletions components/server/src/user/user-deletion-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { injectable, inject } from "inversify";
import { UserDB, WorkspaceDB, UserStorageResourcesDB } from '@gitpod/gitpod-db/lib';
import { UserDB, WorkspaceDB, UserStorageResourcesDB, TeamDB } from '@gitpod/gitpod-db/lib';
import { User, Workspace } from "@gitpod/gitpod-protocol";
import { StorageClient } from "../storage/storage-client";
import { log } from '@gitpod/gitpod-protocol/lib/util/logging';
Expand All @@ -22,6 +22,7 @@ export class UserDeletionService {
@inject(UserDB) protected readonly db: UserDB;
@inject(WorkspaceDB) protected readonly workspaceDb: WorkspaceDB;
@inject(UserStorageResourcesDB) protected readonly userStorageResourcesDb: UserStorageResourcesDB;
@inject(TeamDB) protected readonly teamDb: TeamDB;
@inject(StorageClient) protected readonly storageClient: StorageClient;
@inject(WorkspaceManagerClientProvider) protected readonly workspaceManagerClientProvider: WorkspaceManagerClientProvider;
@inject(WorkspaceDeletionService) protected readonly workspaceDeletionService: WorkspaceDeletionService;
Expand Down Expand Up @@ -72,7 +73,9 @@ export class UserDeletionService {
// UserStorageResourcesDB
this.userStorageResourcesDb.deleteAllForUser(user.id),
// Bucket
this.deleteUserBucket(id)
this.deleteUserBucket(id),
// Team memberships
this.deleteTeamMemberships(id),
]);

// Track the deletion Event for Analytics Purposes
Expand Down Expand Up @@ -132,6 +135,11 @@ export class UserDeletionService {
}
}

protected async deleteTeamMemberships(userId: string) {
const teams = await this.teamDb.findTeamsByUser(userId);
await Promise.all(teams.map(t => this.teamDb.removeMemberFromTeam(userId, t.id)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexTugarev Did you mean to /lgtm this Pull Request? 😇

}

anonymizeWorkspace(ws: Workspace) {
ws.context.title = 'deleted-title';
ws.context.normalizedContextURL = 'deleted-normalizedContextURL';
Expand Down