mirror of
https://github.com/baserow/baserow.git
synced 2026-12-05 00:38:35 +00:00
* fix: accept workspace invitations only with the emailed token or a verified email Accepting by id only compared the username with the invited address, which anyone can register without verifying it. The emailed token now proves ownership and verifies the email; without it, the user's email has to be verified. * fix: require a verified email to reject invitations and keep accept visible Rejecting still only checked the username, so whoever registered the invited address could delete the invitation. Accept stays visible after a verification error so it works once the email is verified. * fix: hide accept for unverified users, allow reject, skip the check without SMTP Without an email backend neither the invitation nor a verification email arrives, so the check can't be met. Signing up from the invitation link verifies the email, so the user is signed in even when verification is enforced. * fix: leaving a workspace hangs and removing the current user deletes the wrong workspace
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { getClient } from "../client";
|
|
import { waitForInvitationToken } from "./mail";
|
|
import { User } from "./user";
|
|
|
|
export class Workspace {
|
|
constructor(public id: number, public name: string, public user: User) {}
|
|
}
|
|
export async function createWorkspace(
|
|
user: User,
|
|
name: String = "Default workspace"
|
|
): Promise<Workspace> {
|
|
const response: any = await getClient(user).post("workspaces/", { name });
|
|
const workspaceData = response.data;
|
|
return new Workspace(workspaceData.id, workspaceData.name, user);
|
|
}
|
|
|
|
/**
|
|
* Adds an existing user to a workspace. There is no endpoint that adds a
|
|
* member outright, so this invites them and accepts on their behalf.
|
|
*/
|
|
export async function addUserToWorkspace(
|
|
inviter: User,
|
|
workspace: Workspace,
|
|
invitee: User,
|
|
permissions: "ADMIN" | "MEMBER" = "MEMBER"
|
|
): Promise<void> {
|
|
const invitation: any = await getClient(inviter).post(
|
|
`workspaces/invitations/workspace/${workspace.id}/`,
|
|
{
|
|
email: invitee.email,
|
|
permissions,
|
|
}
|
|
);
|
|
await getClient(invitee).post(
|
|
`workspaces/invitations/${invitation.data.id}/accept/`,
|
|
{ token: await waitForInvitationToken(invitee.email) }
|
|
);
|
|
}
|
|
|
|
export async function getUsersFirstWorkspace(user: User): Promise<Workspace> {
|
|
const response: any = await getClient(user).get("workspaces/", {});
|
|
let firstWorkspaceData = response.data[0];
|
|
return new Workspace(firstWorkspaceData.id, firstWorkspaceData.name, user);
|
|
}
|