Revision 3436eeb0 pithos/api/functions.py

b/pithos/api/functions.py
44 44
    LengthRequired, PreconditionFailed, RangeNotSatisfiable, UnprocessableEntity)
45 45
from pithos.api.util import (format_meta_key, printable_meta_dict, get_account_meta,
46 46
    put_account_meta, get_container_meta, put_container_meta, get_object_meta, put_object_meta,
47
    update_manifest_meta, validate_modification_preconditions, validate_matching_preconditions,
48
    split_container_object_string, copy_or_move_object, get_int_parameter, get_content_length,
49
    get_content_range, raw_input_socket, socket_read_iterator, object_data_response,
50
    put_object_block, hashmap_hash, api_method)
47
    update_manifest_meta, format_permissions, validate_modification_preconditions,
48
    validate_matching_preconditions, split_container_object_string, copy_or_move_object,
49
    get_int_parameter, get_content_length, get_content_range, get_sharing, raw_input_socket,
50
    socket_read_iterator, object_data_response, put_object_block, hashmap_hash, api_method)
51 51
from pithos.backends import backend
52 52

  
53 53

  
......
348 348
        else:
349 349
            try:
350 350
                meta = backend.get_object_meta(request.user, v_account, v_container, x[0], x[1])
351
                object_meta.append(printable_meta_dict(meta))
351
                permissions = backend.get_object_permissions(request.user, v_account, v_container, x[0])
352 352
            except NameError:
353 353
                pass
354
            if permissions:
355
                meta['X-Object-Sharing'] = format_permissions(permissions)
356
            object_meta.append(printable_meta_dict(meta))
354 357
    if request.serialization == 'xml':
355 358
        data = render_to_string('objects.xml', {'container': v_container, 'objects': object_meta})
356 359
    elif request.serialization  == 'json':
......
370 373
    version = get_int_parameter(request, 'version')
371 374
    try:
372 375
        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)
373 377
    except NameError:
374 378
        raise ItemNotFound('Object does not exist')
375 379
    except IndexError:
376 380
        raise ItemNotFound('Version does not exist')
377 381
    
382
    if permissions:
383
        meta['X-Object-Sharing'] = format_permissions(permissions)
378 384
    update_manifest_meta(request, v_account, meta)
379 385
    
380 386
    response = HttpResponse(status=200)
......
398 404
        version_list = True
399 405
    try:
400 406
        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)
401 408
    except NameError:
402 409
        raise ItemNotFound('Object does not exist')
403 410
    except IndexError:
404 411
        raise ItemNotFound('Version does not exist')
405 412
    
413
    if permissions:
414
        meta['X-Object-Sharing'] = format_permissions(permissions)
406 415
    update_manifest_meta(request, v_account, meta)
407 416
    
408 417
    # Evaluate conditions.
......
485 494
    # Error Response Codes: serviceUnavailable (503),
486 495
    #                       unprocessableEntity (422),
487 496
    #                       lengthRequired (411),
497
    #                       conflict (409),
488 498
    #                       itemNotFound (404),
489 499
    #                       unauthorized (401),
490 500
    #                       badRequest (400)
......
510 520
        return HttpResponse(status=201)
511 521
    
512 522
    meta = get_object_meta(request)
523
    permissions = get_sharing(request)
513 524
    content_length = -1
514 525
    if request.META.get('HTTP_TRANSFER_ENCODING') != 'chunked':
515 526
        content_length = get_content_length(request)
......
534 545
        raise UnprocessableEntity('Object ETag does not match')
535 546
    
536 547
    try:
537
        backend.update_object_hashmap(request.user, v_account, v_container, v_object, size, hashmap, meta, True)
548
        backend.update_object_hashmap(request.user, v_account, v_container, v_object, size, hashmap, meta, True, permissions)
538 549
    except NameError:
539 550
        raise ItemNotFound('Container does not exist')
551
    except ValueError:
552
        raise BadRequest('Invalid sharing header')
553
    except AttributeError:
554
        raise Conflict('Sharing already set above or below this path in the hierarchy')
540 555
    
541 556
    response = HttpResponse(status=201)
542 557
    response['ETag'] = meta['hash']
......
582 597
def object_update(request, v_account, v_container, v_object):
583 598
    # Normal Response Codes: 202, 204
584 599
    # Error Response Codes: serviceUnavailable (503),
600
    #                       conflict (409),
585 601
    #                       itemNotFound (404),
586 602
    #                       unauthorized (401),
587 603
    #                       badRequest (400)
588 604
    
589 605
    meta = get_object_meta(request)
606
    permissions = get_sharing(request)
590 607
    content_type = meta.get('Content-Type')
591 608
    if content_type:
592 609
        del(meta['Content-Type']) # Do not allow changing the Content-Type.
......
607 624
        except NameError:
608 625
            raise ItemNotFound('Object does not exist')
609 626
    
627
    # Handle permission changes.
628
    if permissions:
629
        try:
630
            backend.update_object_permissions(request.user, v_account, v_container, v_object, permissions)
631
        except NameError:
632
            raise ItemNotFound('Object does not exist')
633
        except ValueError:
634
            raise BadRequest('Invalid sharing header')
635
        except AttributeError:
636
            raise Conflict('Sharing already set above or below this path in the hierarchy')
637
    
638
    # TODO: Merge above functions with updating the hashmap if there is data in the request.
639
    
610 640
    # A Content-Type or Content-Range header may indicate data updates.
611 641
    if content_type is None:
612 642
        return HttpResponse(status=202)
......
665 695
        backend.update_object_hashmap(request.user, v_account, v_container, v_object, size, hashmap, meta, False)
666 696
    except NameError:
667 697
        raise ItemNotFound('Container does not exist')
668
        
698
    except ValueError:
699
        raise BadRequest('Invalid sharing header')
700
    except AttributeError:
701
        raise Conflict('Sharing already set above or below this path in the hierarchy')
702
    
669 703
    response = HttpResponse(status=204)
670 704
    response['ETag'] = meta['hash']
671 705
    return response

Also available in: Unified diff