details: http://www.bx.psu.edu/hg/galaxy/rev/fc4c0c7e5da9 changeset: 2593:fc4c0c7e5da9 user: rc date: Thu Aug 20 16:54:44 2009 -0400 description: Fixed a bug in rendering form wrt AddressField Fixed other bugs admin's request UI 6 file(s) affected in this change: lib/galaxy/web/controllers/forms.py lib/galaxy/web/controllers/requests_admin.py lib/galaxy/web/framework/__init__.py templates/admin/requests/grid.mako test/base/twilltestcase.py test/functional/test_forms_and_requests.py diffs (290 lines): diff -r a7f9325bb319 -r fc4c0c7e5da9 lib/galaxy/web/controllers/forms.py --- a/lib/galaxy/web/controllers/forms.py Thu Aug 20 11:43:28 2009 -0400 +++ b/lib/galaxy/web/controllers/forms.py Thu Aug 20 16:54:44 2009 -0400 @@ -421,12 +421,14 @@ return [ fdc.latest_form for fdc in fdc_list ] -def get_form_widgets( trans, form, contents=[], **kwd ): +def get_form_widgets( trans, form, contents=[], user=None, **kwd ): ''' Return the list of widgets that comprise a form definition, including field contents if any. ''' params = util.Params( kwd ) + if not user: + user = trans.user widgets = [] for index, field in enumerate( form.fields ): field_name = 'field_%i' % index @@ -458,7 +460,7 @@ field_widget.set_size( 3, 40 ) field_widget.value = value elif field['type'] == 'AddressField': - field_widget.user = trans.user + field_widget.user = user field_widget.value = value field_widget.params = params elif field[ 'type' ] == 'SelectField': diff -r a7f9325bb319 -r fc4c0c7e5da9 lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Thu Aug 20 11:43:28 2009 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Thu Aug 20 16:54:44 2009 -0400 @@ -177,10 +177,9 @@ widget=TextField('desc', 40, desc), helptext='(Optional)')) # libraries selectbox - libraries = get_authorized_libs(trans, trans.user) - libui = self.__library_ui(libraries, request, **kwd) + libui = self.__library_ui(trans, trans.user, request, **kwd) widgets = widgets + libui - widgets = widgets + get_form_widgets(trans, request.type.request_form, request.values.content, **kwd) + widgets = widgets + get_form_widgets(trans, request.type.request_form, request.values.content, request.user, **kwd) return trans.fill_template( '/admin/requests/edit_request.mako', select_request_type=select_request_type, request_type=request.type, @@ -673,13 +672,9 @@ util.restore_text( params.get( 'desc', '' ) )), helptext='(Optional)')) # libraries selectbox - if not user: - libraries = [] - else: - libraries = get_authorized_libs(trans, user) - libui = self.__library_ui(libraries, **kwd) + libui = self.__library_ui(trans, user, **kwd) widgets = widgets + libui - widgets = widgets + get_form_widgets(trans, request_type.request_form, contents=[], **kwd) + widgets = widgets + get_form_widgets(trans, request_type.request_form, contents=[], user=user, **kwd) return trans.fill_template( '/admin/requests/new_request.mako', select_request_type=select_request_type, request_type=request_type, @@ -706,9 +701,13 @@ select_user.add_option(user.email, user.id) return select_user - def __library_ui(self, libraries, request=None, **kwd): + def __library_ui(self, trans, user, request=None, **kwd): params = util.Params( kwd ) lib_id = params.get( 'library_id', 'none' ) + if not user: + libraries = trans.app.model.Library.filter(trans.app.model.Library.table.c.deleted == False).order_by(trans.app.model.Library.name).all() + else: + libraries = get_authorized_libs(trans, user) lib_list = SelectField('library_id', refresh_on_change=True, refresh_on_change_values=['new']) if request and lib_id == 'none': @@ -724,13 +723,12 @@ else: lib_list.add_option(lib.name, lib.id) if lib_id == 'new': - lib_list.add_option('Create a new library', 'new', selected=True) + lib_list.add_option('Create a new data library', 'new', selected=True) else: - lib_list.add_option('Create a new library', 'new') - widget = dict(label='Library', + lib_list.add_option('Create a new data library', 'new') + widget = dict(label='Data library', widget=lib_list, - helptext='Associated library where the resultant \ - dataset will be stored.') + helptext='Data library where the resultant dataset will be stored.') if lib_id == 'new': new_lib = dict(label='Create a new Library', widget=TextField('new_library_name', 40, diff -r a7f9325bb319 -r fc4c0c7e5da9 lib/galaxy/web/framework/__init__.py --- a/lib/galaxy/web/framework/__init__.py Thu Aug 20 11:43:28 2009 -0400 +++ b/lib/galaxy/web/framework/__init__.py Thu Aug 20 16:54:44 2009 -0400 @@ -641,7 +641,6 @@ self.name = name self.action = action self.submit_text = submit_text - #self.submit_name = submit_text+"_button" self.inputs = [] def add_input( self, type, name, label, value=None, error=None, help=None, use_label=True ): self.inputs.append( FormInput( type, label, name, value, error, help, use_label ) ) diff -r a7f9325bb319 -r fc4c0c7e5da9 templates/admin/requests/grid.mako --- a/templates/admin/requests/grid.mako Thu Aug 20 11:43:28 2009 -0400 +++ b/templates/admin/requests/grid.mako Thu Aug 20 16:54:44 2009 -0400 @@ -76,7 +76,7 @@ <div class="grid-header"> <h2>${grid.title}</h2> - %if len(trans.user.requests): + %if len(trans.app.model.Request.query().all()): ##<span class="title">Filter:</span> %for i, filter in enumerate( grid.standard_filters ): %if i > 0: diff -r a7f9325bb319 -r fc4c0c7e5da9 test/base/twilltestcase.py --- a/test/base/twilltestcase.py Thu Aug 20 11:43:28 2009 -0400 +++ b/test/base/twilltestcase.py Thu Aug 20 16:54:44 2009 -0400 @@ -1077,6 +1077,17 @@ for index, field_value in enumerate(fields): tc.fv( "1", "field_%i" % index, field_value ) tc.submit( "create_request_button" ) + def create_request_admin( self, request_type_id, user_id, name, desc, library_id, fields ): + self.home() + self.visit_url( "%s/requests_admin/new?create=True&select_request_type=%i" % (self.url, request_type_id) ) + self.check_page_for_string( 'Add a new request' ) + tc.fv( "1", "select_user", str(user_id) ) + tc.fv( "1", "name", name ) + tc.fv( "1", "desc", desc ) + tc.fv( "1", "library_id", str(library_id) ) + for index, field_value in enumerate(fields): + tc.fv( "1", "field_%i" % index, field_value ) + tc.submit( "create_request_button" ) def add_samples( self, request_id, request_name, samples ): self.home() self.visit_url( "%s/requests/list?sort=-create_time&operation=show_request&id=%s" % ( self.url, self.security.encode_id( request_id ) )) diff -r a7f9325bb319 -r fc4c0c7e5da9 test/functional/test_forms_and_requests.py --- a/test/functional/test_forms_and_requests.py Thu Aug 20 11:43:28 2009 -0400 +++ b/test/functional/test_forms_and_requests.py Thu Aug 20 16:54:44 2009 -0400 @@ -100,28 +100,13 @@ global request_type request_type = galaxy.model.RequestType.filter( and_( galaxy.model.RequestType.table.c.name==request_type_name ) ).all()[-1] assert request_type is not None, 'Problem retrieving request type named "%s" from the database' % request_type_name - def test_025_create_address( self ): - """Testing address creation""" - #self.create_address( user_address1 ) - #self.check_page_for_string( 'Address <b>%s</b> has been added' % user_address1[ 'short_desc' ] ) - ## TODO: FIX HACK - ## the user address creation should be done as a test. - global user_address - user_address = galaxy.model.UserAddress() - user_address.user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test@bx.psu.edu' ).first() - user_address.desc = address1[ 'short_desc' ] - user_address.name = address1[ 'name' ] - user_address.institution = address1[ 'institution' ] - user_address.address = address1[ 'address1' ]+' '+address1[ 'address2' ] - user_address.city = address1[ 'city' ] - user_address.state = address1[ 'state' ] - user_address.postal_code = address1[ 'postal_code' ] - user_address.country = address1[ 'country' ] - user_address.phone = address1[ 'phone' ] - user_address.flush() - user_address.user.refresh() - def test_030_create_request( self ): - """Testing creating and submitting a request""" + def test_025_create_address_and_library( self ): + """Testing address & library creation""" + # first create a regular user + self.logout() + self.login( email='test1@bx.psu.edu' ) + self.logout() + self.login( email='test@bx.psu.edu' ) # first create a library for the request so that it can be submitted later lib_name = 'TestLib001' self.create_library( lib_name, '' ) @@ -144,12 +129,48 @@ break if not admin_user_private_role: raise AssertionError( "Private role not found for user '%s'" % admin_user.email ) + global regular_user1 + regular_user1 = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test1@bx.psu.edu' ).first() + assert regular_user1 is not None, 'Problem retrieving user with email "test1@bx.psu.edu" from the database' + # Get the regular user's private role for later use + global regular_user1_private_role + regular_user1_private_role = None + for role in regular_user1.all_roles(): + if role.name == regular_user1.email and role.description == 'Private Role for %s' % regular_user1.email: + regular_user1_private_role = role + break + if not regular_user1_private_role: + raise AssertionError( "Private role not found for user '%s'" % regular_user1.email ) # Set permissions on the library, sort for later testing permissions_in = [ k for k, v in galaxy.model.Library.permitted_actions.items() ] permissions_out = [] - # Role one members are: admin_user, regular_user1, regular_user3. Each of these users will be permitted to + # Role one members are: admin_user, regular_user1. Each of these users will be permitted to # LIBRARY_ADD, LIBRARY_MODIFY, LIBRARY_MANAGE for library items. - self.set_library_permissions( str( library_one.id ), library_one.name, str( admin_user_private_role.id ), permissions_in, permissions_out ) + self.set_library_permissions( str( library_one.id ), library_one.name, str( regular_user1_private_role.id ), permissions_in, permissions_out ) + # create address + #self.create_address( user_address1 ) + #self.check_page_for_string( 'Address <b>%s</b> has been added' % user_address1[ 'short_desc' ] ) + ## TODO: FIX HACK + ## the user address creation should be done as a test. + global user_address + user_address = galaxy.model.UserAddress() + user_address.user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test1@bx.psu.edu' ).first() + user_address.desc = address1[ 'short_desc' ] + user_address.name = address1[ 'name' ] + user_address.institution = address1[ 'institution' ] + user_address.address = address1[ 'address1' ]+' '+address1[ 'address2' ] + user_address.city = address1[ 'city' ] + user_address.state = address1[ 'state' ] + user_address.postal_code = address1[ 'postal_code' ] + user_address.country = address1[ 'country' ] + user_address.phone = address1[ 'phone' ] + user_address.flush() + user_address.user.refresh() + def test_030_create_request( self ): + """Testing creating and submitting a request as a regular user""" + # login as a regular user + self.logout() + self.login( email='test1@bx.psu.edu' ) # set field values fields = ['field one value', 'field two value', str(user_address.id)] # create the request @@ -162,7 +183,6 @@ galaxy.model.Request.table.c.deleted==False ) ).first() # check if the request's state is now set to 'unsubmitted' assert request_one.state is not request_one.states.UNSUBMITTED, "The state of the request '%s' should be set to '%s'" % ( request_one.name, request_one.states.UNSUBMITTED ) - # sample fields samples = [ ( 'Sample One', [ 'S1 Field 0 Value' ] ), ( 'Sample Two', [ 'S2 Field 0 Value' ] ) ] @@ -181,6 +201,8 @@ def test_035_request_lifecycle( self ): """Testing request lifecycle as it goes through all the states""" # goto admin manage requests page + self.logout() + self.login( email='test@bx.psu.edu' ) self.home() self.visit_page( 'requests_admin/list' ) self.check_page_for_string( request_one.name ) @@ -203,10 +225,43 @@ request_one.refresh() # check if the request's state is now set to 'complete' assert request_one.state is not request_one.states.COMPLETE, "The state of the request '%s' should be set to '%s'" % ( request_one.name, request_one.states.COMPLETE ) +# def test_40_admin_create_request_on_behalf_of_regular_user( self ): +# """Testing creating and submitting a request as an admin on behalf of a regular user""" +# self.logout() +# self.login( email='test@bx.psu.edu' ) +## permissions_in = [ k for k, v in galaxy.model.Library.permitted_actions.items() ] +## permissions_out = [] +## self.set_library_permissions( str( library_one.id ), library_one.name, str( admin_user_private_role.id ), permissions_in, permissions_out ) +# # set field values +# fields = ['field one value', 'field two value', str(user_address.id)] +# # create the request +# request_name, request_desc = 'Request Two', 'Request Two Description' +# self.create_request_admin(request_type.id, regular_user1.id, request_name, request_desc, library_one.id, fields) +# self.check_page_for_string( request_name ) +# self.check_page_for_string( request_desc ) +# global request_two +# request_one = galaxy.model.Request.filter( and_( galaxy.model.Request.table.c.name==request_name, +# galaxy.model.Request.table.c.deleted==False ) ).first() +# # check if the request's state is now set to 'unsubmitted' +# assert request_two.state is not request_two.states.UNSUBMITTED, "The state of the request '%s' should be set to '%s'" % ( request_two.name, request_two.states.UNSUBMITTED ) +# # sample fields +# samples = [ ( 'Sample One', [ 'S1 Field 0 Value' ] ), +# ( 'Sample Two', [ 'S2 Field 0 Value' ] ) ] +# # add samples to this request +# self.add_samples( request_two.id, request_two.name, samples ) +# for sample_name, fields in samples: +# self.check_page_for_string( sample_name ) +# self.check_page_for_string( 'Unsubmitted' ) +# for field_value in fields: +# self.check_page_for_string( field_value ) +# # submit the request +# self.submit_request( request_two.id, request_two.name ) +# request_two.refresh() +# # check if the request's state is now set to 'submitted' +# assert request_two.state is not request_two.states.SUBMITTED, "The state of the request '%s' should be set to '%s'" % ( request_two.name, request_two.states.SUBMITTED ) - \ No newline at end of file