add random_alias_suffix to settings api
This commit is contained in:
parent
229dc7fd44
commit
a270c72d60
|
@ -10,6 +10,7 @@ from app.models import (
|
||||||
SLDomain,
|
SLDomain,
|
||||||
CustomDomain,
|
CustomDomain,
|
||||||
SenderFormatEnum,
|
SenderFormatEnum,
|
||||||
|
AliasSuffixEnum,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ def setting_to_dict(user: User):
|
||||||
else "uuid",
|
else "uuid",
|
||||||
"random_alias_default_domain": user.default_random_alias_domain(),
|
"random_alias_default_domain": user.default_random_alias_domain(),
|
||||||
"sender_format": SenderFormatEnum.get_name(user.sender_format),
|
"sender_format": SenderFormatEnum.get_name(user.sender_format),
|
||||||
|
"random_alias_suffix": AliasSuffixEnum.get_name(user.random_alias_suffix),
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
@ -71,6 +73,13 @@ def update_setting():
|
||||||
user.sender_format = SenderFormatEnum.get_value(sender_format)
|
user.sender_format = SenderFormatEnum.get_value(sender_format)
|
||||||
user.sender_format_updated_at = arrow.now()
|
user.sender_format_updated_at = arrow.now()
|
||||||
|
|
||||||
|
if "random_alias_suffix" in data:
|
||||||
|
random_alias_suffix = data["random_alias_suffix"]
|
||||||
|
if not AliasSuffixEnum.has_name(random_alias_suffix):
|
||||||
|
return jsonify(error="Invalid random_alias_suffix"), 400
|
||||||
|
|
||||||
|
user.random_alias_suffix = AliasSuffixEnum.get_value(random_alias_suffix)
|
||||||
|
|
||||||
if "random_alias_default_domain" in data:
|
if "random_alias_default_domain" in data:
|
||||||
default_domain = data["random_alias_default_domain"]
|
default_domain = data["random_alias_default_domain"]
|
||||||
sl_domain: SLDomain = SLDomain.get_by(domain=default_domain)
|
sl_domain: SLDomain = SLDomain.get_by(domain=default_domain)
|
||||||
|
|
18
docs/api.md
18
docs/api.md
|
@ -717,13 +717,13 @@ List of deleted alias.
|
||||||
Delete a contact
|
Delete a contact
|
||||||
|
|
||||||
Input:
|
Input:
|
||||||
|
|
||||||
- `Authentication` header that contains the api key
|
- `Authentication` header that contains the api key
|
||||||
- `contact_id` in url.
|
- `contact_id` in url.
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
If success, 200.
|
If success, 200.
|
||||||
|
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"deleted": true
|
"deleted": true
|
||||||
|
@ -735,6 +735,7 @@ If success, 200.
|
||||||
Block/unblock contact
|
Block/unblock contact
|
||||||
|
|
||||||
Input:
|
Input:
|
||||||
|
|
||||||
- `Authentication` header that contains the api key
|
- `Authentication` header that contains the api key
|
||||||
- `contact_id` in url.
|
- `contact_id` in url.
|
||||||
|
|
||||||
|
@ -748,15 +749,18 @@ If success, 200 along with the new alias status:
|
||||||
```
|
```
|
||||||
|
|
||||||
### Notification endpoints
|
### Notification endpoints
|
||||||
|
|
||||||
#### GET /api/notifications
|
#### GET /api/notifications
|
||||||
|
|
||||||
Get notifications
|
Get notifications
|
||||||
|
|
||||||
Input:
|
Input:
|
||||||
|
|
||||||
- `Authentication` in header: the api key
|
- `Authentication` in header: the api key
|
||||||
- page in url: the page number, starts at 0
|
- page in url: the page number, starts at 0
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
|
|
||||||
- more: whether there's more notifications
|
- more: whether there's more notifications
|
||||||
- notifications: list of notification, each notification has:
|
- notifications: list of notification, each notification has:
|
||||||
- id
|
- id
|
||||||
|
@ -785,6 +789,7 @@ For example
|
||||||
Mark a notification as read
|
Mark a notification as read
|
||||||
|
|
||||||
Input:
|
Input:
|
||||||
|
|
||||||
- `Authentication` in header: the api key
|
- `Authentication` in header: the api key
|
||||||
- notification_id in url: the page number, starts at 0
|
- notification_id in url: the page number, starts at 0
|
||||||
|
|
||||||
|
@ -802,7 +807,8 @@ Return user setting.
|
||||||
"alias_generator": "word",
|
"alias_generator": "word",
|
||||||
"notification": true,
|
"notification": true,
|
||||||
"random_alias_default_domain": "sl.local",
|
"random_alias_default_domain": "sl.local",
|
||||||
"sender_format": "VIA"
|
"sender_format": "AT",
|
||||||
|
"random_alias_suffix": "random_string"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -811,10 +817,12 @@ Return user setting.
|
||||||
Update user setting. All input fields are optional.
|
Update user setting. All input fields are optional.
|
||||||
|
|
||||||
Input:
|
Input:
|
||||||
- alias_generator (string): uuid or word
|
|
||||||
- notification (boolean): true or false
|
- alias_generator (string): `uuid` or `word`
|
||||||
|
- notification (boolean): `true` or `false`
|
||||||
- random_alias_default_domain (string): one of the domains returned by `GET /api/setting/domains`
|
- random_alias_default_domain (string): one of the domains returned by `GET /api/setting/domains`
|
||||||
- sender_format (string): possible values are AT, VIA, A, FULL
|
- sender_format (string): possible values are `AT`, `A`, `NAME_ONLY`, `AT_ONLY`, `NO_NAME`
|
||||||
|
- random_alias_suffix (string): possible values are `word`, `random_string`
|
||||||
|
|
||||||
Output: same as `GET /api/setting`
|
Output: same as `GET /api/setting`
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
from app.models import CustomDomain, AliasGeneratorEnum, SenderFormatEnum
|
from app.models import (
|
||||||
|
CustomDomain,
|
||||||
|
AliasGeneratorEnum,
|
||||||
|
SenderFormatEnum,
|
||||||
|
AliasSuffixEnum,
|
||||||
|
)
|
||||||
from tests.utils import login
|
from tests.utils import login
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +17,7 @@ def test_get_setting(flask_client):
|
||||||
"notification": True,
|
"notification": True,
|
||||||
"random_alias_default_domain": "sl.local",
|
"random_alias_default_domain": "sl.local",
|
||||||
"sender_format": "AT",
|
"sender_format": "AT",
|
||||||
|
"random_alias_suffix": "random_string",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,6 +69,10 @@ def test_update_settings_sender_format(flask_client):
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert user.sender_format == SenderFormatEnum.A.value
|
assert user.sender_format == SenderFormatEnum.A.value
|
||||||
|
|
||||||
|
r = flask_client.patch("/api/setting", json={"sender_format": "NAME_ONLY"})
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert user.sender_format == SenderFormatEnum.NAME_ONLY.value
|
||||||
|
|
||||||
|
|
||||||
def test_get_setting_domains(flask_client):
|
def test_get_setting_domains(flask_client):
|
||||||
user = login(flask_client)
|
user = login(flask_client)
|
||||||
|
@ -78,3 +88,16 @@ def test_get_setting_domains_v2(flask_client):
|
||||||
|
|
||||||
r = flask_client.get("/api/v2/setting/domains")
|
r = flask_client.get("/api/v2/setting/domains")
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_settings_random_alias_suffix(flask_client):
|
||||||
|
user = login(flask_client)
|
||||||
|
# default random_alias_suffix is random_string
|
||||||
|
assert user.random_alias_suffix == AliasSuffixEnum.random_string.value
|
||||||
|
|
||||||
|
r = flask_client.patch("/api/setting", json={"random_alias_suffix": "invalid"})
|
||||||
|
assert r.status_code == 400
|
||||||
|
|
||||||
|
r = flask_client.patch("/api/setting", json={"random_alias_suffix": "word"})
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert user.random_alias_suffix == AliasSuffixEnum.word.value
|
||||||
|
|
Loading…
Reference in a new issue