Revision e8886082

b/pithos/api/functions.py
348 348
        else:
349 349
            try:
350 350
                meta = backend.get_object_meta(request.user, v_account, v_container, x[0], x[1])
351
                permissions = backend.get_object_permissions(request.user, v_account, v_container, x[0])
351
                if until is None:
352
                    permissions = backend.get_object_permissions(request.user, v_account, v_container, x[0])
353
                else:
354
                    permissions = None
352 355
            except NameError:
353 356
                pass
354 357
            if permissions:
......
373 376
    version = get_int_parameter(request, 'version')
374 377
    try:
375 378
        meta = backend.get_object_meta(request.user, v_account, v_container, v_object, version)
376
        permissions = backend.get_object_permissions(request.user, v_account, v_container, v_object)
379
        if version is None:
380
            permissions = backend.get_object_permissions(request.user, v_account, v_container, v_object)
381
        else:
382
            permissions = None
377 383
    except NameError:
378 384
        raise ItemNotFound('Object does not exist')
379 385
    except IndexError:
......
399 405
    #                       notModified (304)
400 406
    
401 407
    version = get_int_parameter(request, 'version')
402
    version_list = False
408
    
409
    # Reply with the version list. Do this first, as the object may be deleted.
403 410
    if version is None and request.GET.get('version') == 'list':
404
        version_list = True
411
        if request.serialization == 'text':
412
            raise BadRequest('No format specified for version list.')
413
        
414
        d = {'versions': backend.list_versions(request.user, v_account, v_container, v_object)}
415
        if request.serialization == 'xml':
416
            d['object'] = v_object
417
            data = render_to_string('versions.xml', d)
418
        elif request.serialization  == 'json':
419
            data = json.dumps(d)
420
        
421
        response = HttpResponse(data, status=200)
422
        response['Content-Length'] = len(data)
423
        return response
424
    
405 425
    try:
406 426
        meta = backend.get_object_meta(request.user, v_account, v_container, v_object, version)
407
        permissions = backend.get_object_permissions(request.user, v_account, v_container, v_object)
427
        if version is None:
428
            permissions = backend.get_object_permissions(request.user, v_account, v_container, v_object)
429
        else:
430
            permissions = None
408 431
    except NameError:
409 432
        raise ItemNotFound('Object does not exist')
410 433
    except IndexError:
......
423 446
        response['ETag'] = meta['hash']
424 447
        return response
425 448
    
426
    # Reply with the version list.
427
    if version_list:
428
        if request.serialization == 'text':
429
            raise BadRequest('No format specified for version list.')
430
        
431
        d = {'versions': backend.list_versions(request.user, v_account, v_container, v_object)}
432
        if request.serialization == 'xml':
433
            d['object'] = v_object
434
            data = render_to_string('versions.xml', d)
435
        elif request.serialization  == 'json':
436
            data = json.dumps(d)
437
        
438
        response = HttpResponse(data, status=200)
439
        put_object_meta(response, meta)
440
        response['Content-Length'] = len(data)
441
        return response
442
    
443 449
    sizes = []
444 450
    hashmaps = []
445 451
    if 'X-Object-Manifest' in meta:
b/pithos/api/util.py
174 174

  
175 175
def format_permissions(permissions):
176 176
    ret = []
177
    if 'public' in permissions:
178
        ret.append('public')
179 177
    if 'private' in permissions:
180 178
        ret.append('private')
181 179
    r = ','.join(permissions.get('read', []))
......
234 232
    
235 233
    meta = get_object_meta(request)
236 234
    permissions = get_sharing(request)
237
    # Keep previous values of 'Content-Type' (if a new one is absent) and 'hash'.
235
    src_version = request.META.get('HTTP_X_SOURCE_VERSION')
236
    
238 237
    try:
239
        src_meta = backend.get_object_meta(request.user, v_account, src_container, src_name)
240
    except NameError:
238
        if move:
239
            src_meta = backend.get_object_meta(request.user, v_account, src_container, src_name)
240
        else:
241
            src_meta = backend.get_object_meta(request.user, v_account, src_container, src_name, src_version)
242
    except NameError, IndexError:
241 243
        raise ItemNotFound('Container or object does not exist')
244
    
245
    # Keep previous values of 'Content-Type' (if a new one is absent) and 'hash'.
242 246
    if 'Content-Type' in meta and 'Content-Type' in src_meta:
243 247
        del(src_meta['Content-Type'])
