@@ -330,6 +330,88 @@ def verify_code(cls, email, code, code_type):
330
330
331
331
return correct_code
332
332
333
+ @classmethod
334
+ def delete (cls , email , force = False ):
335
+ if not cls .exists (email ):
336
+ raise IncorrectEmailError (f'This email does not exist: { email } ' )
337
+
338
+ tables = ['qiita.study_users' , 'qiita.study_tags' ,
339
+ 'qiita.processing_job_workflow' , 'qiita.processing_job' ,
340
+ 'qiita.message_user' , 'qiita.analysis_users' ,
341
+ 'qiita.analysis' ]
342
+
343
+ not_empty = []
344
+ for t in tables :
345
+ with qdb .sql_connection .TRN :
346
+ sql = f"SELECT COUNT(email) FROM { t } WHERE email = %s"
347
+ qdb .sql_connection .TRN .add (sql , [email ])
348
+ count = qdb .sql_connection .TRN .execute_fetchflatten ()[0 ]
349
+ if count != 0 :
350
+ not_empty .append (t )
351
+
352
+ if not_empty and not force :
353
+ raise ValueError (f'These tables are not empty: "{ not_empty } ", '
354
+ 'delete them first or use `force=True`' )
355
+
356
+ sql = """
357
+ DELETE FROM qiita.study_users WHERE email = %(email)s;
358
+ DELETE FROM qiita.study_tags WHERE email = %(email)s;
359
+ DELETE FROM qiita.processing_job_workflow_root
360
+ WHERE processing_job_workflow_id IN (
361
+ SELECT processing_job_workflow_id
362
+ FROM qiita.processing_job_workflow
363
+ WHERE email = %(email)s);
364
+ DELETE FROM qiita.processing_job_workflow WHERE email = %(email)s;
365
+ DELETE FROM qiita.processing_job_validator
366
+ WHERE processing_job_id IN (
367
+ SELECT processing_job_id
368
+ FROM qiita.processing_job
369
+ WHERE email = %(email)s);
370
+ DELETE FROM qiita.analysis_processing_job
371
+ WHERE processing_job_id IN (
372
+ SELECT processing_job_id
373
+ FROM qiita.processing_job
374
+ WHERE email = %(email)s);
375
+ DELETE FROM qiita.artifact_output_processing_job
376
+ WHERE processing_job_id IN (
377
+ SELECT processing_job_id
378
+ FROM qiita.processing_job
379
+ WHERE email = %(email)s);
380
+ DELETE FROM qiita.artifact_processing_job
381
+ WHERE processing_job_id IN (
382
+ SELECT processing_job_id
383
+ FROM qiita.processing_job
384
+ WHERE email = %(email)s);
385
+ DELETE FROM qiita.parent_processing_job WHERE parent_id IN (
386
+ SELECT processing_job_id
387
+ FROM qiita.processing_job
388
+ WHERE email = %(email)s);
389
+ DELETE FROM qiita.processing_job WHERE email = %(email)s;
390
+ DELETE FROM qiita.message_user WHERE email = %(email)s;
391
+ DELETE FROM qiita.analysis_users WHERE email = %(email)s;
392
+ DELETE FROM qiita.analysis_portal WHERE analysis_id IN (
393
+ SELECT analysis_id
394
+ FROM qiita.analysis
395
+ WHERE email = %(email)s);
396
+ DELETE FROM qiita.analysis_artifact WHERE analysis_id IN (
397
+ SELECT analysis_id
398
+ FROM qiita.analysis
399
+ WHERE email = %(email)s);
400
+ DELETE FROM qiita.analysis_filepath WHERE analysis_id IN (
401
+ SELECT analysis_id
402
+ FROM qiita.analysis
403
+ WHERE email = %(email)s);
404
+ DELETE FROM qiita.analysis_sample WHERE analysis_id IN (
405
+ SELECT analysis_id
406
+ FROM qiita.analysis
407
+ WHERE email = %(email)s);
408
+ DELETE FROM qiita.analysis WHERE email = %(email)s;
409
+ DELETE FROM qiita.qiita_user WHERE email = %(email)s;"""
410
+
411
+ with qdb .sql_connection .TRN :
412
+ qdb .sql_connection .TRN .add (sql , {'email' : email })
413
+ qdb .sql_connection .TRN .execute ()
414
+
333
415
# ---properties---
334
416
@property
335
417
def email (self ):
0 commit comments