-
Notifications
You must be signed in to change notification settings - Fork 80
Improving analysis listing #2170
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
Merged
ElDeveloper
merged 2 commits into
qiita-spots:analysis-refactor
from
antgonza:improving-analysis-listing-A
Jul 18, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (c) 2014--, The Qiita Development Team. | ||
# | ||
# Distributed under the terms of the BSD 3-clause License. | ||
# | ||
# The full license is in the file LICENSE, distributed with this software. | ||
# ----------------------------------------------------------------------------- | ||
|
||
from json import dumps | ||
|
||
from tornado.web import authenticated, HTTPError | ||
from tornado.gen import coroutine, Task | ||
|
||
from qiita_core.qiita_settings import qiita_config | ||
from qiita_core.util import execute_as_transaction | ||
from qiita_pet.handlers.base_handlers import BaseHandler | ||
from qiita_pet.handlers.util import get_shared_links | ||
from qiita_db.user import User | ||
from qiita_db.analysis import Analysis | ||
from qiita_db.util import add_message | ||
|
||
|
||
class ShareAnalysisAJAX(BaseHandler): | ||
@execute_as_transaction | ||
def _get_shared_for_study(self, analysis, callback): | ||
shared_links = get_shared_links(analysis) | ||
users = [u.email for u in analysis.shared_with] | ||
callback((users, shared_links)) | ||
|
||
@execute_as_transaction | ||
def _share(self, analysis, user, callback): | ||
user = User(user) | ||
add_message('Analysis <a href="%s/analysis/results/%d">\'%s\'</a> ' | ||
'has been shared with you.' % | ||
(qiita_config.portal_dir, analysis.id, analysis.name), | ||
[user]) | ||
callback(analysis.share(user)) | ||
|
||
@execute_as_transaction | ||
def _unshare(self, analysis, user, callback): | ||
user = User(user) | ||
add_message('Analysis \'%s\' has been unshared with you.' % | ||
analysis.name, [user]) | ||
callback(analysis.unshare(user)) | ||
|
||
@authenticated | ||
@coroutine | ||
@execute_as_transaction | ||
def get(self): | ||
analysis_id = int(self.get_argument('id')) | ||
analysis = Analysis(analysis_id) | ||
if self.current_user != analysis.owner and \ | ||
self.current_user not in analysis.shared_with: | ||
raise HTTPError(403, 'User %s does not have permissions to share ' | ||
'analysis %s' % ( | ||
self.current_user.id, analysis.id)) | ||
|
||
selected = self.get_argument('selected', None) | ||
deselected = self.get_argument('deselected', None) | ||
|
||
if selected is not None: | ||
yield Task(self._share, analysis, selected) | ||
if deselected is not None: | ||
yield Task(self._unshare, analysis, deselected) | ||
|
||
users, links = yield Task(self._get_shared_for_study, analysis) | ||
|
||
self.write(dumps({'users': users, 'links': links})) |
59 changes: 59 additions & 0 deletions
59
qiita_pet/handlers/analysis_handlers/tests/test_sharing_handlers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (c) 2014--, The Qiita Development Team. | ||
# | ||
# Distributed under the terms of the BSD 3-clause License. | ||
# | ||
# The full license is in the file LICENSE, distributed with this software. | ||
# ----------------------------------------------------------------------------- | ||
|
||
from unittest import main | ||
from json import loads | ||
|
||
from qiita_db.analysis import Analysis | ||
from qiita_db.user import User | ||
from qiita_pet.test.tornado_test_base import TestHandlerBase | ||
|
||
|
||
class TestShareStudyAjax(TestHandlerBase): | ||
|
||
def test_get(self): | ||
a = Analysis(1) | ||
u = User('shared@foo.bar') | ||
self.assertEqual(a.shared_with, [u]) | ||
|
||
# deselecting | ||
args = {'deselected': u.id, 'id': a.id} | ||
response = self.get('/analysis/sharing/', args) | ||
self.assertEqual(response.code, 200) | ||
exp = {'users': [], 'links': ''} | ||
self.assertEqual(loads(response.body), exp) | ||
self.assertEqual(a.shared_with, []) | ||
|
||
# Make sure unshared message added to the system | ||
self.assertEqual("Analysis 'SomeAnalysis' has been unshared with you.", | ||
u.messages()[0][1]) | ||
|
||
# selecting | ||
args = {'selected': u.id, 'id': a.id} | ||
response = self.get('/analysis/sharing/', args) | ||
self.assertEqual(response.code, 200) | ||
exp = { | ||
'users': ['shared@foo.bar'], | ||
'links': | ||
('<a target="_blank" href="mailto:shared@foo.bar">Shared</a>')} | ||
self.assertEqual(loads(response.body), exp) | ||
self.assertEqual(a.shared_with, [u]) | ||
|
||
# Make sure shared message added to the system | ||
self.assertEqual('Analysis <a href="/analysis/results/1">\'SomeAnalys' | ||
'is\'</a> has been shared with you.', | ||
u.messages()[0][1]) | ||
|
||
def test_get_no_access(self): | ||
args = {'selected': 'demo@microbio.me', 'id': 2} | ||
response = self.get('/analysis/sharing/', args) | ||
self.assertEqual(response.code, 403) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When analyses are unshared the output data should be either empty or include a "completed" message. We were doing this for the portion of the REST API that @wasade and I worked on. Seemed clean and you don't really need an empty list of
users
orlinks
. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a fair point and perhaps worth it. Note that this will imply that we will need to have 2 calls for the same functionality as right now the call actually also changes the display so the new code will have to be: delete/add user, request current values.
Now, based on (1) this code/mechanism is based on Artifact sharing, which means that we will need to change both to be complete and (2) that what I did is simply return these deleted lines from this branch + add some tests; I also believe that this is out of the scope of this PR and opening an issue for further discussion is the best path forward. See #2171.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, sounds good!