mirror of
https://github.com/simple-login/app.git
synced 2025-02-23 15:23:27 +08:00
Add GET /api/setting
This commit is contained in:
parent
91534d3cf2
commit
77bf9537d0
4 changed files with 54 additions and 0 deletions
13
README.md
13
README.md
|
@ -1381,6 +1381,19 @@ Input:
|
|||
Output:
|
||||
200 if success
|
||||
|
||||
### Settings endpoints
|
||||
|
||||
#### GET /api/setting
|
||||
|
||||
Return user setting
|
||||
|
||||
```json
|
||||
{
|
||||
"alias_generator": "uuid",
|
||||
"notification": true,
|
||||
"random_alias_default_domain": "sl.local"
|
||||
}
|
||||
```
|
||||
|
||||
### Misc endpoints
|
||||
#### POST /api/apple/process_payment
|
||||
|
|
|
@ -9,4 +9,5 @@ from .views import (
|
|||
apple,
|
||||
mailbox,
|
||||
notification,
|
||||
setting,
|
||||
)
|
||||
|
|
27
app/api/views/setting.py
Normal file
27
app/api/views/setting.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from flask import jsonify, g
|
||||
|
||||
from app.api.base import api_bp, require_api_auth
|
||||
from app.models import User, AliasGeneratorEnum
|
||||
|
||||
|
||||
def setting_to_dict(user: User):
|
||||
ret = {
|
||||
"notification": user.notification,
|
||||
"alias_generator": "word"
|
||||
if user.alias_generator == AliasGeneratorEnum.word
|
||||
else "uuid",
|
||||
"random_alias_default_domain": user.default_random_alias_domain(),
|
||||
}
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
@api_bp.route("/setting")
|
||||
@require_api_auth
|
||||
def get_setting():
|
||||
"""
|
||||
Return user setting
|
||||
"""
|
||||
user = g.user
|
||||
|
||||
return jsonify(setting_to_dict(user))
|
13
tests/api/test_setting.py
Normal file
13
tests/api/test_setting.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from tests.utils import login
|
||||
|
||||
|
||||
def test_get_setting(flask_client):
|
||||
user = login(flask_client)
|
||||
|
||||
r = flask_client.get("/api/setting")
|
||||
assert r.status_code == 200
|
||||
assert r.json == {
|
||||
"alias_generator": "uuid",
|
||||
"notification": True,
|
||||
"random_alias_default_domain": "sl.local",
|
||||
}
|
Loading…
Reference in a new issue