File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -278,6 +278,54 @@ class ThreadService extends BaseService {
278278 res . json ( { } ) ;
279279 }
280280 } ) . attach ( router ) ;
281+
282+ Endpoint ( {
283+ route : '/delete' ,
284+ methods : [ 'POST' ] ,
285+ mw : [ configurable_auth ( ) ] ,
286+ handler : async ( req , res ) => {
287+ const uid = req . body . uid ;
288+
289+ if ( ! is_valid_uuid ( uid ) ) {
290+ throw APIError . create ( 'field_invalid' , null , {
291+ key : 'uid' ,
292+ expected : 'uuid' ,
293+ got : whatis ( uid ) ,
294+ } ) ;
295+ }
296+
297+ // Get existing thread
298+ const thread = await this . get_thread ( { uid } ) ;
299+ if ( ! thread ) {
300+ throw APIError . create ( 'thread_not_found' , null , {
301+ uid,
302+ } ) ;
303+ }
304+
305+ const actor = Context . get ( 'actor' ) ;
306+
307+ // Check edit permission
308+ {
309+ const permission = PermissionUtil . join ( 'thread' , uid , 'delete' ) ;
310+ const svc_permission = this . services . get ( 'permission' ) ;
311+ const reading = await svc_permission . scan ( actor , permission ) ;
312+ const options = PermissionUtil . reading_to_options ( reading ) ;
313+ if ( options . length <= 0 ) {
314+ throw APIError . create ( 'permission_denied' , null , {
315+ permission,
316+ } ) ;
317+ }
318+ }
319+
320+ // Update thread
321+ await this . db . write (
322+ "DELETE FROM `thread` WHERE uid=?" ,
323+ [ uid ]
324+ ) ;
325+
326+ res . json ( { } ) ;
327+ }
328+ } ) . attach ( router ) ;
281329 }
282330
283331 async get_thread ( { uid } ) {
You can’t perform that action at this time.
0 commit comments