OpenSlides/openslides/mediafiles/access_permissions.py

33 lines
1.0 KiB
Python
Raw Normal View History

from typing import Any, Dict, List
2018-08-22 22:00:08 +02:00
from ..utils.access_permissions import BaseAccessPermissions
from ..utils.auth import async_has_perm
class MediafileAccessPermissions(BaseAccessPermissions):
"""
Access permissions container for Mediafile and MediafileViewSet.
"""
2019-01-06 16:22:33 +01:00
base_permission = "mediafiles.can_see"
async def get_restricted_data(
2019-01-06 16:22:33 +01:00
self, full_data: List[Dict[str, Any]], user_id: int
) -> List[Dict[str, Any]]:
"""
Returns the restricted serialized data for the instance prepared
for the user. Removes hidden mediafiles for some users.
"""
# Parse data.
2019-01-06 16:22:33 +01:00
if await async_has_perm(user_id, "mediafiles.can_see") and await async_has_perm(
user_id, "mediafiles.can_see_hidden"
):
data = full_data
2019-01-06 16:22:33 +01:00
elif await async_has_perm(user_id, "mediafiles.can_see"):
# Exclude hidden mediafiles.
2019-01-06 16:22:33 +01:00
data = [full for full in full_data if not full["hidden"]]
else:
data = []
return data