Add /v2/setting/domains

This commit is contained in:
Son NK 2020-11-14 16:37:36 +01:00
parent ae64bd26b9
commit f452c79aec
3 changed files with 49 additions and 17 deletions

View File

@ -97,3 +97,19 @@ def get_available_domains_for_random_alias():
] ]
return jsonify(ret) 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)

View File

@ -701,28 +701,30 @@ Input:
Output: same as `GET /api/setting` 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 Return domains that user can use to create random alias
`is_custom` is true if this is a user's domain, otherwise false.
```json ```json
[ [
[ {
true, "domain": "d1.test",
"d1.test" "is_custom": false
], },
[ {
true, "domain": "d2.test",
"d2.test" "is_custom": false
], },
[ {
true, "domain": "sl.local",
"sl.local" "is_custom": false
], },
[ {
false, "domain": "ab.cd",
"ab.cd" "is_custom": true
] }
] ]
``` ```

View File

@ -65,3 +65,17 @@ def test_get_setting_domains(flask_client):
[True, "sl.local"], [True, "sl.local"],
[False, "ab.cd"], [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},
]