Skip to content

Commit

Permalink
support "enabled" param in /api/v2/aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenkims committed Apr 28, 2022
1 parent 46646f4 commit a2c477a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/api/views/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
19 changes: 19 additions & 0 deletions tests/api/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit a2c477a

Please sign in to comment.