@@ -514,6 +514,26 @@ def pmid(self, pmid):
514
514
qdb .sql_connection .TRN .add (sql , [pmid , self ._id ])
515
515
qdb .sql_connection .TRN .execute ()
516
516
517
+ @property
518
+ def can_be_publicized (self ):
519
+ """Returns whether the analysis can be made public
520
+
521
+ Returns
522
+ -------
523
+ bool
524
+ Whether the analysis can be publicized or not
525
+ """
526
+ # The analysis can be made public if all the artifacts used
527
+ # to get the samples from are public
528
+ with qdb .sql_connection .TRN :
529
+ sql = """SELECT DISTINCT artifact_id
530
+ FROM qiita.analysis_sample
531
+ WHERE analysis_id = %s"""
532
+ qdb .sql_connection .TRN .add (sql , [self .id ])
533
+ return all (
534
+ [qdb .artifact .Artifact (aid ).visibility == 'public'
535
+ for aid in qdb .sql_connection .TRN .execute_fetchflatten ()])
536
+
517
537
def add_artifact (self , artifact ):
518
538
"""Adds an artifact to the analysis
519
539
@@ -570,6 +590,24 @@ def has_access(self, user):
570
590
return self in Analysis .get_by_status ('public' ) | \
571
591
user .private_analyses | user .shared_analyses
572
592
593
+ def can_edit (self , user ):
594
+ """Returns whether the given user can edit the analysis
595
+
596
+ Parameters
597
+ ----------
598
+ user : User object
599
+ User we are checking edit permissions for
600
+
601
+ Returns
602
+ -------
603
+ bool
604
+ Whether user can edit the study or not
605
+ """
606
+ # The analysis is editable only if the user is the owner, is in the
607
+ # shared list or the user is an admin
608
+ return (user .level in {'superuser' , 'admin' } or self .owner == user or
609
+ user in self .shared_with )
610
+
573
611
def summary_data (self ):
574
612
"""Return number of studies, artifacts, and samples selected
575
613
0 commit comments