Skip to content

Commit

Permalink
[teams] enable features on joining of a team
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTugarev authored and roboquat committed Sep 1, 2021
1 parent 6bc80eb commit a4f3803
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions components/dashboard/src/projects/NewProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export default function NewProject() {
setProvider("github.com");
}
}
if (user) {
if (!user?.rolesOrPermissions?.includes('teams-and-projects')) {
(async () => {
setUser(await getGitpodService().server.getLoggedInUser());
})();

}
}
}, [user]);

useEffect(() => {
Expand Down Expand Up @@ -84,6 +92,13 @@ export default function NewProject() {
(async () => {
updateOrgsState();
const repos = await updateReposInAccounts();

{ // automatically enable T&P
if (!user?.rolesOrPermissions?.includes('teams-and-projects')) {
setUser(await getGitpodService().server.getLoggedInUser());
}
}

const first = repos[0];
if (first) {
setSelectedAccount(first.account);
Expand Down
9 changes: 9 additions & 0 deletions components/dashboard/src/teams/JoinTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import { useContext, useEffect, useState } from "react";
import { useHistory } from "react-router-dom";
import { getGitpodService } from "../service/service";
import { UserContext } from "../user-context";
import { TeamsContext } from "./teams-context";

export default function() {
const { setTeams } = useContext(TeamsContext);
const { user, setUser } = useContext(UserContext);
const history = useHistory();

const [ joinError, setJoinError ] = useState<Error>();
Expand All @@ -25,6 +27,13 @@ export default function() {
const team = await getGitpodService().server.joinTeam(inviteId);
const teams = await getGitpodService().server.getTeams();
setTeams(teams);

{ // automatically enable T&P
if (!user?.rolesOrPermissions?.includes('teams-and-projects')) {
setUser(await getGitpodService().server.getLoggedInUser());
}
}

history.push(`/${team.slug}/members`);
} catch (error) {
console.error(error);
Expand Down
2 changes: 2 additions & 0 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,8 @@ export class GitpodServerEEImpl extends GitpodServerImpl<GitpodClient, GitpodSer
const cloneUrlsInUse = new Set(projects.map(p => p.cloneUrl));
repositories.forEach(r => { r.inUse = cloneUrlsInUse.has(r.cloneUrl) });

await this.ensureTeamsEnabled();

return repositories;
}

Expand Down
13 changes: 13 additions & 0 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1427,9 +1427,22 @@ export class GitpodServerImpl<Client extends GitpodClient, Server extends Gitpod
}
await this.teamDB.addMemberToTeam(user.id, invite.teamId);
const team = await this.teamDB.findTeamById(invite.teamId);

await this.ensureTeamsEnabled();

return team!;
}

protected async ensureTeamsEnabled() {
if (this.user && !this.user?.rolesOrPermissions?.includes('teams-and-projects')) {
this.user.rolesOrPermissions = [...(this.user.rolesOrPermissions || []), 'teams-and-projects'];
await this.userDB.updateUserPartial({
id: this.user.id,
rolesOrPermissions: this.user.rolesOrPermissions
})
}
}

public async setTeamMemberRole(teamId: string, userId: string, role: TeamMemberRole): Promise<void> {
this.checkAndBlockUser("setTeamMemberRole");
await this.guardTeamOperation(teamId, "update");
Expand Down

0 comments on commit a4f3803

Please sign in to comment.