Skip to content

Commit 50bfc4a

Browse files
authored
Merge pull request #2122 from antgonza/user-kept-public-study
public studies are being shown in the user own studies
2 parents b5c7fd5 + 219f479 commit 50bfc4a

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

qiita_pet/handlers/study_handlers/listing_handlers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ def _build_study_info(user, search_type, study_proc=None, proc_samples=None):
7171
build_samples = True
7272

7373
# get list of studies for table
74+
user_study_set = user.user_studies.union(user.shared_studies)
7475
if search_type == 'user':
75-
user_study_set = user.user_studies.union(user.shared_studies)
7676
if user.level == 'admin':
7777
user_study_set = (user_study_set |
7878
Study.get_by_status('sandbox') |
79-
Study.get_by_status('private'))
80-
study_set = user_study_set - Study.get_by_status('public')
79+
Study.get_by_status('private') -
80+
Study.get_by_status('public'))
81+
study_set = user_study_set
8182
elif search_type == 'public':
82-
study_set = Study.get_by_status('public')
83+
study_set = Study.get_by_status('public') - user_study_set
8384
else:
8485
raise ValueError('Not a valid search type')
8586
if study_proc is not None:

qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,36 @@ def setUp(self):
8484
self.exp = [self.single_exp]
8585

8686
def test_build_study_info(self):
87+
for a in Study(1).artifacts():
88+
a.visibility = 'private'
89+
8790
obs = _build_study_info(User('test@foo.bar'), 'user')
8891
self.assertEqual(obs, self.exp)
8992

93+
obs = _build_study_info(User('test@foo.bar'), 'public')
94+
self.assertEqual(obs, [])
95+
96+
obs = _build_study_info(User('demo@microbio.me'), 'public')
97+
self.assertEqual(obs, [])
98+
99+
# make all the artifacts public - (1) the only study in the tests,
100+
for a in Study(1).artifacts():
101+
a.visibility = 'public'
102+
self.exp[0]['status'] = 'public'
103+
104+
obs = _build_study_info(User('test@foo.bar'), 'user')
105+
self.assertEqual(obs, self.exp)
106+
107+
obs = _build_study_info(User('test@foo.bar'), 'public')
108+
self.assertEqual(obs, [])
109+
110+
obs = _build_study_info(User('demo@microbio.me'), 'public')
111+
self.assertEqual(obs, self.exp)
112+
113+
# return to it's private status
114+
for a in Study(1).artifacts():
115+
a.visibility = 'private'
116+
90117
def test_build_study_info_erros(self):
91118
with self.assertRaises(IncompetentQiitaDeveloperError):
92119
_build_study_info(User('test@foo.bar'), 'user', study_proc={})

0 commit comments

Comments
 (0)