Пример #1
1
def import_shares():
    admin = User.objects.get(username='******')
    select = """SELECT 
                    sp.description,
                    sp.random_dir,
                    sp.submitted,
                    p.description as pdescription,
                    p.project_title as ptitle,
                    g.db_group, 
                    t.type as type, 
                    t.description as type_description 
                FROM sub_project sp join project p on sp.project_id = p.project_id join type t on sp.type_id = t.type_id join db_group g on g.group_id = p.group_id"""
    subprojects = dictfetchall(select)
    for sp in subprojects:
        share_id = '00000%s'%sp['random_dir']
        try:
            share = Share.objects.get(id=share_id)
            share.delete()
        except:
            pass
        share = Share(id=share_id)
        share.name = ('%s: %s- %s, %s'%(sp['db_group'],sp['ptitle'],sp['type'],sp['submitted']))[:99]
        print 'Creating %s'%share.name[:99]
        share.notes = "Project Description:%s\nSubproject Description:%s"%(sp['pdescription'],sp['description'])
        share.owner=admin
        share.created = sp['submitted']
        share.save()
        tag = Tag.objects.get_or_create(name=sp['db_group'])[0]
        share.tags.add(tag)
        share.save()
Пример #2
0
def import_shares():
    admin = User.objects.get(username='******')
    select = """SELECT 
                    sp.description,
                    sp.random_dir,
                    sp.submitted,
                    p.description as pdescription,
                    p.project_title as ptitle,
                    g.db_group, 
                    t.type as type, 
                    t.description as type_description 
                FROM sub_project sp join project p on sp.project_id = p.project_id join type t on sp.type_id = t.type_id join db_group g on g.group_id = p.group_id"""
    subprojects = dictfetchall(select)
    for sp in subprojects:
        share_id = '00000%s' % sp['random_dir']
        try:
            share = Share.objects.get(id=share_id)
            share.delete()
        except:
            pass
        share = Share(id=share_id)
        share.name = (
            '%s: %s- %s, %s' %
            (sp['db_group'], sp['ptitle'], sp['type'], sp['submitted']))[:99]
        print 'Creating %s' % share.name[:99]
        share.notes = "Project Description:%s\nSubproject Description:%s" % (
            sp['pdescription'], sp['description'])
        share.owner = admin
        share.created = sp['submitted']
        share.save()
        tag = Tag.objects.get_or_create(name=sp['db_group'])[0]
        share.tags.add(tag)
        share.save()
Пример #3
0
 def wrapped_f(*args, **kwargs):
     from bioshareX.models import Share
     share = kwargs.get(self.share_param, None)
     if share:
         if not isinstance(kwargs[self.share_param], Share):
             try:
                 share = Share.get_by_slug_or_id(share)
             except Share.DoesNotExist:
                 return render(
                     args[0],
                     'errors/message.html',
                     {'message': 'No share with that ID exists.'},
                     status=500)
         if not paths_contain(settings.DIRECTORY_WHITELIST,
                              share.get_realpath()):
             raise Exception('Share has an invalid root path: %s' %
                             share.get_realpath())
     path = kwargs.get(self.path_param, None)
     if path is not None:
         test_path(path)
         if share:
             full_path = os.path.join(share.get_path(), path)
             if not paths_contain(settings.DIRECTORY_WHITELIST,
                                  full_path):
                 raise Exception('Illegal path encountered, %s, %s' %
                                 (share.get_path(), path))
     return f(*args, **kwargs)
Пример #4
0
 def __init__(self, server):
     self.server = server
     self.user = server.user
     self.shares = {}
     self.modified_date = {}
     for share in Share.user_queryset(self.user,include_stats=False):
         self.shares[share.slug_or_id] = share#{'path':share.get_realpath()}
Пример #5
0
def share_autocomplete(request):
    terms = [term.strip() for term in request.GET.get('query').split()]
    query = reduce(lambda q,value: q&Q(name__icontains=value), terms , Q())
    try:
        share_objs = Share.user_queryset(request.user).filter(query).order_by('-created')[:10]
        shares = [{'id':s.id,'url':reverse('list_directory',kwargs={'share':s.id}),'name':s.name,'notes':s.notes} for s in share_objs]
        return json_response({'status':'success','shares':shares})
    except Exception, e:
        return json_error([e.message])
Пример #6
0
def share_autocomplete(request):
    terms = [term.strip() for term in request.GET.get('query').split()]
    query = reduce(lambda q,value: q&Q(name__icontains=value), terms , Q())
    try:
        share_objs = Share.user_queryset(request.user).filter(query).order_by('-created')[:10]
        shares = [{'id':s.id,'url':reverse('list_directory',kwargs={'share':s.id}),'name':s.name,'notes':s.notes} for s in share_objs]
        return json_response({'status':'success','shares':shares})
    except Exception, e:
        return json_error([e.message])
