1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/f65eb16fdf1e/ Changeset: f65eb16fdf1e User: greg Date: 2014-07-17 21:41:56 Summary: Eliminate the use of trans in the tool shed's review_util.py module. Affected #: 3 files diff -r 49e900b2a87108eb1e8b2bbea8a1bf6daedd6328 -r f65eb16fdf1e0b7a6f3483373c32765107c3b2b6 lib/galaxy/webapps/tool_shed/controllers/repository_review.py --- a/lib/galaxy/webapps/tool_shed/controllers/repository_review.py +++ b/lib/galaxy/webapps/tool_shed/controllers/repository_review.py @@ -34,7 +34,7 @@ message = kwd.get( 'message', '' ) status = kwd.get( 'status', 'done' ) encoded_review_id = kwd[ 'id' ] - review = review_util.get_review( trans, encoded_review_id ) + review = review_util.get_review( trans.app, encoded_review_id ) if kwd.get( 'approve_repository_review_button', False ): approved_select_field_name = '%s%sapproved' % ( encoded_review_id, STRSEP ) approved_select_field_value = str( kwd[ approved_select_field_name ] ) @@ -67,7 +67,7 @@ def browse_review( self, trans, **kwd ): message = kwd.get( 'message', '' ) status = kwd.get( 'status', 'done' ) - review = review_util.get_review( trans, kwd[ 'id' ] ) + review = review_util.get_review( trans.app, kwd[ 'id' ] ) repository = review.repository repo = hg_util.get_repo_for_repository( trans.app, repository=repository, repo_path=None, create=False ) rev, changeset_revision_label = hg_util.get_rev_label_from_changeset_revision( repo, review.changeset_revision ) @@ -104,7 +104,7 @@ if not name or not description: message = 'Enter a valid name and a description' status = 'error' - elif review_util.get_component_by_name( trans, name ): + elif review_util.get_component_by_name( trans.app, name ): message = 'A component with that name already exists' status = 'error' else: @@ -137,7 +137,7 @@ if changeset_revision: # Make sure there is not already a review of the revision by the user. repository = suc.get_repository_in_tool_shed( trans.app, repository_id ) - if review_util.get_review_by_repository_id_changeset_revision_user_id( trans=trans, + if review_util.get_review_by_repository_id_changeset_revision_user_id( app=trans.app, repository_id=repository_id, changeset_revision=changeset_revision, user_id=trans.security.encode_id( trans.user.id ) ): @@ -145,7 +145,9 @@ status = "error" else: # See if there are any reviews for previous changeset revisions that the user can copy. - if not create_without_copying and not previous_review_id and review_util.has_previous_repository_reviews( trans, repository, changeset_revision ): + if not create_without_copying and \ + not previous_review_id and \ + review_util.has_previous_repository_reviews( trans.app, repository, changeset_revision ): return trans.response.send_redirect( web.url_for( controller='repository_review', action='select_previous_review', **kwd ) ) @@ -163,7 +165,7 @@ trans.sa_session.add( review ) trans.sa_session.flush() if previous_review_id: - review_to_copy = review_util.get_review( trans, previous_review_id ) + review_to_copy = review_util.get_review( trans.app, previous_review_id ) self.copy_review( trans, review_to_copy, review ) review_id = trans.security.encode_id( review.id ) message = "Begin your review of revision <b>%s</b> of repository <b>%s</b>." \ @@ -199,7 +201,7 @@ action='manage_categories', message=message, status='error' ) ) - component = review_util.get_component( trans, id ) + component = review_util.get_component( trans.app, id ) if kwd.get( 'edit_component_button', False ): new_description = kwd.get( 'description', '' ).strip() if component.description != new_description: @@ -224,9 +226,9 @@ message = kwd.get( 'message', '' ) status = kwd.get( 'status', 'done' ) review_id = kwd.get( 'id', None ) - review = review_util.get_review( trans, review_id ) + review = review_util.get_review( trans.app, review_id ) components_dict = odict() - for component in review_util.get_components( trans ): + for component in review_util.get_components( trans.app ): components_dict[ component.name ] = dict( component=component, component_review=None ) repository = review.repository repo = hg_util.get_repo_for_repository( trans.app, repository=repository, repo_path=None, create=False ) @@ -276,8 +278,11 @@ approved = str( v ) elif component_review_attr == 'rating': rating = int( str( v ) ) - component = review_util.get_component( trans, component_id ) - component_review = review_util.get_component_review_by_repository_review_id_component_id( trans, review_id, component_id ) + component = review_util.get_component( trans.app, component_id ) + component_review = \ + review_util.get_component_review_by_repository_review_id_component_id( trans.app, + review_id, + component_id ) if component_review: # See if the existing component review should be updated. if component_review.comment != comment or \ @@ -477,7 +482,10 @@ rev, changeset_revision_label = hg_util.get_rev_label_from_changeset_revision( repo, changeset_revision ) if changeset_revision in reviewed_revision_hashes: # Find the review for this changeset_revision - repository_reviews = review_util.get_reviews_by_repository_id_changeset_revision( trans, repository_id, changeset_revision ) + repository_reviews = \ + review_util.get_reviews_by_repository_id_changeset_revision( trans.app, + repository_id, + changeset_revision ) # Determine if the current user can add a review to this revision. can_add_review = trans.user not in [ repository_review.user for repository_review in repository_reviews ] repository_metadata = suc.get_repository_metadata_by_changeset_revision( trans.app, repository_id, changeset_revision ) @@ -515,7 +523,9 @@ repo = hg_util.get_repo_for_repository( trans.app, repository=repository, repo_path=None, create=False ) installable = changeset_revision in [ metadata_revision.changeset_revision for metadata_revision in repository.metadata_revisions ] rev, changeset_revision_label = hg_util.get_rev_label_from_changeset_revision( repo, changeset_revision ) - reviews = review_util.get_reviews_by_repository_id_changeset_revision( trans, repository_id, changeset_revision ) + reviews = review_util.get_reviews_by_repository_id_changeset_revision( trans.app, + repository_id, + changeset_revision ) return trans.fill_template( '/webapps/tool_shed/repository_review/reviews_of_changeset_revision.mako', repository=repository, changeset_revision=changeset_revision, @@ -534,7 +544,7 @@ if 'operation' in kwd: operation = kwd['operation'].lower() # The value of the received id is the encoded review id. - review = review_util.get_review( trans, kwd[ 'id' ] ) + review = review_util.get_review( trans.app, kwd[ 'id' ] ) repository = review.repository kwd[ 'id' ] = trans.security.encode_id( repository.id ) if operation == "inspect repository revisions": @@ -578,7 +588,9 @@ repository = suc.get_repository_in_tool_shed( trans.app, kwd[ 'id' ] ) changeset_revision = kwd.get( 'changeset_revision', None ) repo = hg_util.get_repo_for_repository( trans.app, repository=repository, repo_path=None, create=False ) - previous_reviews_dict = review_util.get_previous_repository_reviews( trans, repository, changeset_revision ) + previous_reviews_dict = review_util.get_previous_repository_reviews( trans.app, + repository, + changeset_revision ) rev, changeset_revision_label = hg_util.get_rev_label_from_changeset_revision( repo, changeset_revision ) return trans.fill_template( '/webapps/tool_shed/repository_review/select_previous_review.mako', repository=repository, diff -r 49e900b2a87108eb1e8b2bbea8a1bf6daedd6328 -r f65eb16fdf1e0b7a6f3483373c32765107c3b2b6 lib/tool_shed/util/review_util.py --- a/lib/tool_shed/util/review_util.py +++ b/lib/tool_shed/util/review_util.py @@ -7,87 +7,110 @@ log = logging.getLogger( __name__ ) -def can_browse_repository_reviews( trans, repository ): - """Determine if there are any reviews of the received repository for which the current user has permission to browse any component reviews.""" - user = trans.user +def can_browse_repository_reviews( app, user, repository ): + """ + Determine if there are any reviews of the received repository for which the + current user has permission to browse any component reviews. + """ if user: for review in repository.reviews: for component_review in review.component_reviews: - if trans.app.security_agent.user_can_browse_component_review( trans.app, repository, component_review, user ): + if app.security_agent.user_can_browse_component_review( app, + repository, + component_review, user ): return True return False -def changeset_revision_reviewed_by_user( trans, user, repository, changeset_revision ): +def changeset_revision_reviewed_by_user( user, repository, changeset_revision ): """Determine if the current changeset revision has been reviewed by the current user.""" for review in repository.reviews: if review.changeset_revision == changeset_revision and review.user == user: return True return False -def get_component( trans, id ): +def get_component( app, id ): """Get a component from the database.""" - return trans.sa_session.query( trans.model.Component ).get( trans.security.decode_id( id ) ) + sa_session = app.model.context.current + return sa_session.query( app.model.Component ).get( app.security.decode_id( id ) ) -def get_component_review( trans, id ): +def get_component_review( app, id ): """Get a component_review from the database""" - return trans.sa_session.query( trans.model.ComponentReview ).get( trans.security.decode_id( id ) ) + sa_session = app.model.context.current + return sa_session.query( app.model.ComponentReview ).get( app.security.decode_id( id ) ) -def get_component_by_name( trans, name ): +def get_component_by_name( app, name ): """Get a component from the database via a name.""" - return trans.sa_session.query( trans.app.model.Component ) \ - .filter( trans.app.model.Component.table.c.name==name ) \ - .first() + sa_session = app.model.context.current + return sa_session.query( app.app.model.Component ) \ + .filter( app.app.model.Component.table.c.name==name ) \ + .first() -def get_component_review_by_repository_review_id_component_id( trans, repository_review_id, component_id ): +def get_component_review_by_repository_review_id_component_id( app, repository_review_id, component_id ): """Get a component_review from the database via repository_review_id and component_id.""" - return trans.sa_session.query( trans.model.ComponentReview ) \ - .filter( and_( trans.model.ComponentReview.table.c.repository_review_id == trans.security.decode_id( repository_review_id ), - trans.model.ComponentReview.table.c.component_id == trans.security.decode_id( component_id ) ) ) \ - .first() + sa_session = app.model.context.current + return sa_session.query( app.model.ComponentReview ) \ + .filter( and_( app.model.ComponentReview.table.c.repository_review_id == app.security.decode_id( repository_review_id ), + app.model.ComponentReview.table.c.component_id == app.security.decode_id( component_id ) ) ) \ + .first() -def get_components( trans ): - return trans.sa_session.query( trans.app.model.Component ) \ - .order_by( trans.app.model.Component.name ) \ - .all() +def get_components( app ): + sa_session = app.model.context.current + return sa_session.query( app.model.Component ) \ + .order_by( app.model.Component.name ) \ + .all() -def get_previous_repository_reviews( trans, repository, changeset_revision ): - """Return an ordered dictionary of repository reviews up to and including the received changeset revision.""" - repo = hg_util.get_repo_for_repository( trans.app, repository=repository, repo_path=None, create=False ) +def get_previous_repository_reviews( app, repository, changeset_revision ): + """ + Return an ordered dictionary of repository reviews up to and including the + received changeset revision. + """ + repo = hg_util.get_repo_for_repository( app, repository=repository, repo_path=None, create=False ) reviewed_revision_hashes = [ review.changeset_revision for review in repository.reviews ] previous_reviews_dict = odict() for changeset in hg_util.reversed_upper_bounded_changelog( repo, changeset_revision ): previous_changeset_revision = str( repo.changectx( changeset ) ) if previous_changeset_revision in reviewed_revision_hashes: - previous_rev, previous_changeset_revision_label = hg_util.get_rev_label_from_changeset_revision( repo, previous_changeset_revision ) - revision_reviews = get_reviews_by_repository_id_changeset_revision( trans, - trans.security.encode_id( repository.id ), + previous_rev, previous_changeset_revision_label = \ + hg_util.get_rev_label_from_changeset_revision( repo, previous_changeset_revision ) + revision_reviews = get_reviews_by_repository_id_changeset_revision( app, + app.security.encode_id( repository.id ), previous_changeset_revision ) - previous_reviews_dict[ previous_changeset_revision ] = dict( changeset_revision_label=previous_changeset_revision_label, - reviews=revision_reviews ) + previous_reviews_dict[ previous_changeset_revision ] = \ + dict( changeset_revision_label=previous_changeset_revision_label, + reviews=revision_reviews ) return previous_reviews_dict -def get_review( trans, id ): +def get_review( app, id ): """Get a repository_review from the database via id.""" - return trans.sa_session.query( trans.model.RepositoryReview ).get( trans.security.decode_id( id ) ) + sa_session = app.model.context.current + return sa_session.query( app.model.RepositoryReview ).get( app.security.decode_id( id ) ) -def get_review_by_repository_id_changeset_revision_user_id( trans, repository_id, changeset_revision, user_id ): - """Get a repository_review from the database via repository id, changeset_revision and user_id.""" - return trans.sa_session.query( trans.model.RepositoryReview ) \ - .filter( and_( trans.model.RepositoryReview.repository_id == trans.security.decode_id( repository_id ), - trans.model.RepositoryReview.changeset_revision == changeset_revision, - trans.model.RepositoryReview.user_id == trans.security.decode_id( user_id ) ) ) \ - .first() +def get_review_by_repository_id_changeset_revision_user_id( app, repository_id, changeset_revision, user_id ): + """ + Get a repository_review from the database via repository id, changeset_revision + and user_id. + """ + sa_session = app.model.context.current + return sa_session.query( app.model.RepositoryReview ) \ + .filter( and_( app.model.RepositoryReview.repository_id == app.security.decode_id( repository_id ), + app.model.RepositoryReview.changeset_revision == changeset_revision, + app.model.RepositoryReview.user_id == app.security.decode_id( user_id ) ) ) \ + .first() -def get_reviews_by_repository_id_changeset_revision( trans, repository_id, changeset_revision ): +def get_reviews_by_repository_id_changeset_revision( app, repository_id, changeset_revision ): """Get all repository_reviews from the database via repository id and changeset_revision.""" - return trans.sa_session.query( trans.model.RepositoryReview ) \ - .filter( and_( trans.model.RepositoryReview.repository_id == trans.security.decode_id( repository_id ), - trans.model.RepositoryReview.changeset_revision == changeset_revision ) ) \ - .all() + sa_session = app.model.context.current + return sa_session.query( app.model.RepositoryReview ) \ + .filter( and_( app.model.RepositoryReview.repository_id == app.security.decode_id( repository_id ), + app.model.RepositoryReview.changeset_revision == changeset_revision ) ) \ + .all() -def has_previous_repository_reviews( trans, repository, changeset_revision ): - """Determine if a repository has a changeset revision review prior to the received changeset revision.""" - repo = hg_util.get_repo_for_repository( trans.app, repository=repository, repo_path=None, create=False ) +def has_previous_repository_reviews( app, repository, changeset_revision ): + """ + Determine if a repository has a changeset revision review prior to the + received changeset revision. + """ + repo = hg_util.get_repo_for_repository( app, repository=repository, repo_path=None, create=False ) reviewed_revision_hashes = [ review.changeset_revision for review in repository.reviews ] for changeset in hg_util.reversed_upper_bounded_changelog( repo, changeset_revision ): previous_changeset_revision = str( repo.changectx( changeset ) ) diff -r 49e900b2a87108eb1e8b2bbea8a1bf6daedd6328 -r f65eb16fdf1e0b7a6f3483373c32765107c3b2b6 templates/webapps/tool_shed/common/repository_actions_menu.mako --- a/templates/webapps/tool_shed/common/repository_actions_menu.mako +++ b/templates/webapps/tool_shed/common/repository_actions_menu.mako @@ -34,7 +34,7 @@ can_browse_contents = not is_new - if can_browse_repository_reviews( trans, repository ): + if can_browse_repository_reviews( trans.app, trans.user, repository ): can_browse_reviews = True else: can_browse_reviews = False @@ -79,7 +79,7 @@ can_review_repository = True else: can_review_repository = False - if changeset_revision_reviewed_by_user( trans, trans.user, repository, changeset_revision ): + if changeset_revision_reviewed_by_user( trans.user, repository, changeset_revision ): reviewed_by_user = True else: reviewed_by_user = False @@ -88,7 +88,7 @@ reviewed_by_user = False if reviewed_by_user: - review = get_review_by_repository_id_changeset_revision_user_id( trans=trans, + review = get_review_by_repository_id_changeset_revision_user_id( app=trans.app, repository_id=trans.security.encode_id( repository.id ), changeset_revision=changeset_revision, user_id=trans.security.encode_id( trans.user.id ) ) Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.