Support note in POST /api/alias/custom/new
This commit is contained in:
parent
417009b3be
commit
aad06f73e9
|
@ -680,6 +680,7 @@ Input:
|
|||
- Request Message Body in json (`Content-Type` is `application/json`)
|
||||
- alias_prefix: string. The first part of the alias that user can choose.
|
||||
- alias_suffix: should be one of the suffixes returned in the `GET /api/v2/alias/options` endpoint.
|
||||
- (Optional) note: alias note
|
||||
|
||||
Output:
|
||||
If success, 201 with the new alias, for example
|
||||
|
|
|
@ -21,6 +21,7 @@ def new_custom_alias():
|
|||
alias_prefix, for ex "www_groupon_com"
|
||||
alias_suffix, either .random_letters@simplelogin.co or @my-domain.com
|
||||
optional "hostname" in args
|
||||
optional "note"
|
||||
Output:
|
||||
201 if success
|
||||
409 if the alias already exists
|
||||
|
@ -46,6 +47,7 @@ def new_custom_alias():
|
|||
|
||||
alias_prefix = data.get("alias_prefix", "").strip()
|
||||
alias_suffix = data.get("alias_suffix", "").strip()
|
||||
note = data.get("note")
|
||||
alias_prefix = convert_to_id(alias_prefix)
|
||||
|
||||
if not verify_prefix_suffix(user, alias_prefix, alias_suffix, user_custom_domains):
|
||||
|
@ -57,7 +59,7 @@ def new_custom_alias():
|
|||
return jsonify(error=f"alias {full_alias} already exists"), 409
|
||||
|
||||
gen_email = GenEmail.create(
|
||||
user_id=user.id, email=full_alias, mailbox_id=user.default_mailbox_id
|
||||
user_id=user.id, email=full_alias, mailbox_id=user.default_mailbox_id, note=note
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
|
|
|
@ -16,17 +16,38 @@ def test_success(flask_client):
|
|||
api_key = ApiKey.create(user.id, "for test")
|
||||
db.session.commit()
|
||||
|
||||
# create new alias with note
|
||||
word = random_word()
|
||||
|
||||
r = flask_client.post(
|
||||
url_for("api.new_custom_alias", hostname="www.test.com"),
|
||||
headers={"Authentication": api_key.code},
|
||||
json={"alias_prefix": "prefix", "alias_suffix": f".{word}@{EMAIL_DOMAIN}"},
|
||||
json={
|
||||
"alias_prefix": "prefix",
|
||||
"alias_suffix": f".{word}@{EMAIL_DOMAIN}",
|
||||
"note": "test note",
|
||||
},
|
||||
)
|
||||
|
||||
assert r.status_code == 201
|
||||
assert r.json["alias"] == f"prefix.{word}@{EMAIL_DOMAIN}"
|
||||
|
||||
new_ge = GenEmail.get_by(email=r.json["alias"])
|
||||
assert new_ge.note == "test note"
|
||||
|
||||
# create alias without note
|
||||
word = random_word()
|
||||
r = flask_client.post(
|
||||
url_for("api.new_custom_alias", hostname="www.test.com"),
|
||||
headers={"Authentication": api_key.code},
|
||||
json={"alias_prefix": "prefix", "alias_suffix": f".{word}@{EMAIL_DOMAIN}",},
|
||||
)
|
||||
|
||||
assert r.status_code == 201
|
||||
assert r.json["alias"] == f"prefix.{word}@{EMAIL_DOMAIN}"
|
||||
|
||||
new_ge = GenEmail.get_by(email=r.json["alias"])
|
||||
assert new_ge.note is None
|
||||
|
||||
|
||||
def test_out_of_quota(flask_client):
|
||||
user = User.create(
|
||||
|
|
Loading…
Reference in a new issue