File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,16 @@ describe("#urls.unfurl", () => {
143143 expect ( body . name ) . toEqual ( mentionedUser . name ) ;
144144 } ) ;
145145
146+ it ( "should return 204 when internal document url points to non-existent document" , async ( ) => {
147+ const res = await server . post ( "/api/urls.unfurl" , {
148+ body : {
149+ token : user . getJwtToken ( ) ,
150+ url : `${ env . URL } /doc/non-existent-doc-abc123` ,
151+ } ,
152+ } ) ;
153+ expect ( res . status ) . toEqual ( 204 ) ;
154+ } ) ;
155+
146156 it ( "should succeed with status 200 ok when valid document url is supplied" , async ( ) => {
147157 const document = await buildDocument ( {
148158 teamId : user . teamId ,
Original file line number Diff line number Diff line change @@ -164,10 +164,10 @@ router.post(
164164 const document = await Document . findByPk ( previewDocumentId , {
165165 userId : actor . id ,
166166 } ) ;
167- if ( ! document ) {
168- throw NotFoundError ( "Document does not exist" ) ;
167+ if ( ! document || ! can ( actor , "read" , document ) ) {
168+ ctx . response . status = 204 ;
169+ return ;
169170 }
170- authorize ( actor , "read" , document ) ;
171171
172172 ctx . body = await presentUnfurl ( {
173173 type : UnfurlResourceType . Document ,
You can’t perform that action at this time.
0 commit comments