Esempio n. 1
0
    def repository_reviews_by_user(self, trans, **kwd):
        message = escape(kwd.get('message', ''))
        status = kwd.get('status', 'done')

        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.app, kwd['id'])
            repository = review.repository
            kwd['id'] = trans.security.encode_id(repository.id)
            if operation == "inspect repository revisions":
                return trans.response.send_redirect(
                    web.url_for(controller='repository_review',
                                action='manage_repository_reviews',
                                **kwd))
            if operation == "view_or_manage_repository":
                kwd['changeset_revision'] = review.changeset_revision
                return trans.response.send_redirect(
                    web.url_for(controller='repository_review',
                                action='view_or_manage_repository',
                                **kwd))
        # The user may not be the current user.  The value of the received id is the encoded user id.
        user = suc.get_user(trans.app, kwd['id'])
        self.repository_reviews_by_user_grid.title = "All repository revision reviews for user '%s'" % user.username
        return self.repository_reviews_by_user_grid(trans, **kwd)
Esempio n. 2
0
    def show(self, trans, id, **kwd):
        """
        GET /api/users/{encoded_user_id}
        GET /api/users/current
        Returns a dictionary of information about a user.

        :param id: the encoded id of the User object.
        """
        user = None
        # user is requesting data about themselves
        if id == "current" and trans.user:
            user = trans.user
        else:
            user = suc.get_user(trans.app, id)

        if user is None:
            user_dict = dict(message='Unable to locate user record for id %s.' % (str(id)),
                             status='error')
            return user_dict
        user_dict = user.to_dict(view='element',
                                 value_mapper=self.__get_value_mapper(trans))
        user_dict['url'] = web.url_for(controller='users',
                                       action='show',
                                       id=trans.security.encode_id(user.id))
        return user_dict
Esempio n. 3
0
    def show(self, trans, id, **kwd):
        """
        GET /api/users/{encoded_user_id}
        GET /api/users/current
        Returns a dictionary of information about a user.

        :param id: the encoded id of the User object.
        """
        user = None
        # user is requesting data about themselves
        if id == "current" and trans.user:
            user = trans.user
        else:
            user = suc.get_user(trans.app, id)

        if user is None:
            user_dict = dict(
                message='Unable to locate user record for id %s.' % (str(id)),
                status='error')
            return user_dict
        user_dict = user.to_dict(view='element',
                                 value_mapper=self.__get_value_mapper(trans))
        user_dict['url'] = web.url_for(controller='users',
                                       action='show',
                                       id=trans.security.encode_id(user.id))
        return user_dict
Esempio n. 4
0
    def show( self, trans, id, **kwd ):
        """
        GET /api/users/{encoded_user_id}
        Returns a dictionary of information about a user.

        :param id: the encoded id of the User object.
        """
        # Example URL: http://localhost:9009/api/users/f9cad7b01a472135
        user = suc.get_user( trans.app, id )
        if user is None:
            user_dict = dict( message='Unable to locate user record for id %s.' % ( str( id ) ),
                              status='error' )
            return user_dict
        user_dict = user.to_dict( view='element',
                                  value_mapper=self.__get_value_mapper( trans ) )
        user_dict[ 'url' ] = web.url_for( controller='users',
                                          action='show',
                                          id=trans.security.encode_id( user.id ) )
        return user_dict
    def repository_reviews_by_user( self, trans, **kwd ):

        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.app, kwd[ 'id' ] )
            repository = review.repository
            kwd[ 'id' ] = trans.security.encode_id( repository.id )
            if operation == "inspect repository revisions":
                return trans.response.send_redirect( web.url_for( controller='repository_review',
                                                                  action='manage_repository_reviews',
                                                                  **kwd ) )
            if operation == "view_or_manage_repository":
                kwd[ 'changeset_revision' ] = review.changeset_revision
                return trans.response.send_redirect( web.url_for( controller='repository_review',
                                                                  action='view_or_manage_repository',
                                                                  **kwd ) )
        # The user may not be the current user.  The value of the received id is the encoded user id.
        user = suc.get_user( trans.app, kwd[ 'id' ] )
        self.repository_reviews_by_user_grid.title = "All repository revision reviews for user '%s'" % user.username
        return self.repository_reviews_by_user_grid( trans, **kwd )
 def browse_repositories( self, trans, **kwd ):
     # We add parameters to the keyword dict in this method in order to rename the param
     # with an "f-" prefix, simulating filtering by clicking a search link.  We have
     # to take this approach because the "-" character is illegal in HTTP requests.
     if 'operation' in kwd:
         operation = kwd[ 'operation' ].lower()
         if operation == "view_or_manage_repository":
             return trans.response.send_redirect( web.url_for( controller='repository',
                                                               action='browse_repositories',
                                                               **kwd ) )
         elif operation == "edit_repository":
             return trans.response.send_redirect( web.url_for( controller='repository',
                                                               action='edit_repository',
                                                               **kwd ) )
         elif operation == "repositories_by_user":
             # Eliminate the current filters if any exist.
             for k, v in kwd.items():
                 if k.startswith( 'f-' ):
                     del kwd[ k ]
             if 'user_id' in kwd:
                 user = suc.get_user( trans.app, kwd[ 'user_id' ] )
                 kwd[ 'f-email' ] = user.email
                 del kwd[ 'user_id' ]
             else:
                 # The received id is the repository id, so we need to get the id of the user
                 # that uploaded the repository.
                 repository_id = kwd.get( 'id', None )
                 repository = suc.get_repository_in_tool_shed( trans.app, repository_id )
                 kwd[ 'f-email' ] = repository.user.email
         elif operation == "repositories_by_category":
             # Eliminate the current filters if any exist.
             for k, v in kwd.items():
                 if k.startswith( 'f-' ):
                     del kwd[ k ]
             category_id = kwd.get( 'id', None )
             category = suc.get_category( trans.app, category_id )
             kwd[ 'f-Category.name' ] = category.name
         elif operation == "receive email alerts":
             if kwd[ 'id' ]:
                 kwd[ 'caller' ] = 'browse_repositories'
                 return trans.response.send_redirect( web.url_for( controller='repository',
                                                                   action='set_email_alerts',
                                                                   **kwd ) )
             else:
                 del kwd[ 'operation' ]
         elif operation == 'delete':
             return self.delete_repository( trans, **kwd )
         elif operation == "undelete":
             return self.undelete_repository( trans, **kwd )
     # The changeset_revision_select_field in the RepositoryGrid performs a refresh_on_change
     # which sends in request parameters like changeset_revison_1, changeset_revision_2, etc.  One
     # of the many select fields on the grid performed the refresh_on_change, so we loop through
     # all of the received values to see which value is not the repository tip.  If we find it, we
     # know the refresh_on_change occurred, and we have the necessary repository id and change set
     # revision to pass on.
     for k, v in kwd.items():
         changeset_revision_str = 'changeset_revision_'
         if k.startswith( changeset_revision_str ):
             repository_id = trans.security.encode_id( int( k.lstrip( changeset_revision_str ) ) )
             repository = suc.get_repository_in_tool_shed( tran.apps, repository_id )
             if repository.tip( trans.app ) != v:
                 return trans.response.send_redirect( web.url_for( controller='repository',
                                                                   action='browse_repositories',
                                                                   operation='view_or_manage_repository',
                                                                   id=trans.security.encode_id( repository.id ),
                                                                   changeset_revision=v ) )
     # Render the list view
     return self.repository_grid( trans, **kwd )