Пример #7
0
 def wrapped_f(*args, **kwargs):
     from bioshareX.models import Share
     try:
         share = Share.get_by_slug_or_id(kwargs[self.share_param])
     except Share.DoesNotExist:
         return render(args[0],
                       'errors/message.html',
                       {'message': 'No share with that ID exists.'},
                       status=500)
     kwargs[self.share_param] = share
     request = args[0]
     user_permissions = share.get_user_permissions(request.user)
     for perm in self.perms:
         if not share.secure and perm in [
                 'view_share_files', 'download_share_files'
         ]:
             continue
         if not perm in user_permissions:
             if request.is_ajax():
                 if not request.user.is_authenticated():
                     return JsonResponse(
                         {
                             'status':
                             'error',
                             'unauthenticated':
                             True,
                             'errors': [
                                 'You do not have access to this resource.'
                             ]
                         },
                         status=status.HTTP_401_UNAUTHORIZED)
                     return json_error({
                         'status':
                         'error',
                         'unauthenticated':
                         True,
                         'errors':
                         ['You do not have access to this resource.']
                     })
                 else:
                     return json_error(
                         ['You do not have access to this resource.'])
             else:
                 if not request.user.is_authenticated():
                     url = reverse(
                         'login'
                     ) + '?next=%s' % request.get_full_path()
                     return redirect(url)
                 return redirect('forbidden')
     return f(*args, **kwargs)
Пример #8
0
 def _get_share(self,path):
     parts = path.split(os.path.sep)
     if len(parts) < 2:
         print 'bad length'
         raise PermissionDenied("Received an invalid path: %s"%path)
     if not self.shares.has_key(parts[1]) and self.user.id == -1: #Anonymous users don't yet have a dictionary of shares.
         try:
             share = Share.get_by_slug_or_id(parts[1])
             self.shares[share.slug_or_id] = share
         except:
             pass
     if not self.shares.has_key(parts[1]):
         print 'no share exists'
         print path
         raise PermissionDenied("Share does not exist: %s"%path[1])
     return self.shares[parts[1]]
Пример #9
0
 def wrapped_f(*args,**kwargs):
     from bioshareX.models import Share
     share = kwargs.get(self.share_param,None)
     if share:
         if not isinstance(kwargs[self.share_param], Share):
             share = Share.get_by_slug_or_id(share)
         if not paths_contain(settings.DIRECTORY_WHITELIST,share.get_realpath()):
             raise Exception('Share has an invalid root path: %s'%share.get_realpath())
     path = kwargs.get(self.path_param,None)
     if path is not None:
         test_path(path)
         if share:
             full_path = os.path.join(share.get_path(),path)
             if not paths_contain(settings.DIRECTORY_WHITELIST,full_path):
                 raise Exception('Illegal path encountered, %s, %s'%(share.get_path(),path))
     return f(*args,**kwargs)
Пример #10
0
 def wrapped_f(*args,**kwargs):
     from bioshareX.models import Share
     share = Share.get_by_slug_or_id(kwargs[self.share_param])
     kwargs[self.share_param]=share
     request = args[0]
     user_permissions = share.get_user_permissions(request.user)
     for perm in self.perms:
         if not share.secure and perm in ['view_share_files','download_share_files']:
             continue
         if not perm in user_permissions:
             if request.is_ajax():
                 if not request.user.is_authenticated():
                     return JsonResponse({'status':'error','unauthenticated':True,'errors':['You do not have access to this resource.']},status=status.HTTP_401_UNAUTHORIZED)
                     return json_error({'status':'error','unauthenticated':True,'errors':['You do not have access to this resource.']})
                 else:
                     return json_error(['You do not have access to this resource.'])
             else:
                 if not request.user.is_authenticated():
                     url = reverse('login') + '?next=%s' % request.get_full_path()
                     return redirect(url)
                 return redirect('forbidden')
     return f(*args,**kwargs)
Пример #11
0
 def get_queryset(self):
     return Share.user_queryset(self.request.user,include_stats=False).select_related('owner','stats').prefetch_related('tags','user_permissions__user','group_permissions__group')
Пример #12
0
 def get_queryset(self):
     shares = Share.user_queryset(self.request.user,include_stats=False)
     return ShareLog.objects.filter(share__in=shares)
Пример #13
0
 def get_queryset(self):
     return Share.user_queryset(self.request.user,include_stats=False).select_related('owner','stats').prefetch_related('tags','user_permissions__user','group_permissions__group')
Пример #14
0
 def get_queryset(self):
     shares = Share.user_queryset(self.request.user,include_stats=False)
     return ShareLog.objects.filter(share__in=shares)