244 248
    for k in ('Content-Type', 'hash'):
......
249 253
        if move:
250 254
            backend.move_object(request.user, v_account, src_container, src_name, dest_container, dest_name, meta, True, permissions)
251 255
        else:
252
            src_version = request.META.get('HTTP_X_SOURCE_VERSION')
253 256
            backend.copy_object(request.user, v_account, src_container, src_name, dest_container, dest_name, meta, True, permissions, src_version)
254
    except NameError:
257
    except NameError, IndexError:
255 258
        raise ItemNotFound('Container or object does not exist')
256 259
    except ValueError:
257 260
        raise BadRequest('Invalid sharing header')
......
370 373
    
371 374
    ret = {}
372 375
    for perm in (x.replace(' ','') for x in permissions.split(';')):
373
        if perm == 'public':
374
            ret['public'] = True
375
            continue
376
        elif perm == 'private':
376
        if perm == 'private':
377 377
            ret['private'] = True
378 378
            continue
379 379
        elif perm.startswith('read='):
380 380
            ret['read'] = [v.replace(' ','') for v in perm[5:].split(',')]
381
            if '*' in ret['read']:
382
                ret['read'] = ['*']
381 383
            if len(ret['read']) == 0:
382 384
                raise BadRequest('Bad X-Object-Sharing header value')
383 385
        elif perm.startswith('write='):
384 386
            ret['write'] = [v.replace(' ','') for v in perm[6:].split(',')]
387
            if '*' in ret['write']:
388
                ret['write'] = ['*']
385 389
            if len(ret['write']) == 0:
386 390
                raise BadRequest('Bad X-Object-Sharing header value')
387 391
        else:
388 392
            raise BadRequest('Bad X-Object-Sharing header value')
393
    if 'private' in ret:
394
        if 'read' in ret:
395
            del(ret['read'])
396
        if 'write' in ret:
397
            del(ret['write'])
389 398
    return ret
390 399

  
391 400
def raw_input_socket(request):
b/pithos/backends/simple.py
217 217
        if version is None:
218 218
            modified = mtime
219 219
        else:
220
            modified = self._get_version(path)[1] # Overall last modification
220
            modified = self._get_version(path, version)[1] # Overall last modification
221 221
        
222 222
        meta = self._get_metadata(path, version_id)
223 223
        meta.update({'name': name, 'bytes': size, 'version': version_id, 'version_timestamp': mtime, 'modified': modified})
......
323 323
        logger.debug("list_versions: %s %s %s", account, container, name)
324 324
        # This will even show deleted versions.
325 325
        path = os.path.join(account, container, name)
326
        sql = '''select distinct version_id, strftime('%s', tstamp) from versions where name = ?'''
326
        sql = '''select distinct version_id, strftime('%s', tstamp) from versions where name = ? and hide = 0'''
327 327
        c = self.con.execute(sql, (path,))
328 328
        return [(int(x[0]), int(x[1])) for x in c.fetchall()]
329 329
    
......
491 491
        sql = '''select name from permissions
492 492
                    where name != ? and (name like ? or ? like name || ?)'''
493 493
        c = self.con.execute(sql, (path, path + '%', path, '%'))
494
        if c.fetchall() is not None:
494
        rows = c.fetchall()
495
        if rows:
495 496
            raise AttributeError('Permissions already set')
496 497
        
497 498
        # Format given permissions set.
498 499
        r = permissions.get('read', [])
499 500
        w = permissions.get('write', [])
500
        if True in [False or '*' in x or ',' in x for x in r]:
501
        if True in [False or ',' in x for x in r]:
501 502
            raise ValueError('Bad characters in read permissions')
502
        if True in [False or '*' in x or ',' in x for x in w]:
503
        if True in [False or ',' in x for x in w]:
503 504
            raise ValueError('Bad characters in write permissions')
504 505
        r = ','.join(r)
505 506
        w = ','.join(w)
506
        if 'public' in permissions:
507
            r = '*'
508 507
        if 'private' in permissions:
509 508
            r = ''
510 509
            w = ''
......
524 523
        if w != '':
525 524
            ret['write'] = w.split(',')
526 525
        if r != '':
527
            if r == '*':
528
                ret['public'] = True
529
            else:
530
                ret['read'] = r.split(',')        
526
            ret['read'] = r.split(',')        
531 527
        return ret
532 528
    
533 529
    def _put_permissions(self, path, r, w):

Also available in: Unified diff