Skip to content

Commit

Permalink
Merge pull request #2122 from antgonza/user-kept-public-study
Browse files Browse the repository at this point in the history
public studies are being shown in the user own studies
  • Loading branch information
josenavas committed Apr 29, 2017
2 parents b5c7fd5 + 219f479 commit 50bfc4a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
9 changes: 5 additions & 4 deletions qiita_pet/handlers/study_handlers/listing_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ def _build_study_info(user, search_type, study_proc=None, proc_samples=None):
build_samples = True

# get list of studies for table
user_study_set = user.user_studies.union(user.shared_studies)
if search_type == 'user':
user_study_set = user.user_studies.union(user.shared_studies)
if user.level == 'admin':
user_study_set = (user_study_set |
Study.get_by_status('sandbox') |
Study.get_by_status('private'))
study_set = user_study_set - Study.get_by_status('public')
Study.get_by_status('private') -
Study.get_by_status('public'))
study_set = user_study_set
elif search_type == 'public':
study_set = Study.get_by_status('public')
study_set = Study.get_by_status('public') - user_study_set
else:
raise ValueError('Not a valid search type')
if study_proc is not None:
Expand Down
27 changes: 27 additions & 0 deletions qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,36 @@ def setUp(self):
self.exp = [self.single_exp]

def test_build_study_info(self):
for a in Study(1).artifacts():
a.visibility = 'private'

obs = _build_study_info(User('test@foo.bar'), 'user')
self.assertEqual(obs, self.exp)

obs = _build_study_info(User('test@foo.bar'), 'public')
self.assertEqual(obs, [])

obs = _build_study_info(User('demo@microbio.me'), 'public')
self.assertEqual(obs, [])

# make all the artifacts public - (1) the only study in the tests,
for a in Study(1).artifacts():
a.visibility = 'public'
self.exp[0]['status'] = 'public'

obs = _build_study_info(User('test@foo.bar'), 'user')
self.assertEqual(obs, self.exp)

obs = _build_study_info(User('test@foo.bar'), 'public')
self.assertEqual(obs, [])

obs = _build_study_info(User('demo@microbio.me'), 'public')
self.assertEqual(obs, self.exp)

# return to it's private status
for a in Study(1).artifacts():
a.visibility = 'private'

def test_build_study_info_erros(self):
with self.assertRaises(IncompetentQiitaDeveloperError):
_build_study_info(User('test@foo.bar'), 'user', study_proc={})
Expand Down

0 comments on commit 50bfc4a

Please sign in to comment.