mirror of
https://github.com/simple-login/app.git
synced 2025-02-23 15:23:27 +08:00
user can cancel mailbox email change
This commit is contained in:
parent
2f087de061
commit
3eb6700232
3 changed files with 45 additions and 0 deletions
|
@ -1198,6 +1198,7 @@ Input:
|
|||
- `mailbox_id`: in url
|
||||
- (optional) `default`: boolean. Set a mailbox as default mailbox.
|
||||
- (optional) `email`: email address. Change a mailbox email address.
|
||||
- (optional) `cancel_email_change`: boolean. Cancel mailbox email change.
|
||||
|
||||
Output:
|
||||
- 200 if updated successfully
|
||||
|
|
|
@ -98,6 +98,7 @@ def update_mailbox(mailbox_id):
|
|||
mailbox_id: in url
|
||||
(optional) default: in body. Set a mailbox as the default mailbox.
|
||||
(optional) email: in body. Change a mailbox email.
|
||||
(optional) cancel_email_change: in body. Cancel mailbox email change.
|
||||
Output:
|
||||
200 if updated successfully
|
||||
|
||||
|
@ -138,6 +139,12 @@ def update_mailbox(mailbox_id):
|
|||
mailbox.new_email = new_email
|
||||
changed = True
|
||||
|
||||
if "cancel_email_change" in data:
|
||||
cancel_email_change = data.get("cancel_email_change")
|
||||
if cancel_email_change:
|
||||
mailbox.new_email = None
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
db.session.commit()
|
||||
|
||||
|
|
|
@ -121,3 +121,40 @@ def test_update_mailbox_email(flask_client):
|
|||
|
||||
mb = Mailbox.get(mb.id)
|
||||
assert mb.new_email == "new-email@gmail.com"
|
||||
|
||||
|
||||
def test_cancel_mailbox_email_change(flask_client):
|
||||
user = User.create(
|
||||
email="a@b.c", password="password", name="Test User", activated=True
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
# create api_key
|
||||
api_key = ApiKey.create(user.id, "for test")
|
||||
db.session.commit()
|
||||
|
||||
# create a mailbox
|
||||
mb = Mailbox.create(user_id=user.id, email="mb@gmail.com")
|
||||
db.session.commit()
|
||||
|
||||
# update mailbox email
|
||||
r = flask_client.put(
|
||||
url_for("api.delete_mailbox", mailbox_id=mb.id),
|
||||
headers={"Authentication": api_key.code},
|
||||
json={"email": "new-email@gmail.com"},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
|
||||
mb = Mailbox.get(mb.id)
|
||||
assert mb.new_email == "new-email@gmail.com"
|
||||
|
||||
# cancel mailbox email change
|
||||
r = flask_client.put(
|
||||
url_for("api.delete_mailbox", mailbox_id=mb.id),
|
||||
headers={"Authentication": api_key.code},
|
||||
json={"cancel_email_change": True},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
|
||||
mb = Mailbox.get(mb.id)
|
||||
assert mb.new_email is None
|
||||
|
|
Loading…
Reference in a new issue