|
|
@@ -16,16 +16,24 @@
|
|
|
# limitations under the License.
|
|
|
|
|
|
import logging
|
|
|
-from desktop.lib.exceptions_renderable import PopupException
|
|
|
+
|
|
|
+from django.utils.functional import wraps
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
+from desktop.lib.exceptions_renderable import PopupException
|
|
|
+
|
|
|
+from desktop.models import Document2
|
|
|
+
|
|
|
+
|
|
|
try:
|
|
|
from functools import wraps
|
|
|
except ImportError:
|
|
|
from django.utils.functional import wraps
|
|
|
|
|
|
+
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
+
|
|
|
def hue_permission_required(action, app):
|
|
|
"""
|
|
|
Checks that the user has permissions to do
|
|
|
@@ -41,3 +49,25 @@ def hue_permission_required(action, app):
|
|
|
return view_func(request, *args, **kwargs)
|
|
|
return decorated
|
|
|
return decorator
|
|
|
+
|
|
|
+
|
|
|
+def check_document_access_permission():
|
|
|
+ def inner(view_func):
|
|
|
+ def decorate(request, *args, **kwargs):
|
|
|
+ doc_id = {}
|
|
|
+
|
|
|
+ try:
|
|
|
+ if request.GET.get('uuid'):
|
|
|
+ doc_id['uuid'] = request.GET.get('uuid')
|
|
|
+ elif 'doc_id' in kwargs:
|
|
|
+ doc_id['id'] = kwargs['doc_id']
|
|
|
+
|
|
|
+ if doc_id:
|
|
|
+ doc2 = Document2.objects.get(**doc_id)
|
|
|
+ doc2.doc.get().can_read_or_exception(request.user)
|
|
|
+ except Document2.DoesNotExist:
|
|
|
+ raise PopupException(_('Job %(id)s does not exist') % {'id': doc_id})
|
|
|
+
|
|
|
+ return view_func(request, *args, **kwargs)
|
|
|
+ return wraps(view_func)(decorate)
|
|
|
+ return inner
|