allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [32/50] [abbrv] allura git commit: [#7633] ticket:768 Add has_access API for ForgeWiki
Date Fri, 05 Jun 2015 18:41:47 GMT
[#7633] ticket:768 Add has_access API for ForgeWiki


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/0f577ade
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/0f577ade
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/0f577ade

Branch: refs/heads/hs/7873
Commit: 0f577ade39781455654bfc54bc987689fd9fcc6e
Parents: c6c2c3b
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri May 15 09:09:08 2015 +0000
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Mon Jun 1 11:15:34 2015 -0400

----------------------------------------------------------------------
 .../forgewiki/tests/functional/test_rest.py     | 51 ++++++++++++++++++++
 ForgeWiki/forgewiki/wiki_main.py                |  3 +-
 2 files changed, 53 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/0f577ade/ForgeWiki/forgewiki/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_rest.py b/ForgeWiki/forgewiki/tests/functional/test_rest.py
index 560503e..23021d2 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_rest.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_rest.py
@@ -100,3 +100,54 @@ class TestWikiApi(TestRestApiBase):
         # make sure these are unchanged
         assert_equal(json.dumps('<'), '"<"')
         assert_equal(simplejson.dumps('<'), '"<"')
+
+
+class TestWikiHasAccess(TestRestApiBase):
+
+    def setUp(self):
+        super(TestWikiHasAccess, self).setUp()
+        self.setup_with_tools()
+
+    @td.with_wiki
+    def setup_with_tools(self):
+        h.set_context('test', 'wiki', neighborhood='Projects')
+
+    def test_has_access_no_params(self):
+        r = self.api_get('/rest/p/test/wiki/has_access', status=404)
+        r = self.api_get('/rest/p/test/wiki/has_access?user=root', status=404)
+        r = self.api_get('/rest/p/test/wiki/has_access?perm=read', status=404)
+
+    def test_has_access_unknown_params(self):
+        """Unknown user and/or permission always False for has_access API"""
+        r = self.api_get(
+            '/rest/p/test/wiki/has_access?user=babadook&perm=read',
+            user='root')
+        assert_equal(r.status_int, 200)
+        assert_equal(r.json['result'], False)
+        r = self.api_get(
+            '/rest/p/test/wiki/has_access?user=test-user&perm=jump',
+            user='root')
+        assert_equal(r.status_int, 200)
+        assert_equal(r.json['result'], False)
+
+    def test_has_access_not_admin(self):
+        """
+        User which has no 'admin' permission on neighborhood can't use
+        has_access API
+        """
+        self.api_get(
+            '/rest/p/test/wiki/has_access?user=test-admin&perm=admin',
+            user='test-user',
+            status=403)
+
+    def test_has_access(self):
+        r = self.api_get(
+            '/rest/p/test/wiki/has_access?user=test-admin&perm=create',
+            user='root')
+        assert_equal(r.status_int, 200)
+        assert_equal(r.json['result'], True)
+        r = self.api_get(
+            '/rest/p/test/wiki/has_access?user=test-user&perm=create',
+            user='root')
+        assert_equal(r.status_int, 200)
+        assert_equal(r.json['result'], False)

http://git-wip-us.apache.org/repos/asf/allura/blob/0f577ade/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index a87ce8d..8ab3f3d 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -41,6 +41,7 @@ from allura.controllers import AppDiscussionController, BaseController,
AppDiscu
 from allura.controllers import DispatchIndex
 from allura.controllers import attachments as ac
 from allura.controllers.feed import FeedArgs, FeedController
+from allura.controllers.rest import AppRestControllerMixin
 from allura.lib import widgets as w
 from allura.lib.widgets import form_fields as ffw
 from allura.lib.widgets.subscriptions import SubscribeForm
@@ -754,7 +755,7 @@ Some *emphasized* and **strong** text
 '''
 
 
-class RootRestController(BaseController):
+class RootRestController(BaseController, AppRestControllerMixin):
 
     def __init__(self):
         self._discuss = AppDiscussionRestController()


Mime
View raw message