Skip to content

Commit

Permalink
Add endpoint to see the products available for a team
Browse files Browse the repository at this point in the history
Change-Id: If1bbb42166b2cad4a420d48416c89ecbdbe0800f
  • Loading branch information
rh-gvincent committed Dec 4, 2024
1 parent 5826fb6 commit 18fd2c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dci/api/v1/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ def get_remotecis_by_team(user, team_id):
return remotecis.get_all_remotecis(team.id)


@api.route("/teams/<uuid:team_id>/products", methods=["GET"])
@decorators.login_required
def get_products_team_has_access_to(user, team_id):
if user.is_not_epm() and user.is_not_in_team(team_id):
raise dci_exc.Unauthorized()
team = base.get_resource_orm(models2.Team, team_id)
team_products = [p.serialize() for p in team.products]

return flask.jsonify(
{"products": team_products, "_meta": {"count": len(team_products)}}
)


@api.route("/teams/<uuid:t_id>", methods=["PUT"])
@decorators.login_required
def put_team(user, t_id):
Expand Down
12 changes: 12 additions & 0 deletions tests/api/v1/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,15 @@ def test_create_and_update_team_with_has_pre_release_access_flag(admin, epm):

team_updated = update_team_request.data["team"]
assert team_updated["has_pre_release_access"]


def test_get_products_team_has_access_to(admin, team_user_id, team_user_id2):
products_team_user_request = admin.get("/api/v1/teams/%s/products" % team_user_id)
assert products_team_user_request.status_code == 200
products = products_team_user_request.data["products"]
assert sorted([p["name"] for p in products]) == ["OpenStack", "RHEL"]

products_team_user2_request = admin.get("/api/v1/teams/%s/products" % team_user_id2)
assert products_team_user2_request.status_code == 200
products = products_team_user2_request.data["products"]
assert sorted([p["name"] for p in products]) == ["RHEL"]

0 comments on commit 18fd2c8

Please sign in to comment.