Add /v2/setting/domains
This commit is contained in:
parent
ae64bd26b9
commit
f452c79aec
|
@ -97,3 +97,19 @@ def get_available_domains_for_random_alias():
|
|||
]
|
||||
|
||||
return jsonify(ret)
|
||||
|
||||
|
||||
@api_bp.route("/v2/setting/domains")
|
||||
@require_api_auth
|
||||
def get_available_domains_for_random_alias_v2():
|
||||
"""
|
||||
Available domains for random alias
|
||||
"""
|
||||
user = g.user
|
||||
|
||||
ret = [
|
||||
{"domain": domain, "is_custom": not is_sl}
|
||||
for is_sl, domain in user.available_domains_for_random_alias()
|
||||
]
|
||||
|
||||
return jsonify(ret)
|
||||
|
|
36
docs/api.md
36
docs/api.md
|
@ -701,28 +701,30 @@ Input:
|
|||
|
||||
Output: same as `GET /api/setting`
|
||||
|
||||
#### GET /api/setting/domains
|
||||
#### GET /api/v2/setting/domains
|
||||
|
||||
Return domains that user can use to create random alias
|
||||
|
||||
`is_custom` is true if this is a user's domain, otherwise false.
|
||||
|
||||
```json
|
||||
[
|
||||
[
|
||||
true,
|
||||
"d1.test"
|
||||
],
|
||||
[
|
||||
true,
|
||||
"d2.test"
|
||||
],
|
||||
[
|
||||
true,
|
||||
"sl.local"
|
||||
],
|
||||
[
|
||||
false,
|
||||
"ab.cd"
|
||||
]
|
||||
{
|
||||
"domain": "d1.test",
|
||||
"is_custom": false
|
||||
},
|
||||
{
|
||||
"domain": "d2.test",
|
||||
"is_custom": false
|
||||
},
|
||||
{
|
||||
"domain": "sl.local",
|
||||
"is_custom": false
|
||||
},
|
||||
{
|
||||
"domain": "ab.cd",
|
||||
"is_custom": true
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
|
|
|
@ -65,3 +65,17 @@ def test_get_setting_domains(flask_client):
|
|||
[True, "sl.local"],
|
||||
[False, "ab.cd"],
|
||||
]
|
||||
|
||||
|
||||
def test_get_setting_domains_v2(flask_client):
|
||||
user = login(flask_client)
|
||||
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True, commit=True)
|
||||
|
||||
r = flask_client.get("/api/v2/setting/domains")
|
||||
assert r.status_code == 200
|
||||
assert r.json == [
|
||||
{"domain": "d1.test", "is_custom": False},
|
||||
{"domain": "d2.test", "is_custom": False},
|
||||
{"domain": "sl.local", "is_custom": False},
|
||||
{"domain": "ab.cd", "is_custom": True},
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue