Skip to content

Commit a4f3803

Browse files
AlexTugarevroboquat
authored andcommitted
[teams] enable features on joining of a team
1 parent 6bc80eb commit a4f3803

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

components/dashboard/src/projects/NewProject.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export default function NewProject() {
4545
setProvider("github.com");
4646
}
4747
}
48+
if (user) {
49+
if (!user?.rolesOrPermissions?.includes('teams-and-projects')) {
50+
(async () => {
51+
setUser(await getGitpodService().server.getLoggedInUser());
52+
})();
53+
54+
}
55+
}
4856
}, [user]);
4957

5058
useEffect(() => {
@@ -84,6 +92,13 @@ export default function NewProject() {
8492
(async () => {
8593
updateOrgsState();
8694
const repos = await updateReposInAccounts();
95+
96+
{ // automatically enable T&P
97+
if (!user?.rolesOrPermissions?.includes('teams-and-projects')) {
98+
setUser(await getGitpodService().server.getLoggedInUser());
99+
}
100+
}
101+
87102
const first = repos[0];
88103
if (first) {
89104
setSelectedAccount(first.account);

components/dashboard/src/teams/JoinTeam.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import { useContext, useEffect, useState } from "react";
88
import { useHistory } from "react-router-dom";
99
import { getGitpodService } from "../service/service";
10+
import { UserContext } from "../user-context";
1011
import { TeamsContext } from "./teams-context";
1112

1213
export default function() {
1314
const { setTeams } = useContext(TeamsContext);
15+
const { user, setUser } = useContext(UserContext);
1416
const history = useHistory();
1517

1618
const [ joinError, setJoinError ] = useState<Error>();
@@ -25,6 +27,13 @@ export default function() {
2527
const team = await getGitpodService().server.joinTeam(inviteId);
2628
const teams = await getGitpodService().server.getTeams();
2729
setTeams(teams);
30+
31+
{ // automatically enable T&P
32+
if (!user?.rolesOrPermissions?.includes('teams-and-projects')) {
33+
setUser(await getGitpodService().server.getLoggedInUser());
34+
}
35+
}
36+
2837
history.push(`/${team.slug}/members`);
2938
} catch (error) {
3039
console.error(error);

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,8 @@ export class GitpodServerEEImpl extends GitpodServerImpl<GitpodClient, GitpodSer
14991499
const cloneUrlsInUse = new Set(projects.map(p => p.cloneUrl));
15001500
repositories.forEach(r => { r.inUse = cloneUrlsInUse.has(r.cloneUrl) });
15011501

1502+
await this.ensureTeamsEnabled();
1503+
15021504
return repositories;
15031505
}
15041506

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,9 +1427,22 @@ export class GitpodServerImpl<Client extends GitpodClient, Server extends Gitpod
14271427
}
14281428
await this.teamDB.addMemberToTeam(user.id, invite.teamId);
14291429
const team = await this.teamDB.findTeamById(invite.teamId);
1430+
1431+
await this.ensureTeamsEnabled();
1432+
14301433
return team!;
14311434
}
14321435

1436+
protected async ensureTeamsEnabled() {
1437+
if (this.user && !this.user?.rolesOrPermissions?.includes('teams-and-projects')) {
1438+
this.user.rolesOrPermissions = [...(this.user.rolesOrPermissions || []), 'teams-and-projects'];
1439+
await this.userDB.updateUserPartial({
1440+
id: this.user.id,
1441+
rolesOrPermissions: this.user.rolesOrPermissions
1442+
})
1443+
}
1444+
}
1445+
14331446
public async setTeamMemberRole(teamId: string, userId: string, role: TeamMemberRole): Promise<void> {
14341447
this.checkAndBlockUser("setTeamMemberRole");
14351448
await this.guardTeamOperation(teamId, "update");

0 commit comments

Comments
 (0)