From f57ec497a082e0ef77af6daf794a3570bc2456e2 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 26 Jun 2020 02:41:32 +0200 Subject: [PATCH] __magic__ --- wikipack/stars/api_wiki.py | 30 ++++++++++++++++++++---------- wikipack/stars/api_wiki_list.py | 3 +-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/wikipack/stars/api_wiki.py b/wikipack/stars/api_wiki.py index d4352cd7..7f49f291 100644 --- a/wikipack/stars/api_wiki.py +++ b/wikipack/stars/api_wiki.py @@ -11,8 +11,6 @@ class ApiWikiStar(rca.ApiStar): tags = ["wiki"] - methods = ["GET", "POST", "PUT", "DELETE"] - parameters = { "get": { "page_id": "The id of the wiki page to get the details of." @@ -62,11 +60,12 @@ class ApiWikiStar(rca.ApiStar): if lr.role_to_view == "*": return True - if lr.role_to_view: - if lr.role_to_view in user.roles or self.admin_role in user.roles: - return True + if user is None: return False - return True + + if lr.role_to_view in user.roles or self.admin_role in user.roles: + return True + return False @property def default_edit_role(self) -> str: @@ -76,11 +75,12 @@ class ApiWikiStar(rca.ApiStar): if lr.role_to_edit == "*": return True - if lr.role_to_edit: - if lr.role_to_edit in user.roles or self.admin_role in user.roles: - return True + if user is None: return False - return True + + if lr.role_to_edit in user.roles or self.admin_role in user.roles: + return True + return False @property def create_role(self) -> str: @@ -90,6 +90,9 @@ class ApiWikiStar(rca.ApiStar): if self.create_role == "*": return True + if user is None: + return False + if self.create_role in user.roles or self.admin_role in user.roles: return True return False @@ -102,6 +105,9 @@ class ApiWikiStar(rca.ApiStar): if self.delete_role == "*": return True + if user is None: + return False + if self.delete_role in user.roles or self.admin_role in user.roles: return True return False @@ -128,6 +134,7 @@ class ApiWikiStar(rca.ApiStar): return lr + @rca.magic async def get(self, data: rca.ApiData) -> ru.JSON: """Get the details of a specific Wiki page.""" lr = await self.find_lr(data) @@ -142,6 +149,7 @@ class ApiWikiStar(rca.ApiStar): return lr.json() + @rca.magic async def post(self, data: rca.ApiData) -> ru.JSON: """Create a new Wiki page.""" WikiRevisionT = self.alchemy.get(WikiRevision) @@ -177,6 +185,7 @@ class ApiWikiStar(rca.ApiStar): return nr.json() + @rca.magic async def put(self, data: rca.ApiData) -> ru.JSON: """Edit a specific Wiki page, creating a new revision.""" WikiRevisionT = self.alchemy.get(WikiRevision) @@ -215,6 +224,7 @@ class ApiWikiStar(rca.ApiStar): return nr.json() + @rca.magic async def delete(self, data: rca.ApiData) -> ru.JSON: """Delete a specific Wiki page and all its revisions.""" WikiRevisionT = self.alchemy.get(WikiRevision) diff --git a/wikipack/stars/api_wiki_list.py b/wikipack/stars/api_wiki_list.py index 94584b9e..719ac919 100644 --- a/wikipack/stars/api_wiki_list.py +++ b/wikipack/stars/api_wiki_list.py @@ -12,8 +12,6 @@ class ApiWikiListStar(rca.ApiStar): tags = ["wiki"] - methods = ["GET"] - parameters = { "get": {}, } @@ -22,6 +20,7 @@ class ApiWikiListStar(rca.ApiStar): "get": False, } + @rca.magic async def get(self, data: rca.ApiData) -> ru.JSON: """Get the details of a specific Wiki page.""" WikiRevisionT = self.alchemy.get(WikiRevision)