Changeset 1459:b301cae30997
- Timestamp:
- 07/30/08 17:15:40 (4 months ago)
- Files:
-
- lib/galaxy/datatypes/images.py (modified) (2 diffs)
- lib/galaxy/model/__init__.py (modified) (12 diffs)
- lib/galaxy/model/mapping.py (modified) (3 diffs)
- lib/galaxy/tools/__init__.py (modified) (2 diffs)
- lib/galaxy/tools/actions/__init__.py (modified) (4 diffs)
- lib/galaxy/tools/actions/upload.py (modified) (2 diffs)
- lib/galaxy/tools/parameters/basic.py (modified) (3 diffs)
- lib/galaxy/web/controllers/async.py (modified) (1 diff)
- lib/galaxy/web/controllers/dataset.py (modified) (1 diff)
- lib/galaxy/web/controllers/root.py (modified) (9 diffs)
- lib/galaxy/web/controllers/user.py (modified) (1 diff)
- lib/galaxy/web/framework/__init__.py (modified) (2 diffs)
- templates/dataset/edit_attributes.mako (modified) (2 diffs)
- templates/history/options.mako (modified) (1 diff)
- templates/root/history_common.mako (modified) (1 diff)
- templates/user/index.mako (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lib/galaxy/datatypes/images.py
r1454 r1459 111 111 "urlpause" :"100", 112 112 "debug": "false", 113 "posturl": "history_add_to?%s" % urlencode( { 'history_id': dataset.history_id, 'ext': 'maf', 'name': 'GMAJ Output on data %s' % dataset.hid, 'info': 'Added by GMAJ', 'dbkey': dataset.dbkey , 'copy_access_from': dataset.id} )113 "posturl": "history_add_to?%s" % urlencode( { 'history_id': dataset.history_id, 'ext': 'maf', 'name': 'GMAJ Output on data %s' % dataset.hid, 'info': 'Added by GMAJ', 'dbkey': dataset.dbkey } ) 114 114 } 115 115 class_name = "edu.psu.bx.gmaj.MajApplet.class" … … 181 181 "buttonlabel": "Launch LAJ", 182 182 "title": "LAJ in Galaxy", 183 "posturl": "history_add_to?%s" % urlencode( { 'history_id': dataset.history_id, 'ext': 'lav', 'name': 'LAJ Output', 'info': 'Added by LAJ', 'dbkey': dataset.dbkey , 'copy_access_from': dataset.id} ),183 "posturl": "history_add_to?%s" % urlencode( { 'history_id': dataset.history_id, 'ext': 'lav', 'name': 'LAJ Output', 'info': 'Added by LAJ', 'dbkey': dataset.dbkey } ), 184 184 "noseq": "true" 185 185 } lib/galaxy/model/__init__.py
r1456 r1459 28 28 29 29 class User( object ): 30 def __init__( self, email=None, password=None , groups = [], roles = [], default_groups = [], default_roles = []):30 def __init__( self, email=None, password=None ): 31 31 self.email = email 32 32 self.password = password … … 34 34 # Relationships 35 35 self.histories = [] 36 if not groups:37 groups.append( GalaxyGroup.get( GalaxyGroup.public_id ) )38 default_groups.append( groups[-1] )39 default_groups.append( self.create_private_group() )40 group_id_added = []41 for group in groups:42 if group.id not in group_id_added:43 group.add_user( self )44 group_id_added.append( group.id )45 group_id_added = []46 for group in default_groups:47 if group.id not in group_id_added:48 user_group_assoc = DefaultUserGroupAssociation( self, group )49 user_group_assoc.flush()50 group_id_added.append( group.id )51 role_id_added = []52 for role in roles:53 if role.id not in role_id_added:54 role.add_user( self )55 role_id_added.append( role.id )56 role_id_added = []57 for role in default_roles:58 if role.id not in role_id_added:59 role_group_assoc = DefaultUserRoleAssociation( self, role )60 role_group_assoc.flush()61 role_id_added.append( role.id )62 36 def set_password_cleartext( self, cleartext ): 63 37 """Set 'self.password' to the digest of 'cleartext'.""" … … 66 40 """Check if 'cleartext' matches 'self.password' when hashed.""" 67 41 return self.password == sha.new( cleartext ).hexdigest() 68 def create_private_group( self ): 69 #create private group 70 group = GalaxyGroup( self.email, priority = 10 ) 71 group.flush() 72 #create private dataset access role 73 role = AccessRole( "%s dataset access" % self.email, list( Dataset.access_actions.__dict__.values() ), priority = 1 ) 74 role.flush() 75 #add role to group 76 group.add_role( role ) 77 78 #create roles for user modification of role 79 user_role = AccessRole( "%s role modification" % self.email, list( AccessRole.access_actions.__dict__.values() ) ) 80 user_role.flush() 81 #add role to user 82 user_role.add_user( self ) 83 #add role to role 84 role.add_role( user_role ) 85 86 #create roles for user modification of group 87 group_role = AccessRole( "%s group modification" % self.email, list( GalaxyGroup.access_actions.__dict__.values() ) ) 88 group_role.flush() 89 #add role to group 90 group.add_access_role( group_role ) 91 #associate role and user 92 group_role.add_user( self ) 93 94 #add user to group 95 group.add_user( self ) 96 group.flush() 97 return group 98 def add_group( self, group ): 99 return group.add_user( self ) 100 def has_group( self, check_group ): 101 return bool( UserGroupAssociation.get_by( group_id = check_group.id, user_id = self.id ) ) 102 def has_role( self, check_role ): 103 return bool( UserRoleAssociation.get_by( role_id = check_role.id, user_id = self.id ) ) 104 def set_default_access( self, groups = None, roles = None, history = False, dataset = False ): 105 if groups is not None: 106 for assoc in self.default_groups: #this is the association not the actual group 107 assoc.delete() 108 assoc.flush() 109 for group in groups: 110 assoc = DefaultUserGroupAssociation( self, group ) 111 assoc.flush() 112 if roles is not None: 113 for assoc in self.default_roles: #this is the association not the actual group 114 assoc.delete() 115 assoc.flush() 116 for role in roles: 117 assoc = DefaultUserRoleAssociation( self, role ) 118 assoc.flush() 119 if history: 120 for history in self.histories: 121 history.set_default_access( groups = groups, roles = roles, dataset = dataset ) 122 42 123 43 class Job( object ): 124 44 """ … … 182 102 self.dataset = dataset 183 103 184 class AccessRole( object ):185 dataset_actions = Bunch( VIEW = 'dataset_view', #viewing/downloading186 USE = 'dataset_use', #use in jobs187 ADD_ROLE = 'dataset_add_role', #dataset can be added to roles188 REMOVE_ROLE = 'dataset_remove_role', #dataset can be removed from roles189 ADD_GROUP = 'dataset_add_group', #dataset can be added to groups190 REMOVE_GROUP = 'dataset_remove_group' ) #dataset can be removed from groups191 role_actions = Bunch( ADD_DATASET = 'role_add_dataset', #add role to dataset192 REMOVE_DATASET = 'role_remove_dataset', #remove role from dataset193 DELETE = 'role_delete', #delete a role194 MODIFY = 'role_modify', #change a role's actions,195 ADD_GROUP = 'role_add_group', #add role to a group196 REMOVE_GROUP = 'role_remove_group' ) #remove role from a group197 group_actions = Bunch( ADD_DATASET = 'group_add_dataset', #add group to dataset198 REMOVE_DATASET = 'group_remove_dataset', #remove dataset from group199 DELETE = 'group_delete', #delete a group200 ADD_ROLE = 'group_add_role', #add role to group201 REMOVE_ROLE = 'group_remove_role', #remove role from group202 ADD_USER = 'group_add_user' ) #add users to group203 204 access_actions = role_actions205 206 def __init__( self, name, actions, priority = 0 ):207 self.name = name208 if not isinstance( actions, list ):209 actions = [ actions ]210 self.actions = actions211 self.priority = priority212 def add_user( self, user ):213 assoc = UserRoleAssociation( user, self )214 assoc.flush()215 return assoc216 def add_group( self, group ):217 assoc = GroupRoleAssociation( group, self )218 assoc.flush()219 return assoc220 def add_role( self, role ):221 assoc = RoleRoleAssociation( role, self )222 assoc.flush()223 return assoc224 def add_dataset( self, dataset ):225 assoc = RoleDatasetAssociation( self, dataset )226 assoc.flush()227 return assoc228 229 class GalaxyGroup( object ):230 public_id = None231 access_actions = AccessRole.group_actions232 def __init__( self, name, priority = 0 ):233 self.name = name234 self.priority = priority235 def add_user( self, user ):236 assoc = UserGroupAssociation( user, self )237 assoc.flush()238 return assoc239 def add_role( self, role ):240 return role.add_group( self )241 def add_access_role( self, role ):242 assoc = GroupRoleAccessAssociation( self, role )243 assoc.flush()244 return assoc245 def add_dataset( self, dataset ):246 assoc = GroupDatasetAssociation( self, dataset )247 assoc.flush()248 return assoc249 250 class UserGroupAssociation( object ):251 def __init__( self, user, group ):252 self.user = user253 self.group = group254 255 class RoleRoleAssociation( object ):256 def __init__( self, role, target_role ):257 self.role = role258 self.target_role = target_role259 260 class GroupRoleAccessAssociation( object ):261 def __init__( self, group, role ):262 self.group = group263 self.role = role264 265 class GroupRoleAssociation( object ):266 def __init__( self, group, role ):267 self.group = group268 self.role = role269 270 class UserRoleAssociation( object ):271 def __init__( self, user, role ):272 self.user = user273 self.role = role274 275 class GroupDatasetAssociation( object ):276 def __init__( self, group, dataset ):277 if isinstance( group, GroupDatasetAssociation ) or isinstance( group, DefaultUserGroupAssociation ) or isinstance( group, DefaultHistoryGroupAssociation ):278 group = group.group279 self.group = group280 281 if isinstance( dataset, HistoryDatasetAssociation ):282 dataset = dataset.dataset283 self.dataset = dataset284 285 class RoleDatasetAssociation( object ):286 def __init__( self, role, dataset ):287 if isinstance( role, RoleDatasetAssociation ) or isinstance( role, DefaultUserRoleAssociation ) or isinstance( role, DefaultHistoryRoleAssociation ):288 role = role.role289 self.role = role290 291 if isinstance( dataset, HistoryDatasetAssociation ):292 dataset = dataset.dataset293 self.dataset = dataset294 295 class DefaultUserRoleAssociation( object ):296 def __init__( self, user, role ):297 if isinstance( role, RoleDatasetAssociation ) or isinstance( role, DefaultUserRoleAssociation ) or isinstance( role, DefaultHistoryRoleAssociation ):298 role = role.role299 self.user = user300 self.role = role301 302 class DefaultUserGroupAssociation( object ):303 def __init__( self, user, group ):304 if isinstance( group, GroupDatasetAssociation ) or isinstance( group, DefaultUserGroupAssociation ) or isinstance( group, DefaultHistoryGroupAssociation ):305 group = group.group306 self.user = user307 self.group = group308 309 class DefaultHistoryRoleAssociation( object ):310 def __init__( self, history, role ):311 if isinstance( role, RoleDatasetAssociation ) or isinstance( role, DefaultUserRoleAssociation ) or isinstance( role, DefaultHistoryRoleAssociation ):312 role = role.role313 self.history = history314 self.role = role315 316 class DefaultHistoryGroupAssociation( object ):317 def __init__( self, history, group ):318 if isinstance( group, GroupDatasetAssociation ) or isinstance( group, DefaultUserGroupAssociation ) or isinstance( group, DefaultHistoryGroupAssociation ):319 group = group.group320 self.history = history321 self.group = group322 323 class Dataset( object ):324 states = Bunch( NEW = 'new',325 QUEUED = 'queued',326 RUNNING = 'running',327 OK = 'ok',328 EMPTY = 'empty',329 ERROR = 'error',330 DISCARDED = 'discarded' )331 access_actions = AccessRole.dataset_actions332 file_path = "/tmp/"333 engine = None334 def __init__( self, id=None, state=None, external_filename=None, extra_files_path=None, file_size=None, purgable=True, access_groups=[], access_roles=[] ):335 self.id = id336 self.state = state337 self.deleted = False338 self.purged = False339 self.purgable = purgable340 self.external_filename = external_filename341 self._extra_files_path = extra_files_path342 self.file_size = file_size343 if access_groups or access_roles:344 #self.flush()345 for group in access_groups:346 group.add_dataset( self )347 group.flush()348 for role in access_roles:349 role.add_dataset( self )350 role.flush()351 def get_file_name( self ):352 if not self.external_filename:353 assert self.id is not None, "ID must be set before filename used (commit the object)"354 # First try filename directly under file_path355 filename = os.path.join( self.file_path, "dataset_%d.dat" % self.id )356 # Only use that filename if it already exists (backward compatibility),357 # otherwise construct hashed path358 if not os.path.exists( filename ):359 dir = os.path.join( self.file_path, *directory_hash_id( self.id ) )360 # Create directory if it does not exist361 try:362 os.makedirs( dir )363 except OSError, e:364 # File Exists is okay, otherwise reraise365 if e.errno != errno.EEXIST:366 raise367 # Return filename inside hashed directory368 return os.path.abspath( os.path.join( dir, "dataset_%d.dat" % self.id ) )369 else:370 filename = self.external_filename371 # Make filename absolute372 return os.path.abspath( filename )373 374 def set_file_name ( self, filename ):375 if not filename:376 self.external_filename = None377 else:378 self.external_filename = filename379 380 file_name = property( get_file_name, set_file_name )381 382 @property383 def extra_files_path( self ):384 if self._extra_files_path:385 path = self._extra_files_path386 else:387 path = os.path.join( self.file_path, "dataset_%d_files" % self.id )388 #only use path directly under self.file_path if it exists389 if not os.path.exists( path ):390 path = os.path.join( os.path.join( self.file_path, *directory_hash_id( self.id ) ), "dataset_%d_files" % self.id )391 # Make path absolute392 return os.path.abspath( path )393 394 def get_size( self ):395 """Returns the size of the data on disk"""396 if self.file_size:397 return self.file_size398 else:399 try:400 return os.path.getsize( self.file_name )401 except OSError:402 return 0403 def set_size( self ):404 """Returns the size of the data on disk"""405 try:406 self.file_size = os.path.getsize( self.file_name )407 except OSError:408 self.file_size = 0409 def has_data( self ):410 """Detects whether there is any data"""411 return self.get_size() > 0412 def mark_deleted( self, include_children=True ):413 self.deleted = True414 def allow_action( self, user, action ):415 """Returns true when user has permission to perform an action"""416 417 #if dataset is in public group, we always return true for viewing and using418 #this may need to change when the ability to alter groups and roles is allowed419 if action in [ self.access_actions.USE, self.access_actions.VIEW ] and GroupDatasetAssociation.get_by( group_id = GalaxyGroup.public_id, dataset_id = self.id ):420 return True421 elif user is not None:422 #loop through permissions and if allowed return true:423 #check roles associated directly with dataset first424 for role_dataset_assoc in self.roles:425 if action in role_dataset_assoc.role.actions and user.has_role( role_dataset_assoc.role ):426 return True427 #check roles associated with dataset through groups428 for group_dataset_assoc in self.groups:429 if user.has_group( group_dataset_assoc.group ):430 for group_role_assoc in group_dataset_assoc.group.roles:431 if action in group_role_assoc.role.actions:432 return True433 return False #no user and dataset not in public group, or user lacks permission434 def guess_derived_groups_roles( self, other_datasets = [] ):435 """Returns a list of output roles and groups based upon itself and provided datasets"""436 if not other_datasets:437 return [ data_group_assoc.group for data_group_assoc in self.groups ], [ data_role_assoc.role for data_role_assoc in self.roles ]438 access_roles = None439 priority_access_role = None440 access_groups = None441 priority_access_group = None442 for dataset in [ self ] + other_datasets:443 #determine access roles and groups for output datasets444 #roles and groups for output dataset is the intersection across all inputs445 #if we end up with no intersection between inputs, then we rely on priorities446 if isinstance( dataset, HistoryDatasetAssociation ):447 dataset = dataset.dataset448 roles = [ data_role_assoc.role for data_role_assoc in dataset.roles ]449 for role in roles:450 if priority_access_role is None or priority_access_role.priority < role.priority:451 priority_access_role = role452 groups = [ data_group_assoc.group for data_group_assoc in dataset.groups ]453 for group in groups:454 if priority_access_group is None or priority_access_group.priority < group.priority:455 priority_access_group = group456 if access_roles is None:457 access_roles = set( roles )458 access_groups = set( groups )459 else:460 access_roles.intersection_update( set( roles ) )461 access_groups.intersection_update( set( groups ) )462 463 #complete lists for output dataset access464 if access_roles:465 access_roles = list( access_roles )466 else:467 access_roles = []468 if access_groups:469 access_groups = list( access_groups)470 else:471 access_groups = []472 #if we have no roles or groups left after intersection,473 #take the highest priority group or role474 if not access_roles and not access_groups:475 if priority_access_role and priority_access_group:476 if priority_access_group.priority == priority_access_role.priority:477 access_groups = [ priority_access_group ]478 access_roles = [ priority_access_role ]479 elif priority_access_group.priority > priority_access_role.priority:480 access_groups = [ priority_access_group ]481 else:482 access_roles = [ priority_access_role ]483 elif priority_access_role:484 access_roles = [ priority_access_role ]485 elif priority_access_group:486 access_groups = [ priority_access_group ]487 488 return access_groups, access_roles489 def add_group( self, group ):490 return group.add_dataset( self )491 def add_role( self, role ):492 return role.add_dataset( self )493 494 def has_group( self, group ):495 return bool( GroupDatasetAssociation.get_by( group_id = group.id, dataset_id = self.id ) )496 def has_role( self, role ):497 return bool( RoleDatasetAssociation.get_by( role_id = role.id, dataset_id = self.id ) )498 499 # FIXME: sqlalchemy will replace this500 def _delete(self):501 """Remove the file that corresponds to this data"""502 try:503 os.remove(self.data.file_name)504 except OSError, e:505 log.critical('%s delete error %s' % (self.__class__.__name__, e))506 507 508 509 104 class HistoryDatasetAssociation( object ): 510 states = Dataset.states511 access_actions = Dataset.access_actions512 105 def __init__( self, id=None, hid=None, name=None, info=None, blurb=None, peek=None, extension=None, 513 106 dbkey=None, metadata=None, history=None, dataset=None, deleted=False, designation=None, 514 parent_id=None, validation_errors=None, visible=True, create_dataset = False , access_groups = [], access_roles = []):107 parent_id=None, validation_errors=None, visible=True, create_dataset = False ): 515 108 self.name = name or "Unnamed dataset" 516 109 self.id = id … … 528 121 self.history = history 529 122 if not dataset and create_dataset: 530 dataset = Dataset( access_groups = access_groups, access_roles = access_roles)123 dataset = Dataset() 531 124 dataset.flush() 532 125 self.dataset = dataset … … 537 130 def ext( self ): 538 131 return self.extension 132 133 @property 134 def states( self ): 135 return self.dataset.states 539 136 540 137 def get_dataset_state( self ): … … 655 252 return self.datatype.get_converter_types( self, datatypes_registry) 656 253 657 def copy( self, copy_children = False, parent_id = None, target_user = None ): 658 if target_user is None: target_user = self.user 254 def copy( self, copy_children = False, parent_id = None ): 659 255 des = HistoryDatasetAssociation( hid=self.hid, name=self.name, info=self.info, blurb=self.blurb, peek=self.peek, extension=self.extension, dbkey=self.dbkey, metadata=self._metadata, dataset = self.dataset, visible=self.visible, deleted=self.deleted, parent_id=parent_id ) 660 256 des.flush() … … 678 274 child.mark_deleted() 679 275 680 def allow_action( self, user, action ):681 return self.dataset.allow_action( user, action )682 276 683 277 684 278 class History( object ): 685 def __init__( self, id=None, name=None, user=None , default_roles = [], default_groups = []):279 def __init__( self, id=None, name=None, user=None ): 686 280 self.id = id 687 281 self.name = name or "Unnamed history" … … 693 287 self.datasets = [] 694 288 self.galaxy_sessions = [] 695 696 if not default_roles:697 if user:698 default_roles = user.default_roles699 if not default_groups:700 if user:701 default_groups = user.default_groups702 else:703 default_groups = [ GalaxyGroup.get( GalaxyGroup.public_id ) ]704 705 706 self.set_default_access( roles = default_roles, groups = default_groups )707 289 708 290 def _next_hid( self ): … … 744 326 self.datasets.append( dataset ) 745 327 746 def copy( self, target_user = None ): 747 if not target_user: 748 target_user = self.user 749 des = History( user = target_user ) 328 def copy(self): 329 des = History() 750 330 des.flush() 751 331 des.name = self.name 332 des.user_id = self.user_id 752 333 for data in self.datasets: 753 new_data = data.copy( copy_children = True , target_user = target_user)334 new_data = data.copy( copy_children = True ) 754 335 des.add_dataset( new_data ) 755 336 new_data.flush() … … 757 338 des.flush() 758 339 return des 759 760 def set_default_access( self, groups = None, roles = None, dataset = False ):761 if groups is not None:762 for assoc in self.default_groups: #this is the association not the actual group763 assoc.delete()764 assoc.flush()765 for group in groups:766 assoc = DefaultHistoryGroupAssociation( self, group )767 assoc.flush()768 if roles is not None:769 for assoc in self.default_roles: #this is the association not the actual group770 assoc.delete()771 assoc.flush()772 for role in roles:773 assoc = DefaultHistoryRoleAssociation( self, role )774 assoc.flush()775 if dataset:776 for data in self.datasets:777 for hda in data.dataset.history_associations:778 if self.user and hda.history not in self.user.histories:779 break780 else:781 if groups is not None:782 for assoc in data.dataset.groups: #this is the association not the actual group783 assoc.delete()784 assoc.flush()785 for group in groups:786 group.add_dataset( data )787 if roles is not None:788 for assoc in data.dataset.roles: #this is the association not the actual group789 assoc.delete()790 assoc.flush()791 for role in roles:792 role.add_dataset( data )793 794 795 340 796 341 # class Query( object ): … … 802 347 # self.history = history 803 348 # self.datasets = [] 349 350 class Dataset( object ): 351 states = Bunch( NEW = 'new', 352 QUEUED = 'queued', 353 RUNNING = 'running', 354 OK = 'ok', 355 EMPTY = 'empty', 356 ERROR = 'error', 357 DISCARDED = 'discarded' ) 358 file_path = "/tmp/" 359 engine = None 360 def __init__( self, id=None, state=None, external_filename=None, extra_files_path=None, file_size=None, purgable=True ): 361 self.id = id 362 self.state = state 363 self.deleted = False 364 self.purged = False 365 self.purgable = purgable 366 self.external_filename = external_filename 367 self._extra_files_path = extra_files_path 368 self.file_size = file_size 369 370 def get_file_name( self ): 371 if not self.external_filename: 372 assert self.id is not None, "ID must be set before filename used (commit the object)" 373 # First try filename directly under file_path 374 filename = os.path.join( self.file_path, "dataset_%d.dat" % self.id ) 375 # Only use that filename if it already exists (backward compatibility), 376 # otherwise construct hashed path 377 if not os.path.exists( filename ): 378 dir = os.path.join( self.file_path, *directory_hash_id( self.id ) ) 379 # Create directory if it does not exist 380 try: 381 os.makedirs( dir ) 382 except OSError, e: 383 # File Exists is okay, otherwise reraise 384 if e.errno != errno.EEXIST: 385 raise 386 # Return filename inside hashed directory 387 return os.path.abspath( os.path.join( dir, "dataset_%d.dat" % self.id ) ) 388 else: 389 filename = self.external_filename 390 # Make filename absolute 391 return os.path.abspath( filename ) 392 393 def set_file_name ( self, filename ): 394 if not filename: 395 self.external_filename = None 396 else: 397 self.external_filename = filename 398 399 file_name = property( get_file_name, set_file_name ) 400 401 @property 402 def extra_files_path( self ): 403 if self._extra_files_path: 404 path = self._extra_files_path 405 else: 406 path = os.path.join( self.file_path, "dataset_%d_files" % self.id ) 407 #only use path directly under self.file_path if it exists 408 if not os.path.exists( path ): 409 path = os.path.join( os.path.join( self.file_path, *directory_hash_id( self.id ) ), "dataset_%d_files" % self.id ) 410 # Make path absolute 411 return os.path.abspath( path ) 412 413 def get_size( self ): 414 """Returns the size of the data on disk""" 415 if self.file_size: 416 return self.file_size 417 else: 418 try: 419 return os.path.getsize( self.file_name ) 420 except OSError: 421 return 0 422 def set_size( self ): 423 """Returns the size of the data on disk""" 424 try: 425 self.file_size = os.path.getsize( self.file_name ) 426 except OSError: 427 self.file_size = 0 428 def has_data( self ): 429 """Detects whether there is any data""" 430 return self.get_size() > 0 431 def mark_deleted( self, include_children=True ): 432 self.deleted = True 433 434 # FIXME: sqlalchemy will replace this 435 def _delete(self): 436 """Remove the file that corresponds to this data""" 437 try: 438 os.remove(self.data.file_name) 439 except OSError, e: 440 log.critical('%s delete error %s' % (self.__class__.__name__, e)) 804 441 805 442 class Old_Dataset( Dataset ): lib/galaxy/model/mapping.py
r1454 r1459 113 113 Column( "err_type", TrimmedString( 64 ) ), 114 114 Column( "attributes", TEXT ) ) 115 116 GalaxyGroup.table = Table( "galaxy_group", metadata,117 Column( "id", Integer, primary_key=True ),118 Column( "create_time", DateTime, default=now ),119 Column( "update_time", DateTime, default=now, onupdate=now ),120 Column( "name", TEXT ),121 Column( "priority", Integer ) )122 123 UserGroupAssociation.table = Table( "user_group_association", metadata,124 Column( "id", Integer, primary_key=True ),125 Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),126 Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),127 Column( "create_time", DateTime, default=now ),128 Column( "update_time", DateTime, default=now, onupdate=now ) )129 130 AccessRole.table = Table( "access_role", metadata,131 Column( "id", Integer, primary_key=True ),132 Column( "create_time", DateTime, default=now ),133 Column( "update_time", DateTime, default=now, onupdate=now ),134 Column( "name", TEXT ),135 Column( "actions", JSONType(), default=[] ),136 Column( "priority", Integer ) )137 138 UserRoleAssociation.table = Table( "user_role_association", metadata,139 Column( "id", Integer, primary_key=True ),140 Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),141 Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ),142 Column( "create_time", DateTime, default=now ),143 Column( "update_time", DateTime, default=now, onupdate=now ) )144 145 GroupRoleAssociation.table = Table( "group_role_association", metadata,146 Column( "id", Integer, primary_key=True ),147 Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),148 Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ),149 Column( "create_time", DateTime, default=now ),150 Column( "update_time", DateTime, default=now, onupdate=now ) )151 152 GroupDatasetAssociation.table = Table( "group_dataset_association", metadata,153 Column( "id", Integer, primary_key=True ),154 Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),155 Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),156 Column( "create_time", DateTime, default=now ),157 Column( "update_time", DateTime, default=now, onupdate=now ) )158 159 RoleDatasetAssociation.table = Table( "role_dataset_association", metadata,160 Column( "id", Integer, primary_key=True ),161 Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ),162 Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),163 Column( "create_time", DateTime, default=now ),164 Column( "update_time", DateTime, default=now, onupdate=now ) )165 166 RoleRoleAssociation.table = Table( "role_role_association", metadata,167 Column( "id", Integer, primary_key=True ),168 Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ),169 Column( "target_role_id", Integer, ForeignKey( "access_role.id" ), index=True ),170 Column( "create_time", DateTime, default=now ),171 Column( "update_time", DateTime, default=now, onupdate=now ) )172 173 GroupRoleAccessAssociation.table = Table( "group_role_access_association", metadata,174 Column( "id", Integer, primary_key=True ),175 Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ),176 Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),177 Column( "create_time", DateTime, default=now ),178 Column( "update_time", DateTime, default=now, onupdate=now ) )179 180 181 DefaultUserRoleAssociation.table = Table( "default_user_role_association", metadata,182 Column( "id", Integer, primary_key=True ),183 Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ),184 Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),185 Column( "create_time", DateTime, default=now ),186 Column( "update_time", DateTime, default=now, onupdate=now ) )187 188 DefaultUserGroupAssociation.table = Table( "default_user_group_association", metadata,189 Column( "id", Integer, primary_key=True ),190 Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),191 Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),192 Column( "create_time", DateTime, default=now ),193 Column( "update_time", DateTime, default=now, onupdate=now ) )194 195 DefaultHistoryRoleAssociation.table = Table( "default_history_role_association", metadata,196 Column( "id", Integer, primary_key=True ),197 Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ),198 Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),199 Column( "create_time", DateTime, default=now ),200 Column( "update_time", DateTime, default=now, onupdate=now ) )201 202 DefaultHistoryGroupAssociation.table = Table( "default_history_group_association", metadata,203 Column( "id", Integer, primary_key=True ),204 Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),205 Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),206 Column( "create_time", DateTime, default=now ),207 Column( "update_time", DateTime, default=now, onupdate=now ) )208 115 209 116 Job.table = Table( "job", metadata, … … 386 293 collection_class=ordering_list( 'order_index' ) ) 387 294 ) ) 388 389 assign_mapper( context, GalaxyGroup, GalaxyGroup.table,390 properties=dict( users=relation( UserGroupAssociation ),391 datasets=relation( GroupDatasetAssociation ) ) )392 393 assign_mapper( context, UserGroupAssociation, UserGroupAssociation.table,394 properties=dict( user=relation( User, backref = "groups" ),395 group=relation( GalaxyGroup, backref = "users" ) ) )396 397 assign_mapper( context, UserRoleAssociation, UserRoleAssociation.table,398 properties=dict( role=relation( AccessRole, backref = "users" ),399 user=relation( User, backref = "roles" ) ) )400 401 assign_mapper( context, GroupRoleAssociation, GroupRoleAssociation.table,402 properties=dict( role=relation( AccessRole, backref = "groups" ),403 group=relation( GalaxyGroup, backref = "roles" ) ) )404 405 assign_mapper( context, AccessRole, AccessRole.table )406 407 assign_mapper( context, GroupDatasetAssociation, GroupDatasetAssociation.table,408 properties=dict( dataset=relation( Dataset, backref = "groups" ),409 group=relation( GalaxyGroup, backref = "datasets" ) ) )410 411 assign_mapper( context, RoleDatasetAssociation, RoleDatasetAssociation.table,412 properties=dict( dataset=relation( Dataset, backref = "roles" ),413 role=relation( AccessRole ) ) )414 415 assign_mapper( context, RoleRoleAssociation, RoleRoleAssociation.table,416 properties=dict( role=relation( AccessRole, primaryjoin=( ( RoleRoleAssociation.table.c.role_id == AccessRole.table.c.id ) ) ),417 target_role=relation( AccessRole, primaryjoin=( RoleRoleAssociation.table.c.target_role_id == AccessRole.table.c.id ), backref="roles" ) ) )418 419 assign_mapper( context, GroupRoleAccessAssociation, GroupRoleAccessAssociation.table,420 properties=dict( role=relation( AccessRole, backref="access_groups" ),421 group=relation( GalaxyGroup, backref="access_roles" ) ) )422 423 assign_mapper( context, DefaultUserRoleAssociation, DefaultUserRoleAssociation.table,424 properties=dict( user=relation( User, backref = "default_roles" ),425 role=relation( AccessRole ) ) )426 427 assign_mapper( context, DefaultUserGroupAssociation, DefaultUserGroupAssociation.table,428 properties=dict( user=relation( User, backref = "default_groups" ),429 group=relation( GalaxyGroup ) ) )430 431 assign_mapper( context, DefaultHistoryRoleAssociation, DefaultHistoryRoleAssociation.table,432 properties=dict( history=relation( History, backref = "default_roles" ),433 role=relation( AccessRole ) ) )434 435 assign_mapper( context, DefaultHistoryGroupAssociation, DefaultHistoryGroupAssociation.table,436 properties=dict( history=relation( History, backref = "default_groups" ),437 group=relation( GalaxyGroup ) ) )438 295 439 296 assign_mapper( context, JobToInputDatasetAssociation, JobToInputDatasetAssociation.table, … … 550 407 result.context = context 551 408 result.create_tables = create_tables 552 #set up default table entries here, currently only exist for access controls553 if result.AccessRole.count() == 0:554 log.warning( "There were no access roles located, setting up default (public) access roles." )555 #create public group556 public_group = result.GalaxyGroup( 'public' )557 public_group.flush()558 #create public_all role559 public_role = result.AccessRole( 'public', [ result.Dataset.access_actions.USE, result.Dataset.access_actions.VIEW, result.GalaxyGroup.access_actions.ADD_DATASET, result.GalaxyGroup.access_actions.REMOVE_DATASET ] )560 public_role.flush()561 public_group.add_role( public_role )562 563 #store public group id564 GalaxyGroup.public_id = public_group.id #we use the id instead of the object, because of alchemy sessions565 #add all datasets to public group566 for dataset in result.Dataset.select():567 public_group.add_dataset( dataset )568 569 #loop through all current users and associate with the public group570 #and create and associate with user's own group571 for user in result.User.select():572 public_group.add_user( user )573 private_group = user.create_private_group()574 user.set_default_access( groups = [ public_group, private_group ], roles = [], history = True, dataset = True )575 else:576 #retrieve from database and store public group id, assume first created group is public577 GalaxyGroup.public_id = result.GalaxyGroup.select( order_by = asc( result.GalaxyGroup.table.c.create_time ) )[0].id #we use the id instead of the object, because of alchemy sessions578 log.debug( "Public Group identified as id = %s." % ( GalaxyGroup.public_id ) )579 409 return result 580 410 lib/galaxy/tools/__init__.py
r1454 r1459 1085 1085 else: visible = False 1086 <