mirror of
https://github.com/simple-login/app.git
synced 2024-11-13 07:31:12 +01:00
Merge pull request #941 from simple-login/enable-filter
support "enabled" param in /api/v2/aliases
This commit is contained in:
commit
3fa820fc2b
3 changed files with 25 additions and 1 deletions
|
@ -80,6 +80,7 @@ def get_aliases_v2():
|
|||
page_id: in query
|
||||
pinned: in query
|
||||
disabled: in query
|
||||
enabled: in query
|
||||
Output:
|
||||
- aliases: list of alias:
|
||||
- id
|
||||
|
@ -112,11 +113,14 @@ def get_aliases_v2():
|
|||
|
||||
pinned = "pinned" in request.args
|
||||
disabled = "disabled" in request.args
|
||||
enabled = "enabled" in request.args
|
||||
|
||||
if pinned:
|
||||
alias_filter = "pinned"
|
||||
elif disabled:
|
||||
alias_filter = "disabled"
|
||||
elif enabled:
|
||||
alias_filter = "enabled"
|
||||
else:
|
||||
alias_filter = None
|
||||
|
||||
|
|
|
@ -313,7 +313,8 @@ Input:
|
|||
at 0.
|
||||
- (Optional) `pinned` in query. If set, only pinned aliases are returned.
|
||||
- (Optional) `disabled` in query. If set, only disabled aliases are returned.
|
||||
Please note `pinned` and `disabled` can't be both present.
|
||||
- (Optional) `enabled` in query. If set, only enabled aliases are returned.
|
||||
Please note `pinned`, `disabled`, `enabled` are exclusive, i.e. only one can be present.
|
||||
- (Optional) query: included in request body. Some frameworks might prevent GET request having a non-empty body, in this
|
||||
case this endpoint also supports POST.
|
||||
|
||||
|
|
|
@ -214,6 +214,25 @@ def test_get_disabled_aliases_v2(flask_client):
|
|||
assert r.json["aliases"][0]["id"] == a0.id
|
||||
|
||||
|
||||
def test_get_enabled_aliases_v2(flask_client):
|
||||
user = login(flask_client)
|
||||
|
||||
a0 = Alias.create_new(user, "prefix0")
|
||||
a0.enabled = False
|
||||
Session.commit()
|
||||
|
||||
r = flask_client.get("/api/v2/aliases?page_id=0")
|
||||
assert r.status_code == 200
|
||||
# the default alias (created when user is created) and a0 are returned
|
||||
assert len(r.json["aliases"]) == 2
|
||||
|
||||
r = flask_client.get("/api/v2/aliases?page_id=0&enabled=true")
|
||||
assert r.status_code == 200
|
||||
# only the first alias is returned
|
||||
assert len(r.json["aliases"]) == 1
|
||||
assert r.json["aliases"][0]["id"] != a0.id
|
||||
|
||||
|
||||
def test_delete_alias(flask_client):
|
||||
user = login(flask_client)
|
||||
|
||||
|
|
Loading…
Reference in a new issue