Skip to content

Commit

Permalink
fix: refactor multi tenant policy so it works for tickets
Browse files Browse the repository at this point in the history
Introduce the collection_mapper where you can define which path needs to use which collection

* Release v0.0.72

---------

Co-authored-by: Delsin Van Grembergen <[email protected]>
  • Loading branch information
Delsinvg and Delsin Van Grembergen authored Apr 29, 2024
1 parent 5a957c3 commit 528a86e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "elody"
version = "0.0.71"
version = "0.0.72"
description = "elody SDK for Python"
readme = "README.md"
authors = [{ name = "Inuits", email = "[email protected]" }]
Expand Down
7 changes: 5 additions & 2 deletions src/elody/policies/authorization/multi_tenant_policy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import app # type: ignore

from flask_restful import abort
from inuits_policy_based_auth import BaseAuthorizationPolicy, RequestContext
from inuits_policy_based_auth.contexts import UserContext, PolicyContext
Expand Down Expand Up @@ -41,15 +43,16 @@ def authorize(
policy_context.access_verdict = True
if item_id:
storage = StorageManager().get_db_engine()
collection = request.path.split("/")[1]
request_name = request.path.split("/")[1]
collection = app.collection_mapper.get(request_name, request_name)
item = storage.get_item_from_collection_by_id(collection, item_id)
if not item:
abort(
404,
message=f"Item with id {id} doesn't exist in collection {collection}",
)
item_relations = storage.get_collection_item_relations(collection, item_id)
if not any(
if item.get("type") != "ticket" and not any(
x
for x in item_relations
if x["type"] == "isIn" and x["key"] == user_context.x_tenant.raw["_id"]
Expand Down

0 comments on commit 528a86e

Please sign in to comment.