|
@@ -20,17 +20,15 @@ import json
|
|
|
|
|
|
|
|
from nose.tools import assert_true, assert_false, assert_equal, assert_not_equal, assert_raises
|
|
from nose.tools import assert_true, assert_false, assert_equal, assert_not_equal, assert_raises
|
|
|
|
|
|
|
|
-from django.conf.urls import patterns, url
|
|
|
|
|
from django.contrib.auth.models import User
|
|
from django.contrib.auth.models import User
|
|
|
-from django.core.urlresolvers import reverse
|
|
|
|
|
-from django.db.models import query, CharField, SmallIntegerField
|
|
|
|
|
|
|
|
|
|
|
|
+from beeswax.conf import USE_NEW_EDITOR
|
|
|
|
|
+from desktop.api import massaged_documents_for_json, _get_docs
|
|
|
from desktop.lib.django_test_util import make_logged_in_client
|
|
from desktop.lib.django_test_util import make_logged_in_client
|
|
|
from desktop.lib.test_utils import grant_access
|
|
from desktop.lib.test_utils import grant_access
|
|
|
from desktop.models import DocumentTag , Document
|
|
from desktop.models import DocumentTag , Document
|
|
|
from pig.models import PigScript
|
|
from pig.models import PigScript
|
|
|
from useradmin.models import get_default_user_group
|
|
from useradmin.models import get_default_user_group
|
|
|
-from desktop.api import massaged_documents_for_json, _get_docs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDocModelTags():
|
|
class TestDocModelTags():
|
|
@@ -203,6 +201,8 @@ class TestDocModelPermissions():
|
|
|
self.user = User.objects.get(username="perm_user")
|
|
self.user = User.objects.get(username="perm_user")
|
|
|
self.user_not_me = User.objects.get(username="not_perm_user")
|
|
self.user_not_me = User.objects.get(username="not_perm_user")
|
|
|
|
|
|
|
|
|
|
+ self.old_home_path = '/home2' if USE_NEW_EDITOR.get() else '/home'
|
|
|
|
|
+
|
|
|
grant_access(self.user.username, self.user.username, "desktop")
|
|
grant_access(self.user.username, self.user.username, "desktop")
|
|
|
grant_access(self.user_not_me.username, self.user_not_me.username, "desktop")
|
|
grant_access(self.user_not_me.username, self.user_not_me.username, "desktop")
|
|
|
|
|
|
|
@@ -226,18 +226,18 @@ class TestDocModelPermissions():
|
|
|
|
|
|
|
|
def test_share_document_permissions(self):
|
|
def test_share_document_permissions(self):
|
|
|
# No doc
|
|
# No doc
|
|
|
- response = self.client.get('/home2')
|
|
|
|
|
|
|
+ response = self.client.get(self.old_home_path)
|
|
|
assert_equal({}, json.loads(response.context['json_documents']))
|
|
assert_equal({}, json.loads(response.context['json_documents']))
|
|
|
- response = self.client_not_me.get('/home2')
|
|
|
|
|
|
|
+ response = self.client_not_me.get(self.old_home_path)
|
|
|
assert_equal({}, json.loads(response.context['json_documents']))
|
|
assert_equal({}, json.loads(response.context['json_documents']))
|
|
|
|
|
|
|
|
# Add doc
|
|
# Add doc
|
|
|
script, doc = self._add_doc('test_update_permissions')
|
|
script, doc = self._add_doc('test_update_permissions')
|
|
|
doc_id = '%s' % doc.id
|
|
doc_id = '%s' % doc.id
|
|
|
|
|
|
|
|
- response = self.client.get('/home2')
|
|
|
|
|
|
|
+ response = self.client.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
- response = self.client_not_me.get('/home2')
|
|
|
|
|
|
|
+ response = self.client_not_me.get(self.old_home_path)
|
|
|
assert_false(doc_id in json.loads(response.context['json_documents']))
|
|
assert_false(doc_id in json.loads(response.context['json_documents']))
|
|
|
|
|
|
|
|
assert_true(doc.can_read(self.user))
|
|
assert_true(doc.can_read(self.user))
|
|
@@ -270,9 +270,9 @@ class TestDocModelPermissions():
|
|
|
assert_true(doc.can_read(self.user_not_me))
|
|
assert_true(doc.can_read(self.user_not_me))
|
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
|
|
|
|
|
|
- response = self.client.get('/home2')
|
|
|
|
|
|
|
+ response = self.client.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
- response = self.client_not_me.get('/home2')
|
|
|
|
|
|
|
+ response = self.client_not_me.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
|
|
|
|
|
# Un-share
|
|
# Un-share
|
|
@@ -299,9 +299,9 @@ class TestDocModelPermissions():
|
|
|
assert_false(doc.can_read(self.user_not_me))
|
|
assert_false(doc.can_read(self.user_not_me))
|
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
|
|
|
|
|
|
- response = self.client.get('/home2')
|
|
|
|
|
|
|
+ response = self.client.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
- response = self.client_not_me.get('/home2')
|
|
|
|
|
|
|
+ response = self.client_not_me.get(self.old_home_path)
|
|
|
assert_false(doc_id in json.loads(response.context['json_documents']))
|
|
assert_false(doc_id in json.loads(response.context['json_documents']))
|
|
|
|
|
|
|
|
# Share by group
|
|
# Share by group
|
|
@@ -332,9 +332,9 @@ class TestDocModelPermissions():
|
|
|
assert_true(doc.can_read(self.user_not_me))
|
|
assert_true(doc.can_read(self.user_not_me))
|
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
|
|
|
|
|
|
- response = self.client.get('/home2')
|
|
|
|
|
|
|
+ response = self.client.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
- response = self.client_not_me.get('/home2')
|
|
|
|
|
|
|
+ response = self.client_not_me.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
|
|
|
|
|
# Un-share
|
|
# Un-share
|
|
@@ -361,9 +361,9 @@ class TestDocModelPermissions():
|
|
|
assert_false(doc.can_read(self.user_not_me))
|
|
assert_false(doc.can_read(self.user_not_me))
|
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
|
|
|
|
|
|
- response = self.client.get('/home2')
|
|
|
|
|
|
|
+ response = self.client.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
- response = self.client_not_me.get('/home2')
|
|
|
|
|
|
|
+ response = self.client_not_me.get(self.old_home_path)
|
|
|
assert_false(doc_id in json.loads(response.context['json_documents']))
|
|
assert_false(doc_id in json.loads(response.context['json_documents']))
|
|
|
|
|
|
|
|
# Modify by user
|
|
# Modify by user
|
|
@@ -392,9 +392,9 @@ class TestDocModelPermissions():
|
|
|
assert_true(doc.can_read(self.user_not_me))
|
|
assert_true(doc.can_read(self.user_not_me))
|
|
|
assert_true(doc.can_write(self.user_not_me))
|
|
assert_true(doc.can_write(self.user_not_me))
|
|
|
|
|
|
|
|
- response = self.client.get('/home2')
|
|
|
|
|
|
|
+ response = self.client.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
- response = self.client_not_me.get('/home2')
|
|
|
|
|
|
|
+ response = self.client_not_me.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
|
|
|
|
|
# Un-share
|
|
# Un-share
|
|
@@ -421,9 +421,9 @@ class TestDocModelPermissions():
|
|
|
assert_false(doc.can_read(self.user_not_me))
|
|
assert_false(doc.can_read(self.user_not_me))
|
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
|
|
|
|
|
|
- response = self.client.get('/home2')
|
|
|
|
|
|
|
+ response = self.client.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
- response = self.client_not_me.get('/home2')
|
|
|
|
|
|
|
+ response = self.client_not_me.get(self.old_home_path)
|
|
|
assert_false(doc_id in json.loads(response.context['json_documents']))
|
|
assert_false(doc_id in json.loads(response.context['json_documents']))
|
|
|
|
|
|
|
|
# Modify by group
|
|
# Modify by group
|
|
@@ -452,9 +452,9 @@ class TestDocModelPermissions():
|
|
|
assert_true(doc.can_read(self.user_not_me))
|
|
assert_true(doc.can_read(self.user_not_me))
|
|
|
assert_true(doc.can_write(self.user_not_me))
|
|
assert_true(doc.can_write(self.user_not_me))
|
|
|
|
|
|
|
|
- response = self.client.get('/home2')
|
|
|
|
|
|
|
+ response = self.client.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
- response = self.client_not_me.get('/home2')
|
|
|
|
|
|
|
+ response = self.client_not_me.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
|
|
|
|
|
# Un-share
|
|
# Un-share
|
|
@@ -481,9 +481,9 @@ class TestDocModelPermissions():
|
|
|
assert_false(doc.can_read(self.user_not_me))
|
|
assert_false(doc.can_read(self.user_not_me))
|
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
assert_false(doc.can_write(self.user_not_me))
|
|
|
|
|
|
|
|
- response = self.client.get('/home2')
|
|
|
|
|
|
|
+ response = self.client.get(self.old_home_path)
|
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
assert_true(doc_id in json.loads(response.context['json_documents']))
|
|
|
- response = self.client_not_me.get('/home2')
|
|
|
|
|
|
|
+ response = self.client_not_me.get(self.old_home_path)
|
|
|
assert_false(doc_id in json.loads(response.context['json_documents']))
|
|
assert_false(doc_id in json.loads(response.context['json_documents']))
|
|
|
|
|
|
|
|
def test_update_permissions_cannot_escalate_privileges(self):
|
|
def test_update_permissions_cannot_escalate_privileges(self):
|