fix errors
This commit is contained in:
parent
8947b9eafc
commit
fe082026c1
@ -134,16 +134,19 @@ class ImageService:
|
|||||||
# Apply team filtering based on user permissions
|
# Apply team filtering based on user permissions
|
||||||
team_filter = get_team_filter(user)
|
team_filter = get_team_filter(user)
|
||||||
|
|
||||||
# Build filters
|
# Convert collection_id to ObjectId if provided
|
||||||
filters = {}
|
collection_obj_id = ObjectId(collection_id) if collection_id else None
|
||||||
if team_filter:
|
|
||||||
filters["team_id"] = ObjectId(team_filter)
|
|
||||||
if collection_id:
|
|
||||||
filters["collection_id"] = ObjectId(collection_id)
|
|
||||||
|
|
||||||
# Get images
|
# Get images based on user permissions
|
||||||
images = await image_repository.list_with_filters(filters, skip, limit)
|
if team_filter:
|
||||||
total = await image_repository.count_with_filters(filters)
|
# Regular user - filter by team
|
||||||
|
team_obj_id = ObjectId(team_filter)
|
||||||
|
images = await image_repository.get_by_team(team_obj_id, skip, limit, collection_obj_id)
|
||||||
|
total = await image_repository.count_by_team(team_obj_id, collection_obj_id)
|
||||||
|
else:
|
||||||
|
# Admin user - can see all images
|
||||||
|
images = await image_repository.get_all_with_pagination(skip, limit, collection_obj_id)
|
||||||
|
total = await image_repository.count_all(collection_obj_id)
|
||||||
|
|
||||||
# Convert to responses
|
# Convert to responses
|
||||||
image_responses = [
|
image_responses = [
|
||||||
|
|||||||
@ -30,6 +30,16 @@ class AuthorizationContext:
|
|||||||
|
|
||||||
def to_dict(self) -> Dict[str, Any]:
|
def to_dict(self) -> Dict[str, Any]:
|
||||||
"""Convert context to dictionary for logging"""
|
"""Convert context to dictionary for logging"""
|
||||||
|
if self.user is None:
|
||||||
|
return {
|
||||||
|
"user_id": None,
|
||||||
|
"team_id": None,
|
||||||
|
"is_admin": False,
|
||||||
|
"resource_type": self.resource_type,
|
||||||
|
"action": self.action,
|
||||||
|
**self.metadata
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"user_id": str(self.user.id),
|
"user_id": str(self.user.id),
|
||||||
"team_id": str(self.user.team_id),
|
"team_id": str(self.user.team_id),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user