mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
publish: 5.6.1
This commit is contained in:
parent
904597c0ca
commit
68ff79f301
12 changed files with 104 additions and 7 deletions
|
@ -5,7 +5,7 @@
|
|||
|
||||
[tool.poetry]
|
||||
name = "royalnet"
|
||||
version = "5.6"
|
||||
version = "5.6.1"
|
||||
description = "A multipurpose bot and web framework"
|
||||
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
||||
license = "AGPL-3.0+"
|
||||
|
|
|
@ -4,6 +4,10 @@ from .api_login_royalnet import ApiLoginRoyalnetStar
|
|||
from .api_token_info import ApiTokenInfoStar
|
||||
from .api_token_passwd import ApiTokenPasswdStar
|
||||
from .api_token_create import ApiTokenCreateStar
|
||||
from .api_user_get import ApiUserGetStar
|
||||
from .api_user_list import ApiUserListStar
|
||||
from .api_user_find import ApiUserFindStar
|
||||
from .api_alias_list import ApiAliasListStar
|
||||
from .docs import DocsStar
|
||||
|
||||
# Enter the PageStars of your Pack here!
|
||||
|
@ -13,6 +17,10 @@ available_page_stars = [
|
|||
ApiTokenInfoStar,
|
||||
ApiTokenPasswdStar,
|
||||
ApiTokenCreateStar,
|
||||
ApiUserGetStar,
|
||||
ApiUserListStar,
|
||||
ApiUserFindStar,
|
||||
ApiAliasListStar,
|
||||
DocsStar,
|
||||
]
|
||||
|
||||
|
|
25
royalnet/backpack/stars/api_alias_list.py
Normal file
25
royalnet/backpack/stars/api_alias_list.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from starlette.responses import *
|
||||
from royalnet.utils import *
|
||||
from royalnet.backpack.tables import *
|
||||
from royalnet.constellation.api import *
|
||||
|
||||
|
||||
class ApiAliasListStar(ApiStar):
|
||||
path = "/api/alias/list/v1"
|
||||
|
||||
summary = "Get all aliases of the specified user."
|
||||
|
||||
tags = ["alias"]
|
||||
|
||||
parameters = {
|
||||
"user_id": "The id of the user to get the aliases of."
|
||||
}
|
||||
|
||||
async def api(self, data: ApiData) -> JSON:
|
||||
aliases: typing.List[Alias] = await asyncify(
|
||||
data.session
|
||||
.query(self.alchemy.get(Alias))
|
||||
.filter_by(user_id=data["user_id"])
|
||||
.all
|
||||
)
|
||||
return [alias.alias for alias in aliases]
|
|
@ -18,7 +18,7 @@ class ApiLoginRoyalnetStar(ApiStar):
|
|||
"password": "The password of the user you are logging in as."
|
||||
}
|
||||
|
||||
tags = ["royalnet"]
|
||||
tags = ["login"]
|
||||
|
||||
async def api(self, data: ApiData) -> ru.JSON:
|
||||
TokenT = self.alchemy.get(Token)
|
||||
|
|
|
@ -16,7 +16,7 @@ class ApiTokenCreateStar(ApiStar):
|
|||
"duration": "The duration in seconds of the new token."
|
||||
}
|
||||
|
||||
tags = ["royalnet"]
|
||||
tags = ["token"]
|
||||
|
||||
async def api(self, data: ApiData) -> ru.JSON:
|
||||
user = await data.user()
|
||||
|
|
|
@ -7,7 +7,7 @@ class ApiTokenInfoStar(ApiStar):
|
|||
|
||||
summary = "Get info the current login token."
|
||||
|
||||
tags = ["royalnet"]
|
||||
tags = ["token"]
|
||||
|
||||
async def api(self, data: ApiData) -> ru.JSON:
|
||||
token = await data.token()
|
||||
|
|
|
@ -17,7 +17,7 @@ class ApiTokenPasswdStar(ApiStar):
|
|||
"new_password": "The password you want to set."
|
||||
}
|
||||
|
||||
tags = ["royalnet"]
|
||||
tags = ["token"]
|
||||
|
||||
async def api(self, data: ApiData) -> ru.JSON:
|
||||
TokenT = self.alchemy.get(Token)
|
||||
|
|
21
royalnet/backpack/stars/api_user_find.py
Normal file
21
royalnet/backpack/stars/api_user_find.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from royalnet.utils import *
|
||||
from royalnet.backpack.tables import *
|
||||
from royalnet.constellation.api import *
|
||||
|
||||
|
||||
class ApiUserFindStar(ApiStar):
|
||||
path = "/api/user/find/v1"
|
||||
|
||||
summary = "Find a Royalnet user by one of their aliases."
|
||||
|
||||
parameters = {
|
||||
"alias": "One of the aliases of the user to get."
|
||||
}
|
||||
|
||||
tags = ["user"]
|
||||
|
||||
async def api(self, data: ApiData) -> dict:
|
||||
user = await Alias.find_user(self.alchemy, data.session, data["alias"])
|
||||
if user is None:
|
||||
raise NotFoundError("No such user.")
|
||||
return user.json()
|
26
royalnet/backpack/stars/api_user_get.py
Normal file
26
royalnet/backpack/stars/api_user_get.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from royalnet.utils import *
|
||||
from royalnet.backpack.tables import *
|
||||
from royalnet.constellation.api import *
|
||||
|
||||
|
||||
class ApiUserGetStar(ApiStar):
|
||||
path = "/api/user/get/v1"
|
||||
|
||||
summary = "Get a Royalnet user by its id."
|
||||
|
||||
parameters = {
|
||||
"id": "The id of the user to get."
|
||||
}
|
||||
|
||||
tags = ["user"]
|
||||
|
||||
async def api(self, data: ApiData) -> dict:
|
||||
user_id_str = data["id"]
|
||||
try:
|
||||
user_id = int(user_id_str)
|
||||
except (ValueError, TypeError):
|
||||
raise InvalidParameterError("'id' is not a valid int.")
|
||||
user: User = await asyncify(data.session.query(self.alchemy.get(User)).get, user_id)
|
||||
if user is None:
|
||||
raise NotFoundError("No such user.")
|
||||
return user.json()
|
16
royalnet/backpack/stars/api_user_list.py
Normal file
16
royalnet/backpack/stars/api_user_list.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from starlette.responses import *
|
||||
from royalnet.utils import *
|
||||
from royalnet.backpack.tables import *
|
||||
from royalnet.constellation.api import *
|
||||
|
||||
|
||||
class ApiUserListStar(ApiStar):
|
||||
path = "/api/user/list/v1"
|
||||
|
||||
summary = "Get a list of all registered users."
|
||||
|
||||
tags = ["user"]
|
||||
|
||||
async def api(self, data: ApiData) -> dict:
|
||||
users: typing.List[User] = await asyncify(data.session.query(self.alchemy.get(User)).all)
|
||||
return [user.json() for user in users]
|
|
@ -1,3 +1,4 @@
|
|||
from typing import *
|
||||
from sqlalchemy import Column, \
|
||||
Integer, \
|
||||
String, \
|
||||
|
@ -23,7 +24,7 @@ class Alias:
|
|||
return relationship("User", backref="aliases")
|
||||
|
||||
@classmethod
|
||||
async def find_user(cls, alchemy, session, alias: str):
|
||||
async def find_user(cls, alchemy, session, alias: Union[str, int]):
|
||||
result = await ru.asyncify(session.query(alchemy.get(cls)).filter_by(alias=alias.lower()).one_or_none)
|
||||
if result is not None:
|
||||
result = result.user
|
||||
|
|
|
@ -1 +1 @@
|
|||
semantic = "5.6"
|
||||
semantic = "5.6.1"
|
||||
|
|
Loading…
Reference in a new issue