Esempio n. 7
0
 def browse_repositories(self, trans, **kwd):
     # We add parameters to the keyword dict in this method in order to rename the param
     # with an "f-" prefix, simulating filtering by clicking a search link.  We have
     # to take this approach because the "-" character is illegal in HTTP requests.
     if 'operation' in kwd:
         operation = kwd['operation'].lower()
         if operation == "view_or_manage_repository":
             return trans.response.send_redirect(
                 web.url_for(controller='repository',
                             action='browse_repositories',
                             **kwd))
         elif operation == "edit_repository":
             return trans.response.send_redirect(
                 web.url_for(controller='repository',
                             action='edit_repository',
                             **kwd))
         elif operation == "repositories_by_user":
             # Eliminate the current filters if any exist.
             for k, v in list(kwd.items()):
                 if k.startswith('f-'):
                     del kwd[k]
             if 'user_id' in kwd:
                 user = suc.get_user(trans.app, kwd['user_id'])
                 kwd['f-email'] = user.email
                 del kwd['user_id']
             else:
                 # The received id is the repository id, so we need to get the id of the user
                 # that uploaded the repository.
                 repository_id = kwd.get('id', None)
                 repository = repository_util.get_repository_in_tool_shed(
                     trans.app, repository_id)
                 kwd['f-email'] = repository.user.email
         elif operation == "repositories_by_category":
             # Eliminate the current filters if any exist.
             for k, v in list(kwd.items()):
                 if k.startswith('f-'):
                     del kwd[k]
             category_id = kwd.get('id', None)
             category = suc.get_category(trans.app, category_id)
             kwd['f-Category.name'] = category.name
         elif operation == "receive email alerts":
             if kwd['id']:
                 kwd['caller'] = 'browse_repositories'
                 return trans.response.send_redirect(
                     web.url_for(controller='repository',
                                 action='set_email_alerts',
                                 **kwd))
             else:
                 del kwd['operation']
         elif operation == 'delete':
             return self.delete_repository(trans, **kwd)
         elif operation == "undelete":
             return self.undelete_repository(trans, **kwd)
     # The changeset_revision_select_field in the RepositoryGrid performs a refresh_on_change
     # which sends in request parameters like changeset_revison_1, changeset_revision_2, etc.  One
     # of the many select fields on the grid performed the refresh_on_change, so we loop through
     # all of the received values to see which value is not the repository tip.  If we find it, we
     # know the refresh_on_change occurred, and we have the necessary repository id and change set
     # revision to pass on.
     for k, v in kwd.items():
         changeset_revision_str = 'changeset_revision_'
         if k.startswith(changeset_revision_str):
             repository_id = trans.security.encode_id(
                 int(k.lstrip(changeset_revision_str)))
             repository = repository_util.get_repository_in_tool_shed(
                 trans.app, repository_id)
             if repository.tip() != v:
                 return trans.response.send_redirect(
                     web.url_for(controller='repository',
                                 action='browse_repositories',
                                 operation='view_or_manage_repository',
                                 id=trans.security.encode_id(repository.id),
                                 changeset_revision=v))
     # Render the list view
     return self.repository_grid(trans, **kwd)