mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Random PEP-8 fixes to some api controllers.
This commit is contained in:
@@ -10,6 +10,7 @@ from paste.httpexceptions import HTTPBadRequest, HTTPForbidden
|
||||
import logging
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
|
||||
class LibrariesController( BaseAPIController ):
|
||||
|
||||
@web.expose_api
|
||||
@@ -130,7 +131,7 @@ class LibrariesController( BaseAPIController ):
|
||||
new_library['synopsis'] = synopsis
|
||||
new_library['id'] = encoded_id
|
||||
return new_library
|
||||
|
||||
|
||||
def edit( self, trans, encoded_id, payload, **kwd ):
|
||||
"""
|
||||
* PUT /api/libraries/{encoded_id}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
API operations on the contents of a library.
|
||||
"""
|
||||
import logging
|
||||
from galaxy import web , exceptions
|
||||
from galaxy import web, exceptions
|
||||
from galaxy.model import ExtendedMetadata, ExtendedMetadataIndex
|
||||
from galaxy.web.base.controller import BaseAPIController, UsesLibraryMixin, UsesLibraryMixinItems
|
||||
from galaxy.web.base.controller import UsesHistoryDatasetAssociationMixin
|
||||
@@ -11,6 +11,7 @@ from galaxy import util
|
||||
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
|
||||
class LibraryContentsController( BaseAPIController, UsesLibraryMixin, UsesLibraryMixinItems,
|
||||
UsesHistoryDatasetAssociationMixin ):
|
||||
|
||||
@@ -36,6 +37,7 @@ class LibraryContentsController( BaseAPIController, UsesLibraryMixin, UsesLibrar
|
||||
"""
|
||||
rval = []
|
||||
current_user_roles = trans.get_current_user_roles()
|
||||
|
||||
def traverse( folder ):
|
||||
admin = trans.user_is_admin()
|
||||
rval = []
|
||||
@@ -50,7 +52,9 @@ class LibraryContentsController( BaseAPIController, UsesLibraryMixin, UsesLibrar
|
||||
for ld in folder.datasets:
|
||||
if not admin:
|
||||
can_access = trans.app.security_agent.can_access_dataset(
|
||||
current_user_roles, ld.library_dataset_dataset_association.dataset )
|
||||
current_user_roles,
|
||||
ld.library_dataset_dataset_association.dataset
|
||||
)
|
||||
if (admin or can_access) and not ld.deleted:
|
||||
#log.debug( "type(folder): %s" % type( folder ) )
|
||||
#log.debug( "type(api_path): %s; folder.api_path: %s" % ( type(folder.api_path), folder.api_path ) )
|
||||
@@ -73,20 +77,20 @@ class LibraryContentsController( BaseAPIController, UsesLibraryMixin, UsesLibrar
|
||||
return "Invalid library id ( %s ) specified." % str( library_id )
|
||||
#log.debug( "Root folder type: %s" % type( library.root_folder ) )
|
||||
encoded_id = 'F' + trans.security.encode_id( library.root_folder.id )
|
||||
rval.append( dict( id = encoded_id,
|
||||
type = 'folder',
|
||||
name = '/',
|
||||
url = url_for( 'library_content', library_id=library_id, id=encoded_id ) ) )
|
||||
rval.append( dict( id=encoded_id,
|
||||
type='folder',
|
||||
name='/',
|
||||
url=url_for( 'library_content', library_id=library_id, id=encoded_id ) ) )
|
||||
#log.debug( "Root folder attributes: %s" % str(dir(library.root_folder)) )
|
||||
library.root_folder.api_path = ''
|
||||
for content in traverse( library.root_folder ):
|
||||
encoded_id = trans.security.encode_id( content.id )
|
||||
if content.api_type == 'folder':
|
||||
encoded_id = 'F' + encoded_id
|
||||
rval.append( dict( id = encoded_id,
|
||||
type = content.api_type,
|
||||
name = content.api_path,
|
||||
url = url_for( 'library_content', library_id=library_id, id=encoded_id, ) ) )
|
||||
rval.append( dict( id=encoded_id,
|
||||
type=content.api_type,
|
||||
name=content.api_path,
|
||||
url=url_for( 'library_content', library_id=library_id, id=encoded_id, ) ) )
|
||||
return rval
|
||||
|
||||
@web.expose_api
|
||||
|
||||
@@ -4,11 +4,12 @@ API operations on Role objects.
|
||||
import logging
|
||||
from galaxy.web.base.controller import BaseAPIController, url_for
|
||||
from galaxy import web
|
||||
from elementtree.ElementTree import XML
|
||||
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
|
||||
class RoleAPIController( BaseAPIController ):
|
||||
|
||||
@web.expose_api
|
||||
def index( self, trans, **kwd ):
|
||||
"""
|
||||
@@ -61,11 +62,11 @@ class RoleAPIController( BaseAPIController ):
|
||||
if not name or not description:
|
||||
trans.response.status = 400
|
||||
return "Enter a valid name and a description"
|
||||
if trans.sa_session.query( trans.app.model.Role ).filter( trans.app.model.Role.table.c.name==name ).first():
|
||||
if trans.sa_session.query( trans.app.model.Role ).filter( trans.app.model.Role.table.c.name == name ).first():
|
||||
trans.response.status = 400
|
||||
return "A role with that name already exists"
|
||||
|
||||
role_type = trans.app.model.Role.types.ADMIN #TODO: allow non-admins to create roles
|
||||
role_type = trans.app.model.Role.types.ADMIN # TODO: allow non-admins to create roles
|
||||
|
||||
role = trans.app.model.Role( name=name, description=description, type=role_type )
|
||||
trans.sa_session.add( role )
|
||||
@@ -73,12 +74,15 @@ class RoleAPIController( BaseAPIController ):
|
||||
users = [ trans.sa_session.query( trans.model.User ).get( trans.security.decode_id( i ) ) for i in user_ids ]
|
||||
group_ids = payload.get( 'group_ids', [] )
|
||||
groups = [ trans.sa_session.query( trans.model.Group ).get( trans.security.decode_id( i ) ) for i in group_ids ]
|
||||
|
||||
# Create the UserRoleAssociations
|
||||
for user in users:
|
||||
trans.app.security_agent.associate_user_role( user, role )
|
||||
|
||||
# Create the GroupRoleAssociations
|
||||
for group in groups:
|
||||
trans.app.security_agent.associate_group_role( group, role )
|
||||
|
||||
trans.sa_session.flush()
|
||||
encoded_id = trans.security.encode_id( role.id )
|
||||
item = role.to_dict( view='element', value_mapper={ 'id': trans.security.encode_id } )
|
||||
|
||||
Reference in New Issue
Block a user