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

Enable Teams & Projects on joining of a team #5477

Merged
merged 1 commit into from
Sep 1, 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
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());
})();

}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You could simplify this Effect's 🍝 code a bit by adding if (!user) { return; } at the top. (Also the empty line is unnecessary. 😇)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd love to see that PR reverted rather soon, i.e. getting to general availability of Teams & Projects. I would be great to just revert this PR by then with less effort. WDYT?

}, [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
})
}
}
jankeromnes marked this conversation as resolved.
Show resolved Hide resolved

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