Diffdown is a real-time collaborative Markdown editor/previewer built on the AT Protocol diffdown.com

fix: show Share button for document owner by suppressing ownerDID in view template

+12 -5
+12 -5
internal/handler/handler.go
··· 270 270 } 271 271 272 272 // documentView is the shared implementation for viewing a document given an ownerDID and rkey. 273 - func (h *Handler) documentView(w http.ResponseWriter, r *http.Request, ownerUserID, ownerDID, rkey string) { 273 + // isOwner should be true when the current user owns the document; it suppresses the ownerDID 274 + // in the template so the edit button links to /docs/{rkey}/edit rather than the collaborator URL. 275 + func (h *Handler) documentView(w http.ResponseWriter, r *http.Request, ownerUserID, ownerDID, rkey string, isOwner bool) { 274 276 client, err := h.xrpcClient(ownerUserID) 275 277 if err != nil { 276 278 http.Error(w, "Could not connect to PDS", 500) ··· 301 303 Rendered template.HTML 302 304 OwnerDID string // non-empty when viewing a collaborator's document 303 305 } 306 + // Only set OwnerDID when the viewer is not the owner; the template uses 307 + // a non-empty OwnerDID to generate the collaborator edit URL. 308 + templateOwnerDID := ownerDID 309 + if isOwner { 310 + templateOwnerDID = "" 311 + } 304 312 h.render(w, "document_view.html", PageData{ 305 313 Title: doc.Title, 306 314 User: user, 307 - Content: DocumentViewData{Doc: doc, Rendered: template.HTML(rendered), OwnerDID: ownerDID}, 315 + Content: DocumentViewData{Doc: doc, Rendered: template.HTML(rendered), OwnerDID: templateOwnerDID}, 308 316 }) 309 317 } 310 318 ··· 322 330 http.Error(w, "Could not connect to PDS", 500) 323 331 return 324 332 } 325 - 326 - h.documentView(w, r, user.ID, client.DID(), rkey) 333 + h.documentView(w, r, user.ID, client.DID(), rkey, true) 327 334 } 328 335 329 336 // CollaboratorDocumentView renders a document owned by another user (collaborator access). ··· 343 350 return 344 351 } 345 352 346 - h.documentView(w, r, ownerUser.ID, ownerDID, rkey) 353 + h.documentView(w, r, ownerUser.ID, ownerDID, rkey, false) 347 354 } 348 355 349 356 // documentEdit is the shared implementation for the edit page.