private shares and revokation works
This commit is contained in:
@@ -33,18 +33,37 @@ def create_map_share(
|
||||
detail="Only the map owner can share it"
|
||||
)
|
||||
|
||||
# Check if user exists
|
||||
target_user = db.query(User).filter(User.id == share_data.user_id).first()
|
||||
# Look up user by username, email, or UUID
|
||||
target_user = None
|
||||
user_identifier = share_data.user_identifier.strip()
|
||||
|
||||
# Try UUID first
|
||||
try:
|
||||
user_uuid = UUID(user_identifier)
|
||||
target_user = db.query(User).filter(User.id == user_uuid).first()
|
||||
except ValueError:
|
||||
# Not a valid UUID, try username or email
|
||||
target_user = db.query(User).filter(
|
||||
(User.username == user_identifier) | (User.email == user_identifier)
|
||||
).first()
|
||||
|
||||
if not target_user:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="User not found"
|
||||
detail=f"User not found with identifier: {user_identifier}"
|
||||
)
|
||||
|
||||
# Prevent sharing with self
|
||||
if target_user.id == current_user.id:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Cannot share map with yourself"
|
||||
)
|
||||
|
||||
# Check if already shared
|
||||
existing_share = db.query(MapShare).filter(
|
||||
MapShare.map_id == map_id,
|
||||
MapShare.user_id == share_data.user_id
|
||||
MapShare.user_id == target_user.id
|
||||
).first()
|
||||
|
||||
if existing_share:
|
||||
@@ -58,7 +77,7 @@ def create_map_share(
|
||||
# Create new share
|
||||
share = MapShare(
|
||||
map_id=map_id,
|
||||
user_id=share_data.user_id,
|
||||
user_id=target_user.id,
|
||||
permission=share_data.permission,
|
||||
shared_by=current_user.id
|
||||
)
|
||||
@@ -120,7 +139,7 @@ def update_map_share(
|
||||
return share
|
||||
|
||||
|
||||
def delete_map_share(
|
||||
async def delete_map_share(
|
||||
db: Session,
|
||||
map_id: UUID,
|
||||
share_id: UUID,
|
||||
@@ -146,9 +165,16 @@ def delete_map_share(
|
||||
detail="Share not found"
|
||||
)
|
||||
|
||||
# Get user_id before deleting the share
|
||||
revoked_user_id = share.user_id
|
||||
|
||||
db.delete(share)
|
||||
db.commit()
|
||||
|
||||
# Disconnect the user's WebSocket connections
|
||||
from app.websocket.connection_manager import manager
|
||||
await manager.disconnect_user(map_id, revoked_user_id)
|
||||
|
||||
|
||||
def create_share_link(
|
||||
db: Session,
|
||||
|
||||
Reference in New Issue
Block a user