Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix access rights for analyses #181

Merged
merged 10 commits into from
Jul 2, 2014
Merged

Conversation

squirrelo
Copy link
Contributor

Closes #147

This raises a RuntimeError if a person tries to access an Analysis they are not allowed to. This is for logging purposes.

This will also need to happen for Studies, but we don't have those pages yet.

ElDeveloper and others added 3 commits June 23, 2014 22:02
Note that this commit ports over the contents of the previously existing
repository.

Fixes qiita-spots#59
conn_handler = SQLConnectionHandler()
sql = ("SELECT analysis_id FROM qiita.{0} WHERE "
"{0}_analysis_id = %s".format(cls._table))
# MAGIC NUMBER 6: status id for a public study
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to currently avoid this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently no, but it is part of the Analysis object so it shouldn't be too big a problem, should it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, just wanted to be sure.

@antgonza
Copy link
Member

antgonza commented Jul 1, 2014

Added some comments.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.36%) when pulling 6817cd4 on squirrelo:issue-147 into 59e835c on biocore:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.36%) when pulling e1dca81 on squirrelo:issue-147 into 59e835c on biocore:master.

@antgonza
Copy link
Member

antgonza commented Jul 2, 2014

Could you add test to your code? I think that will be the only outstanding issue.

@squirrelo
Copy link
Contributor Author

There are currently no tests for anything tornado based/in qiita-pet, so that will go in in a separate pull request once the framework for doing so is figured out.

@antgonza
Copy link
Member

antgonza commented Jul 2, 2014

OK, could you comment what needs to be figured out?

@squirrelo
Copy link
Contributor Author

Tornado has its own built-in testing framework that can simulate page calls, asynchronous data pulls from other pages, and a few other key things. We have never used it so it will take probably half a day to a day of messing with it to figure out how it all works.

@antgonza
Copy link
Member

antgonza commented Jul 2, 2014

Got it, is not that we need to figure out how to test but the testing
framework. Can someone else check this PR so we can merge?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) when pulling 01a8622 on squirrelo:issue-147 into 59e835c on biocore:master.

RuntimeError
Tried to access analysis that user does not have access to
"""
if analysis_id not in set(Analysis.get_public() + user.shared_analyses +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the call to set is buying you anything here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added set creation time overwhelms the O(1) set lookup vs O(n) list lookup?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely, especially since these sets are likely to share few entries (private and public are disjoint, and shared is likely very small by comparison). A small test (which is not perfect, but meh):

>>> from timeit import Timer
>>> as_set = Timer('3 not in set(range(1000) + range(1001,1020) + range(1021,1061))')
>>> as_list = Timer('3 not in range(1000) + range(1001,1020) + range(1021,1061)') 
>>> as_set.repeat()
[51.94052219390869, 50.028679847717285, 50.24499797821045]
>>> as_list.repeat()
[17.484385013580322, 18.724167108535767, 18.87842297554016]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually really cool to know. Thanks. I'll fix that.

@adamrp
Copy link
Contributor

adamrp commented Jul 2, 2014

Just one comment. Looks good after it's addressed.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) when pulling 0b95cbe on squirrelo:issue-147 into 59e835c on biocore:master.

@squirrelo
Copy link
Contributor Author

Should be ready to merge.

@adamrp
Copy link
Contributor

adamrp commented Jul 2, 2014

Thanks @squirrelo! For the set creation thing that was in my last comment, note that if you were doing the lookup repeatedly (e.g., in a for loop), the set creation would be well worth it!

adamrp added a commit that referenced this pull request Jul 2, 2014
Fix access rights for analyses
@adamrp adamrp merged commit 23cff84 into qiita-spots:master Jul 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handlers accept IDs via GET request, but do not check authentication
5 participants