def result(self, id): res = DBSession.query(Bresults).filter(Bresults.id == id).first() checker.check_permission(user=handler.user.get_user_in_session(request), project=res.job.project, right_id=constants.right_download_id) if res.rtype in constants.track_types: raise redirect(url('/tracks/links/%s' % res.track_id)) src = constants.extra_url() + '/' + res.rpath return dict(page='jobs', model='Job', src=src)
def result(self, id): res = DBSession.query(Bresults).filter(Bresults.id == id).first() checker.check_permission( user=handler.user.get_user_in_session(request), project=res.job.project, right_id=constants.right_download_id) if res.rtype in constants.track_types: raise redirect(url('/tracks/links/%s' % res.track_id)) src = constants.extra_url() + '/' + res.rpath return dict(page='jobs', model='Job', src=src)
def edit(self, *args, **kw): user = handler.user.get_user_in_session(request) if request.method == 'GET': project_id = args[0] else: project_id = kw.get('pid') debug("check permission", 1) if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id) and not checker.is_admin(user=user): flash('You must have %s permission to edit the project.' % constants.right_upload, 'error') raise redirect('/tracks/', {'pid': project_id}) #if checker.is_admin(user=user): #user = DBSession.query(User).join(Project).filter(Project.id == project_id).first() widget = form.EditProject(action=url('/projects/edit/%s' % project_id)).req() widget.value = {'pid': project_id} project = DBSession.query(Project).filter(Project.id == project_id).first() # prendre les user tracks du meme sequence id tracks = DBSession.query(Track).join(User.tracks).filter( and_(User.id == user.id, Track.sequence_id == project.sequence_id, not_(Track.id.in_([t.id for t in project.tracks]))) ).all() # prendre les sared tracks du meme sequence id shared_tracks = handler.user.shared_tracks(user.id, constants.rights['download']['id']) shared_tracks = [t for t in shared_tracks if (t.sequence_id == project.sequence_id and t.id not in [tr.id for tr in project.tracks])] tracks.extend(shared_tracks) if request.method == 'GET': debug("GET", 2) widget.child.children[1].value = project.name widget.child.children[2].options = [('', '')] + [(t.id, t.name) for t in tracks] + [(t.id, t.name, {'selected': True}) for t in project.tracks] return dict(page='tracks', widget=widget, project_id=project_id) debug("POST", 2) try: debug("validate post", 2) widget.validate(kw) except twc.ValidationError as e: debug("error", 2) w = e.widget w.child.children[1].value = project.name w.child.children[2].options = [(t.id, t.name) for t in tracks] + [(t.id, t.name, {'selected': True}) for t in project.tracks] return dict(page='tracks', widget=w, project_id=project_id) debug("validation passed") track_ids = kw.get('tracks', []) if not track_ids: track_ids = [] if not isinstance(track_ids, list): track_ids = [track_ids] if len(track_ids) > 0 and '' in track_ids: track_ids.remove('') # if the project is shared, some track cannot be removed for t in project.tracks: if not checker.user_own_track(user.id, track=t) and t.id not in track_ids and t.id in [s.id for s in shared_tracks]: track_ids.append(t.id) handler.project.e(project_id=project_id, name=kw.get('name'), track_ids=track_ids) raise redirect('/tracks/', {'pid': project_id})
def view(self, project_id, *args, **kw): debug('VIEW') user = handler.user.get_user_in_session(request) if not checker.check_permission(project_id=project_id, user=user, right_id=constants.rights['read']['id']): flash('You must have %s permission to view the project.' % constants.right_read, 'error') raise redirect(url('/')) d = handler.view.prepare_view(project_id, *args, **kw) response.headerlist.append(('Access-Control-Allow-Origin', '*')) return d
def delete(self, *args, **kw): user = handler.user.get_user_in_session(request) if len(args) > 0: project_id = args[0] if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id) and not checker.is_admin(user=user): return reply.error(request, "You must have %s permission to delete the project." % constants.right_upload, '/tracks', {'error': 'wrong credentials'}) handler.project.delete(project_id=project_id) return reply.normal(request, 'Project successfully deleted.', '/tracks', {'success': 'project deleted'})
def delete(self, project_id, selection_id): user = handler.user.get_user_in_session(request) if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id): flash('You must have %s permission to delete the project.' % constants.right_upload, 'error') return {'delete': 'failed'} selection = DBSession.query(Selection).filter(Selection.id == selection_id).first() if not selection.project_id == project_id: flash('Bad project_id: %s' % project_id, 'error') return {'delete': 'failed'} DBSession.delete(selection) DBSession.flush() return {'delete': 'success'}
def share(self, *args, **kw): user = handler.user.get_user_in_session(request) if request.method == 'GET': project_id = args[0] else: project_id = kw.get('pid') if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id) and not checker.is_admin(user=user): flash('You must have %s permission to share the project', 'error') % constants.right_upload raise redirect('/tracks', {'pid': project_id}) project = DBSession.query(Project).filter(Project.id == project_id).first() widget = form.ShareProject(action=url('/projects/share/%s' % project_id)) # public url pub = url('/public/project', {'id': project_id, 'k': project.key}) # download url if project.download_key is None: project.download_key = project.setdefaultkey() down = url('/public/project', {'id': project_id, 'k': project.download_key}) widget.value = {'pid': project_id} tl = handler.help.help_address(url('help'), '#share', 'sharing projects') if request.method == 'POST': if kw.has_key('rights'): rights_checkboxes = kw.get('rights_checkboxes', None) if rights_checkboxes is not None: if not isinstance(rights_checkboxes,list): rights_checkboxes = [rights_checkboxes] handler.project.change_rights(kw.get('pid'), kw.get('cid'), rights=rights_checkboxes) else: handler.project.change_rights(kw.get('pid'), kw.get('cid')) else: circle_ids = kw.get('circles', []) if not circle_ids: circle_ids = [] if not isinstance(circle_ids, list): circle_ids = [circle_ids] if len(circle_ids) > 0 and '' in circle_ids: circle_ids.remove('') handler.project.e(project=project, circle_ids=circle_ids) debug(project.get_circle_with_right_display) cr_data = [util.to_datagrid(datagrid.project_sharing, project.circles_rights, "Sharing", len(project.circles_rights)>0)] widget.child.children[1].options = [('','')] + [(c.id, c.name) for c in user.circles_sharing if c not in project.shared_circles] +\ [(c.id, c.name, {'selected': True}) for c in project.shared_circles] return dict(page='projects', public=pub, download=down, name=project.name, tooltip_links=tl, widget=widget, items=cr_data, project_id=project_id)
def save(self, project_id, color, description, locations): user = handler.user.get_user_in_session(request) if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id): flash( 'You must have %s permission to delete the project.' % constants.right_upload, 'error') return {'save': 'failed'} #print "save %s, color %s, desc %s loc %s" % (project_id, color, description, locations) ''' For the moment, there is only one selection per project''' sel = DBSession.query(Selection).filter( Selection.project_id == project_id).first() if sel is None: sel = Selection() sel.project_id = project_id sel.description = description sel.color = color DBSession.add(sel) DBSession.flush() locations_ids = [] # add locations for loc in json.loads(locations): obj = None if 'id' in loc: obj = DBSession.query(Location).join( Selection.locations).filter( and_(Selection.id == sel.id, Location.id == loc.get('id'))).first() if obj is None: obj = Location() obj.chromosome = loc.get('chr') obj.start = loc.get('start') obj.end = loc.get('end') obj.description = loc.get('desc', 'No description') obj.selection = sel DBSession.add(obj) DBSession.flush() locations_ids.append(obj.id) # remove not saved ones loc_to_remove = DBSession.query(Location).filter( not_(Location.id.in_(locations_ids))).all() for l in loc_to_remove: DBSession.delete(l) DBSession.flush() return {"saved": "ok"}
def view(self, project_id, *args, **kw): debug('VIEW') user = handler.user.get_user_in_session(request) if not checker.check_permission( project_id=project_id, user=user, right_id=constants.rights['read']['id']): flash( 'You must have %s permission to view the project.' % constants.right_read, 'error') raise redirect(url('/')) d = handler.view.prepare_view(project_id, *args, **kw) response.headerlist.append(('Access-Control-Allow-Origin', '*')) return d
def delete(self, project_id, selection_id): user = handler.user.get_user_in_session(request) if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id): flash( 'You must have %s permission to delete the project.' % constants.right_upload, 'error') return {'delete': 'failed'} selection = DBSession.query(Selection).filter( Selection.id == selection_id).first() if not selection.project_id == project_id: flash('Bad project_id: %s' % project_id, 'error') return {'delete': 'failed'} DBSession.delete(selection) DBSession.flush() return {'delete': 'success'}
def delete(self, *args, **kw): user = handler.user.get_user_in_session(request) if len(args) > 0: project_id = args[0] if not checker.check_permission( user=user, project_id=project_id, right_id=constants.right_upload_id ) and not checker.is_admin(user=user): return reply.error( request, "You must have %s permission to delete the project." % constants.right_upload, '/tracks', {'error': 'wrong credentials'}) handler.project.delete(project_id=project_id) return reply.normal(request, 'Project successfully deleted.', '/tracks', {'success': 'project deleted'})
def save(self, project_id, color, description, locations): user = handler.user.get_user_in_session(request) if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id): flash('You must have %s permission to delete the project.' % constants.right_upload, 'error') return {'save': 'failed'} #print "save %s, color %s, desc %s loc %s" % (project_id, color, description, locations) ''' For the moment, there is only one selection per project''' sel = DBSession.query(Selection).filter(Selection.project_id == project_id).first() if sel is None: sel = Selection() sel.project_id = project_id sel.description = description sel.color = color DBSession.add(sel) DBSession.flush() locations_ids = [] # add locations for loc in json.loads(locations): obj = None if 'id' in loc: obj = DBSession.query(Location).join(Selection.locations).filter( and_(Selection.id == sel.id, Location.id == loc.get('id'))).first() if obj is None: obj = Location() obj.chromosome = loc.get('chr') obj.start = loc.get('start') obj.end = loc.get('end') obj.description = loc.get('desc', 'No description') obj.selection = sel DBSession.add(obj) DBSession.flush() locations_ids.append(obj.id) # remove not saved ones loc_to_remove = DBSession.query(Location).filter(not_(Location.id.in_(locations_ids))).all() for l in loc_to_remove: DBSession.delete(l) DBSession.flush() return {"saved": "ok"}
def edit(self, *args, **kw): user = handler.user.get_user_in_session(request) if request.method == 'GET': project_id = args[0] else: project_id = kw.get('pid') debug("check permission", 1) if not checker.check_permission( user=user, project_id=project_id, right_id=constants.right_upload_id) and not checker.is_admin( user=user): flash( 'You must have %s permission to edit the project.' % constants.right_upload, 'error') raise redirect('/tracks/', {'pid': project_id}) #if checker.is_admin(user=user): #user = DBSession.query(User).join(Project).filter(Project.id == project_id).first() widget = form.EditProject(action=url('/projects/edit/%s' % project_id)).req() widget.value = {'pid': project_id} project = DBSession.query(Project).filter( Project.id == project_id).first() # prendre les user tracks du meme sequence id tracks = DBSession.query(Track).join(User.tracks).filter( and_(User.id == user.id, Track.sequence_id == project.sequence_id, not_(Track.id.in_([t.id for t in project.tracks])))).all() # prendre les sared tracks du meme sequence id shared_tracks = handler.user.shared_tracks( user.id, constants.rights['download']['id']) shared_tracks = [ t for t in shared_tracks if (t.sequence_id == project.sequence_id and t.id not in [tr.id for tr in project.tracks]) ] tracks.extend(shared_tracks) if request.method == 'GET': debug("GET", 2) widget.child.children[1].value = project.name widget.child.children[2].options = [('', '')] + [ (t.id, t.name) for t in tracks ] + [(t.id, t.name, { 'selected': True }) for t in project.tracks] return dict(page='tracks', widget=widget, project_id=project_id) debug("POST", 2) try: debug("validate post", 2) widget.validate(kw) except twc.ValidationError as e: debug("error", 2) w = e.widget w.child.children[1].value = project.name w.child.children[2].options = [(t.id, t.name) for t in tracks ] + [(t.id, t.name, { 'selected': True }) for t in project.tracks] return dict(page='tracks', widget=w, project_id=project_id) debug("validation passed") track_ids = kw.get('tracks', []) if not track_ids: track_ids = [] if not isinstance(track_ids, list): track_ids = [track_ids] if len(track_ids) > 0 and '' in track_ids: track_ids.remove('') # if the project is shared, some track cannot be removed for t in project.tracks: if not checker.user_own_track( user.id, track=t) and t.id not in track_ids and t.id in [ s.id for s in shared_tracks ]: track_ids.append(t.id) handler.project.e(project_id=project_id, name=kw.get('name'), track_ids=track_ids) raise redirect('/tracks/', {'pid': project_id})
def share(self, *args, **kw): user = handler.user.get_user_in_session(request) if request.method == 'GET': project_id = args[0] else: project_id = kw.get('pid') if not checker.check_permission( user=user, project_id=project_id, right_id=constants.right_upload_id) and not checker.is_admin( user=user): flash('You must have %s permission to share the project', 'error') % constants.right_upload raise redirect('/tracks', {'pid': project_id}) project = DBSession.query(Project).filter( Project.id == project_id).first() widget = form.ShareProject(action=url('/projects/share/%s' % project_id)) # public url pub = url('/public/project', {'id': project_id, 'k': project.key}) # download url if project.download_key is None: project.download_key = project.setdefaultkey() down = url('/public/project', { 'id': project_id, 'k': project.download_key }) widget.value = {'pid': project_id} tl = handler.help.help_address(url('help'), '#share', 'sharing projects') if request.method == 'POST': if kw.has_key('rights'): rights_checkboxes = kw.get('rights_checkboxes', None) if rights_checkboxes is not None: if not isinstance(rights_checkboxes, list): rights_checkboxes = [rights_checkboxes] handler.project.change_rights(kw.get('pid'), kw.get('cid'), rights=rights_checkboxes) else: handler.project.change_rights(kw.get('pid'), kw.get('cid')) else: circle_ids = kw.get('circles', []) if not circle_ids: circle_ids = [] if not isinstance(circle_ids, list): circle_ids = [circle_ids] if len(circle_ids) > 0 and '' in circle_ids: circle_ids.remove('') handler.project.e(project=project, circle_ids=circle_ids) debug(project.get_circle_with_right_display) cr_data = [ util.to_datagrid(datagrid.project_sharing, project.circles_rights, "Sharing", len(project.circles_rights) > 0) ] widget.child.children[1].options = [('','')] + [(c.id, c.name) for c in user.circles_sharing if c not in project.shared_circles] +\ [(c.id, c.name, {'selected': True}) for c in project.shared_circles] return dict(page='projects', public=pub, download=down, name=project.name, tooltip_links=tl, widget=widget, items=cr_data, project_id=project_id)
def index(self, *args, **kw): user = handler.user.get_user_in_session(request) shared_by = None # view on a specific project if 'pid' in kw and kw.get('pid'): project_id = kw.get('pid') project = DBSession.query(Project).filter(Project.id == project_id).first() if project is None: flash("Project doesn't exists", "error") raise redirect('/tracks') if not checker.check_permission(user=user, project=project, right_id=constants.right_read_id): flash('You must have %s permission to view the project.' % constants.right_read, 'error') raise redirect('/tracks') tracks = project.tracks # view on user project if checker.own(user=user, project=project): kw['own'] = True kw['upload'] = True grid = datagrid.track_grid_user(user, project) # view from a shared user else: rights = handler.project.get_rights(project=project, user=user) debug('find %s' % rights, 2) if constants.right_upload_id in [r.id for r in rights]: kw['upload'] = True debug('view from a shared user %s' % rights) grid = datagrid.track_grid_permissions(user=user, rights=rights, project=project) shared_by = "%s %s" % (project.user.firstname, project.user.name[0].upper()) kw['pn'] = project.name track_list = [util.to_datagrid(grid, tracks, "Track Listing", len(tracks) > 0)] shared_with = project.get_circle_with_right_display # view all user tracks else: if 'pid' in kw: del kw['pid'] shared_with = '' tracks = list(user.tracks) # shared tracks shared_tracks = handler.user.shared_tracks(user.id, constants.rights['download']['id']) tracks.extend(shared_tracks) debug('shared tracks : %s' % ', '.join((str(x) for x in shared_tracks))) track_list = [util.to_datagrid(datagrid.track_grid_user(user), tracks, "Track Listing", len(tracks) > 0)] kw['upload'] = True t = handler.help.help_address(url('/help'), 'main', 'track list help') # project list project_list = [(p.id, p.name,) for p in user.projects] # shared projects shared_with_rights = handler.project.get_shared_projects(user) sorted_projects = sorted(shared_with_rights.iteritems(), key=lambda k: k[0].name) shared_project_list = [(p.id, p.name, ''.join([r[0] for r in rights])) for p, rights in sorted_projects] return dict(page='tracks', model='track', form_title="new track", track_list=track_list, project_list=project_list, shared_project_list=shared_project_list, value=kw, tooltip=t, project_id=kw.get('pid', None), upload=kw.get('upload', None), project_name=kw.get('pn', None), shared_with=shared_with, owner=kw.get('own', False), shared=not kw.get('own', False), shared_by=shared_by)