Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add blank group permission
Marc Seitz4d9c92e15757
diff --git a/components/datarooms/groups/add-member-modal.tsx b/components/datarooms/groups/add-member-modal.tsxindex 0e8ef2fa..0d328999 100644--- a/components/datarooms/groups/add-member-modal.tsx+++ b/components/datarooms/groups/add-member-modal.tsx@@ -14,6 +14,7 @@ import {DialogTrigger,} from "@/components/ui/dialog";import { Label } from "@/components/ui/label";+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";import { Textarea } from "@/components/ui/textarea";import { useAnalytics } from "@/lib/analytics";@@ -44,6 +45,11 @@ export function AddGroupMemberModal({);};+ // Domain validation regex pattern+ const validateDomain = (domain: string) => {+ return domain.match(/^@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/);+ };+const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {const inputValue = e.target.value;setInputValue(inputValue);@@ -53,15 +59,19 @@ export function AddGroupMemberModal({event.preventDefault();event.stopPropagation();- const emails = inputValue+ const inputs = inputValue.split(",")- .map((email) => email.trim().toLowerCase())- .filter((email) => email);+ .map((input) => input.trim().toLowerCase())+ .filter((input) => input);- if (emails.length === 0) return;+ if (inputs.length === 0) return;setLoading(true);+ // Separate domains and emails+ const domains = inputs.filter((input) => input.startsWith("@"));+ const emails = inputs.filter((input) => !input.startsWith("@"));+// validate emailsconst invalidEmails = emails.filter((email) => !validateEmail(email));if (invalidEmails.length > 0) {@@ -70,7 +80,17 @@ export function AddGroupMemberModal({return;}- // POST request with multiple emails+ // validate domains+ const invalidDomains = domains.filter((domain) => !validateDomain(domain));+ if (invalidDomains.length > 0) {+ setLoading(false);+ toast.error(+ "Found one or more invalid domains. Domains should be in format @example.org",+ );+ return;+ }++ // POST request with emails and domainsconst response = await fetch(`/api/teams/${teamId}/datarooms/${dataroomId}/groups/${groupId}/members`,{@@ -79,7 +99,8 @@ export function AddGroupMemberModal({"Content-Type": "application/json",},body: JSON.stringify({- emails: emails,+ emails,+ domains,}),},);@@ -93,7 +114,8 @@ export function AddGroupMemberModal({}analytics.capture("Dataroom Group Member Added", {- inviteeCount: emails.length,+ emailCount: emails.length,+ domainCount: domains.length,teamId: teamId,dataroomId: dataroomId,groupId: groupId,@@ -115,19 +137,20 @@ export function AddGroupMemberModal({<DialogTitle>Add members</DialogTitle></DialogHeader><form onSubmit={handleSubmit}>- <Label htmlFor="email">Email addresses</Label>+ <Label htmlFor="email">Email addresses or domains</Label><div className="flex flex-col gap-2 py-2 text-sm"><Textareavalue={inputValue}onChange={handleInputChange}rows={5}id="email"- placeholder="[email protected], [email protected]"+ placeholder="[email protected], [email protected], @example.org"className="flex-1 bg-muted"autoComplete="off"/><small className="text-xs text-muted-foreground">- Use comma to separate multiple email addresses.+ Use comma to separate multiple email addresses or domains. For+ domains, use format @example.org</small></div>diff --git a/components/datarooms/groups/group-member-table.tsx b/components/datarooms/groups/group-member-table.tsxindex f3df78d6..823bf4c6 100644--- a/components/datarooms/groups/group-member-table.tsx+++ b/components/datarooms/groups/group-member-table.tsx@@ -1,7 +1,12 @@import { useState } from "react";import { useTeam } from "@/context/team-context";-import { MoreHorizontalIcon, PlusCircleIcon, UserXIcon } from "lucide-react";+import {+ MoreHorizontalIcon,+ PlusCircleIcon,+ UserXIcon,+ XIcon,+} from "lucide-react";import { toast } from "sonner";import { mutate } from "swr";@@ -15,6 +20,7 @@ import {DropdownMenuTrigger,} from "@/components/ui/dropdown-menu";import { Skeleton } from "@/components/ui/skeleton";+import { Switch } from "@/components/ui/switch";import {Table,TableBody,@@ -38,10 +44,63 @@ export default function GroupMemberTable({}) {const teamInfo = useTeam();const teamId = teamInfo?.currentTeam?.id;- const { viewerGroupMembers } = useDataroomGroup();+ const { viewerGroupMembers, viewerGroupDomains, viewerGroupAllowAll } =+ useDataroomGroup();const [addMembersOpen, setAddMembersOpen] = useState<boolean>(false);+ const handleToggleAllowAll = async () => {+ const key = `/api/teams/${teamId}/datarooms/${dataroomId}/groups/${groupId}`;+ const response = await fetch(+ `/api/teams/${teamId}/datarooms/${dataroomId}/groups/${groupId}`,+ {+ method: "PATCH",+ body: JSON.stringify({+ allowAll: !viewerGroupAllowAll,+ }),+ headers: {+ "Content-Type": "application/json",+ },+ },+ );++ if (!response.ok) {+ mutate(key);+ toast.error("Failed to update group settings");+ return;+ }+ mutate(key);+ toast.success(+ viewerGroupAllowAll+ ? "Group access restricted to specific members and domains"+ : "Group now allows access from any email",+ );+ };++ const handleRemoveDomain = async (domain: string) => {+ const key = `/api/teams/${teamId}/datarooms/${dataroomId}/groups/${groupId}`;+ const response = await fetch(+ `/api/teams/${teamId}/datarooms/${dataroomId}/groups/${groupId}`,+ {+ method: "PATCH",+ body: JSON.stringify({+ domains: viewerGroupDomains.filter((d) => d !== domain),+ }),+ headers: {+ "Content-Type": "application/json",+ },+ },+ );++ if (!response.ok) {+ mutate(key);+ toast.error("Failed to remove domain");+ return;+ }+ mutate(key);+ toast.success("Domain removed successfully");+ };+const handleRemoveMember = async (id: string) => {// mutate the data optimisticallyconst key = `/api/teams/${teamId}/datarooms/${dataroomId}/groups/${groupId}`;@@ -80,14 +139,27 @@ export default function GroupMemberTable({<div className="l"><div className="mb-2 flex items-center justify-between md:mb-4"><h2>All members</h2>- <Button- size="sm"- onClick={() => setAddMembersOpen(true)}- className="h-8 gap-1"- >- <PlusCircleIcon className="h-4 w-4" />- Add members- </Button>+ <div className="flex items-center gap-4">+ <div className="flex items-center gap-2">+ <Switch+ checked={viewerGroupAllowAll}+ onCheckedChange={handleToggleAllowAll}+ aria-label="Allow all emails"+ />+ <span className="text-sm text-muted-foreground">+ Allow all emails+ </span>+ </div>+ <Button+ size="sm"+ onClick={() => setAddMembersOpen(true)}+ className="h-8 gap-1"+ disabled={viewerGroupAllowAll}+ >+ <PlusCircleIcon className="h-4 w-4" />+ Add members+ </Button>+ </div></div><AddGroupMemberModaldataroomId={dataroomId}@@ -108,80 +180,133 @@ export default function GroupMemberTable({</TableRow></TableHeader><TableBody>- {viewerGroupMembers.length === 0 && (+ {viewerGroupAllowAll ? (<TableRow>- <TableCell colSpan={5}>+ <TableCell colSpan={2}><div className="flex h-40 w-full items-center justify-center">- <p>No Data Available</p>+ <p className="text-sm text-muted-foreground">+ All email addresses are allowed to access this group+ </p></div></TableCell></TableRow>- )}- {viewerGroupMembers ? (- viewerGroupMembers.map((viewer) => (- <TableRow key={viewer.id} className="group/row">- {/* Name */}- <TableCell className="">- <div className="flex items-center overflow-visible sm:space-x-3">- <VisitorAvatar viewerEmail={viewer.viewer.email} />- <div className="min-w-0 flex-1">- <div className="focus:outline-none">- <p className="flex items-center gap-x-2 overflow-visible text-sm font-medium text-gray-800 dark:text-gray-200">- {viewer.viewer.email}- </p>- <p className="text-xs text-muted-foreground/60 sm:text-sm">- {/* {view.link.name ? view.link.name : view.linkId} */}- </p>- </div>- </div>- </div>- </TableCell>- {/* Last Viewed */}- {/* <TableCell className="text-sm text-muted-foreground">- <time- dateTime={new Date(viewer.viewer.updatedAt).toISOString()}- >- {viewer.viewer.updatedAt- ? timeAgo(viewer.viewer.updatedAt)- : "-"}- </time>- </TableCell> */}- {/* Actions */}- <TableCell className="p-0 text-center">- <DropdownMenu>- <DropdownMenuTrigger asChild>- <Button- variant="ghost"- className="h-8 w-8 p-0 group-hover/row:ring-1 group-hover/row:ring-gray-200 group-hover/row:dark:ring-gray-700"- >- <span className="sr-only">Open menu</span>- <MoreHorizontalIcon className="h-4 w-4" />- </Button>- </DropdownMenuTrigger>- <DropdownMenuContent align="end">- <DropdownMenuLabel>Actions</DropdownMenuLabel>- <DropdownMenuSeparator />- <DropdownMenuItem- className="gap-x-2 text-destructive focus:bg-destructive focus:text-destructive-foreground"- onClick={() => handleRemoveMember(viewer.id)}- >- <UserXIcon className="h-4 w-4" />- Remove Member- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>- </TableCell>- </TableRow>- ))- ) : (+ ) : viewerGroupMembers.length === 0 &&+ viewerGroupDomains.length === 0 ? (<TableRow>- <TableCell className="min-w-[100px]">- <Skeleton className="h-6 w-full" />- </TableCell>- <TableCell>- <Skeleton className="h-6 w-24" />+ <TableCell colSpan={2}>+ <div className="flex h-40 w-full items-center justify-center">+ <p>No Data Available</p>+ </div></TableCell></TableRow>+ ) : (+ <>+ {viewerGroupDomains.length > 0 &&+ viewerGroupDomains.map((domain) => (+ <TableRow key={domain} className="group/row">+ <TableCell className="">+ <div className="flex items-center overflow-visible sm:space-x-3">+ <VisitorAvatar viewerEmail={"@"} />+ <div className="min-w-0 flex-1">+ <div className="focus:outline-none">+ <p className="flex items-center gap-x-2 overflow-visible text-sm font-medium text-gray-800 dark:text-gray-200">+ {domain}+ </p>+ </div>+ </div>+ </div>+ </TableCell>+ {/* Actions */}+ <TableCell className="p-0 text-center">+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ variant="ghost"+ className="h-8 w-8 p-0 group-hover/row:ring-1 group-hover/row:ring-gray-200 group-hover/row:dark:ring-gray-700"+ >+ <span className="sr-only">Open menu</span>+ <MoreHorizontalIcon className="h-4 w-4" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuLabel>Actions</DropdownMenuLabel>+ <DropdownMenuSeparator />+ <DropdownMenuItem+ className="gap-x-2 text-destructive focus:bg-destructive focus:text-destructive-foreground"+ onClick={() => handleRemoveDomain(domain)}+ >+ <XIcon className="h-4 w-4" />+ Remove Domain+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </TableCell>+ </TableRow>+ ))}+ {viewerGroupMembers ? (+ viewerGroupMembers.map((viewer) => (+ <TableRow key={viewer.id} className="group/row">+ {/* Name */}+ <TableCell className="">+ <div className="flex items-center overflow-visible sm:space-x-3">+ <VisitorAvatar viewerEmail={viewer.viewer.email} />+ <div className="min-w-0 flex-1">+ <div className="focus:outline-none">+ <p className="flex items-center gap-x-2 overflow-visible text-sm font-medium text-gray-800 dark:text-gray-200">+ {viewer.viewer.email}+ </p>+ </div>+ </div>+ </div>+ </TableCell>+ {/* Last Viewed */}+ {/* <TableCell className="text-sm text-muted-foreground">+ <time+ dateTime={new Date(viewer.viewer.updatedAt).toISOString()}+ >+ {viewer.viewer.updatedAt+ ? timeAgo(viewer.viewer.updatedAt)+ : "-"}+ </time>+ </TableCell> */}+ {/* Actions */}+ <TableCell className="p-0 text-center">+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ variant="ghost"+ className="h-8 w-8 p-0 group-hover/row:ring-1 group-hover/row:ring-gray-200 group-hover/row:dark:ring-gray-700"+ >+ <span className="sr-only">Open menu</span>+ <MoreHorizontalIcon className="h-4 w-4" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuLabel>Actions</DropdownMenuLabel>+ <DropdownMenuSeparator />+ <DropdownMenuItem+ className="gap-x-2 text-destructive focus:bg-destructive focus:text-destructive-foreground"+ onClick={() => handleRemoveMember(viewer.id)}+ >+ <UserXIcon className="h-4 w-4" />+ Remove Member+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </TableCell>+ </TableRow>+ ))+ ) : (+ <TableRow>+ <TableCell className="min-w-[100px]">+ <Skeleton className="h-6 w-full" />+ </TableCell>+ <TableCell>+ <Skeleton className="h-6 w-24" />+ </TableCell>+ </TableRow>+ )}+ </>)}</TableBody></Table>diff --git a/lib/swr/use-dataroom-groups.ts b/lib/swr/use-dataroom-groups.tsindex 6641e734..988da604 100644--- a/lib/swr/use-dataroom-groups.ts+++ b/lib/swr/use-dataroom-groups.ts@@ -78,6 +78,8 @@ export function useDataroomGroup() {return {viewerGroup,viewerGroupMembers: viewerGroup?.members ?? [],+ viewerGroupDomains: viewerGroup?.domains ?? [],+ viewerGroupAllowAll: viewerGroup?.allowAll ?? false,viewerGroupPermissions: viewerGroup?.accessControls ?? [],loading: !viewerGroup && !error,error,diff --git a/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/index.tsindex 539eeb77..9035c969 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/index.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/index.ts@@ -89,7 +89,11 @@ export default async function handle(groupId: string;};- const { name } = req.body as { name: string };+ const { name, domains, allowAll } = req.body as {+ name?: string;+ domains?: string[];+ allowAll?: boolean;+ };const userId = (session.user as CustomUser).id;try {@@ -97,9 +101,19 @@ export default async function handle(where: {id: groupId,dataroomId: dataroomId,+ teamId: teamId,+ team: {+ users: {+ some: {+ userId: userId,+ },+ },+ },},data: {- name,+ ...(name && { name }),+ ...(typeof allowAll === "boolean" && { allowAll }),+ ...(domains && { domains }),},});diff --git a/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/members/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/members/index.tsindex 14e24f97..3f486989 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/members/index.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/members/index.ts@@ -29,7 +29,11 @@ export default async function handle(groupId: string;};- const { emails } = req.body as { emails: string[] };+ const { emails, domains, allowAll } = req.body as {+ emails: string[];+ domains: string[];+ allowAll: boolean;+ };try {// Check if the user is part of the team@@ -87,6 +91,12 @@ export default async function handle(})),});+ // Update the group with the new domains and allowAll setting+ await prisma.viewerGroup.update({+ where: { id: groupId },+ data: { domains, allowAll },+ });+res.status(201).json(members);} catch (error) {console.error("Request error", error);diff --git a/pages/api/views-dataroom.ts b/pages/api/views-dataroom.tsindex bc9176f7..83980029 100644--- a/pages/api/views-dataroom.ts+++ b/pages/api/views-dataroom.ts@@ -231,7 +231,11 @@ export default async function handle(if (link.audienceType === LinkAudienceType.GROUP && link.groupId) {const group = await prisma.viewerGroup.findUnique({where: { id: link.groupId },- select: { members: { include: { viewer: { select: { email: true } } } } },+ select: {+ members: { include: { viewer: { select: { email: true } } } },+ domains: true,+ allowAll: true,+ },});if (!group) {@@ -239,12 +243,26 @@ export default async function handle(return;}- const isMember = group.members.some(- (member) => member.viewer.email === email,- );- if (!isMember) {- res.status(403).json({ message: "Unauthorized access" });- return;+ // Check if all emails are allowed+ if (group.allowAll) {+ // Allow access+ } else {+ // Check individual membership+ const isMember = group.members.some(+ (member) => member.viewer.email === email,+ );++ // Extract domain from email+ const emailDomain = email.substring(email.lastIndexOf("@"));+ // Check domain access+ const hasDomainAccess = group.domains.some(+ (domain) => domain === emailDomain,+ );++ if (!isMember && !hasDomainAccess) {+ res.status(403).json({ message: "Unauthorized access" });+ return;+ }}}