AI-Assisted Coding Lab · Add Expiring Share Links

45:00left of 45:00

Add Expiring Share Links

Designers want to share a design with people outside their team through links that expire and can be revoked. The README has the rules, and share_links.py has the data model. Build it with the assistant and decide what to keep.

share_links.py1 of 3

Files

share_links.py

Python · Editable
from dataclasses import dataclass
@dataclass
class ShareLink:
token: str
design_id: str
role: str # "view" or "edit"
expires_at: float
revoked: bool = False
class ShareLinks:
"""Share links for designs. Anyone holding a token can open the design with the link's role."""
def __init__(self, clock):
self.clock = clock
self.links = {} # token -> ShareLink
def create_link(self, design_id, role, ttl_s):
"""Creates a link and returns its token. Tokens appear in public URLs."""
now = self.clock()
raise NotImplementedError
def resolve(self, token):
"""Returns (design_id, role) for a usable token, or None."""
raise NotImplementedError
def revoke(self, token):
link = self.links.get(token)
if link:
link.revoked = True

Test Output

No runs yet.

Assistant

Scripted
  1. Send the first prompt to start.

Next Prompt

Write create_link. Store the link and return its token.