Exemplo n.º 1
0
def share_document(request):
    """
  Set who else or which other group can interact with the document.

  Example of input: {'read': {'user_ids': [1, 2, 3], 'group_ids': [1, 2, 3]}}
  """
    if not is_admin(request.user) and not ENABLE_SHARING.get():
        return serve_403_error(request)

    uuid = request.POST.get('uuid')
    perms_dict = request.POST.get('data')

    if not uuid or not perms_dict:
        raise PopupException(_('share_document requires uuid and perms_dict'))
    else:
        perms_dict = json.loads(perms_dict)
        uuid = json.loads(uuid)

    doc = Document2.objects.get_by_uuid(user=request.user, uuid=uuid)

    for name, perm in perms_dict.items():
        users = groups = None
        if perm.get('user_ids'):
            users = User.objects.in_bulk(perm.get('user_ids'))
        else:
            users = []

        if perm.get('group_ids'):
            groups = Group.objects.in_bulk(perm.get('group_ids'))
        else:
            groups = []

        doc = doc.share(request.user, name=name, users=users, groups=groups)

    return JsonResponse({'status': 0, 'document': doc.to_dict()})
Exemplo n.º 2
0
def share_document_link(request):
    """
  Globally activate of de-activate access to a document for logged-in users.

  Example of input: {"uuid": "xxxx", "perm": "read" / "write" / "off"}
  """
    if not is_admin(request.user) and not ENABLE_SHARING.get():
        return serve_403_error(request)

    uuid = request.POST.get('uuid')
    perm = request.POST.get('perm')

    if not uuid or not perm:
        raise PopupException(
            _('share_document_link requires uuid and permission data'))
    else:
        uuid = json.loads(uuid)
        perm = json.loads(perm)

    doc = Document2.objects.get_by_uuid(user=request.user, uuid=uuid)
    doc = doc.share_link(request.user, perm=perm)

    return JsonResponse({'status': 0, 'document': doc.to_dict()})