소스 검색

HUE-9096 [doc] Adding link sharing API

Romain 6 년 전
부모
커밋
b4ea055e08
2개의 변경된 파일28개의 추가작업 그리고 0개의 파일을 삭제
  1. 27 0
      desktop/core/src/desktop/api2.py
  2. 1 0
      desktop/core/src/desktop/urls.py

+ 27 - 0
desktop/core/src/desktop/api2.py

@@ -649,6 +649,33 @@ def share_document(request):
   })
 
 
+@api_error_handler
+@require_POST
+def share_document_link(request):
+  """
+  Globally activate of de-activate access to the document to logged-in users.
+
+  Example of input: {'name': 'link_read', 'is_link_on': true}
+  """
+  perm = request.POST.get('data')
+  uuid = request.POST.get('uuid')
+
+  if not uuid or not perm:
+    raise PopupException(_('share_document_link requires uuid and permission data'))
+  else:
+    perm = json.loads(perm)
+    uuid = json.loads(uuid)
+
+  doc = Document2.objects.get_by_uuid(user=request.user, uuid=uuid)
+
+  doc = doc.share(request.user, name=perm['name'], is_link_on=perm['is_link_on'])
+
+  return JsonResponse({
+    'status': 0,
+    'document': doc.to_dict()
+  })
+
+
 @ensure_csrf_cookie
 def export_documents(request):
   if request.GET.get('documents'):

+ 1 - 0
desktop/core/src/desktop/urls.py

@@ -156,6 +156,7 @@ dynamic_patterns += [
   url(r'^desktop/api2/doc/delete/?$', desktop_api2.delete_document),
   url(r'^desktop/api2/doc/copy/?$', desktop_api2.copy_document),
   url(r'^desktop/api2/doc/restore/?$', desktop_api2.restore_document),
+  url(r'^desktop/api2/doc/share/link/?$', desktop_api2.share_document_link),
   url(r'^desktop/api2/doc/share/?$', desktop_api2.share_document),
 
   url(r'^desktop/api2/get_config/?$', desktop_api2.get_config),