1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

__magic__

This commit is contained in:
Steffo 2020-06-26 02:41:32 +02:00
parent e6ebee3c6a
commit f57ec497a0
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
2 changed files with 21 additions and 12 deletions

View file

@ -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 user is None:
return False
if lr.role_to_view in user.roles or self.admin_role in user.roles:
return True
return False
return True
@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 user is None:
return False
if lr.role_to_edit in user.roles or self.admin_role in user.roles:
return True
return False
return True
@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)

View file

@ -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)