Time on this item: 0:00
Who can edit a document
The task given to the agent
Return whether user may edit doc. Owners and admins may; archived docs are admin-only; suspended users may edit nothing.
Write canEditDocument(user, doc), which returns true if the user may edit the document and false otherwise. A user may edit a document they own (doc.ownerId is their id). An admin may edit any document, including archived ones. Nobody except an admin may edit an archived document, not even its owner. A suspended user may edit nothing, whatever their role and whoever owns the document.
The code it wrote
One line is wrong, or none is.
Line 1:
export interface User {Line 2:
id: string;Line 3:
role: "admin" | "member";Line 4:
suspended: boolean;Line 5:
}Line 6, blank:
Line 7:
export interface Doc {Line 8:
id: string;Line 9:
ownerId: string;Line 10:
archived: boolean;Line 11:
}Line 12, blank:
Line 13:
export function canEditDocument(user: User, doc: Doc): boolean {Line 14:
if (user.suspended) return false;Line 15:
if (user.role === "admin") return true;Line 16:
if (doc.archived) return false;Line 17:
return doc.ownerId !== user.id;Line 18:
}