2020-05-15 18:24:21 +02:00
|
|
|
from typing import Any, Dict, List, Optional, cast
|
2018-07-09 23:22:26 +02:00
|
|
|
|
|
|
|
from openslides.core.config import config
|
2018-12-23 11:05:38 +01:00
|
|
|
from openslides.core.models import Projector
|
2018-07-09 23:22:26 +02:00
|
|
|
from openslides.users.models import User
|
2020-05-15 18:24:21 +02:00
|
|
|
from openslides.utils.projector import (
|
|
|
|
ProjectorAllDataProvider,
|
|
|
|
get_config,
|
|
|
|
register_projector_slide,
|
|
|
|
)
|
2018-07-09 23:22:26 +02:00
|
|
|
|
|
|
|
|
2018-10-28 10:04:52 +01:00
|
|
|
class TConfig:
|
2018-07-09 23:22:26 +02:00
|
|
|
"""
|
|
|
|
Cachable, that fills the cache with the default values of the config variables.
|
|
|
|
"""
|
|
|
|
|
2019-09-02 13:57:12 +02:00
|
|
|
personalized_model = False
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
def get_collection_string(self) -> str:
|
|
|
|
return config.get_collection_string()
|
|
|
|
|
|
|
|
def get_elements(self) -> List[Dict[str, Any]]:
|
|
|
|
elements = []
|
|
|
|
config.key_to_id = {}
|
|
|
|
for id, item in enumerate(config.config_variables.values()):
|
2019-01-06 16:22:33 +01:00
|
|
|
elements.append(
|
|
|
|
{"id": id + 1, "key": item.name, "value": item.default_value}
|
|
|
|
)
|
|
|
|
config.key_to_id[item.name] = id + 1
|
2018-07-09 23:22:26 +02:00
|
|
|
return elements
|
|
|
|
|
2018-11-01 17:30:18 +01:00
|
|
|
async def restrict_elements(
|
2019-01-06 16:22:33 +01:00
|
|
|
self, user_id: int, elements: List[Dict[str, Any]]
|
|
|
|
) -> List[Dict[str, Any]]:
|
2018-10-28 10:04:52 +01:00
|
|
|
return elements
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
|
2018-10-28 10:04:52 +01:00
|
|
|
class TUser:
|
2018-07-09 23:22:26 +02:00
|
|
|
"""
|
2018-12-23 11:05:38 +01:00
|
|
|
Cachable, that fills the cache with fake users.
|
2018-07-09 23:22:26 +02:00
|
|
|
"""
|
|
|
|
|
2019-09-02 13:57:12 +02:00
|
|
|
personalized_model = False
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
def get_collection_string(self) -> str:
|
|
|
|
return User.get_collection_string()
|
|
|
|
|
|
|
|
def get_elements(self) -> List[Dict[str, Any]]:
|
|
|
|
return [
|
2019-01-06 16:22:33 +01:00
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"username": "admin",
|
|
|
|
"title": "",
|
|
|
|
"first_name": "",
|
|
|
|
"last_name": "Administrator",
|
|
|
|
"structure_level": "",
|
|
|
|
"number": "",
|
|
|
|
"about_me": "",
|
|
|
|
"groups_id": [4],
|
|
|
|
"is_present": False,
|
|
|
|
"is_committee": False,
|
|
|
|
"email": "",
|
|
|
|
"last_email_send": None,
|
|
|
|
"comment": "",
|
|
|
|
"is_active": True,
|
|
|
|
"default_password": "admin",
|
|
|
|
"session_auth_hash": "362d4f2de1463293cb3aaba7727c967c35de43ee",
|
|
|
|
}
|
|
|
|
]
|
2018-07-09 23:22:26 +02:00
|
|
|
|
2018-11-01 17:30:18 +01:00
|
|
|
async def restrict_elements(
|
2019-01-06 16:22:33 +01:00
|
|
|
self, user_id: int, elements: List[Dict[str, Any]]
|
|
|
|
) -> List[Dict[str, Any]]:
|
2018-10-28 10:04:52 +01:00
|
|
|
return elements
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
|
2018-12-23 11:05:38 +01:00
|
|
|
class TProjector:
|
|
|
|
"""
|
|
|
|
Cachable, that mocks the projector.
|
|
|
|
"""
|
|
|
|
|
2019-09-02 13:57:12 +02:00
|
|
|
personalized_model = False
|
|
|
|
|
2018-12-23 11:05:38 +01:00
|
|
|
def get_collection_string(self) -> str:
|
|
|
|
return Projector.get_collection_string()
|
|
|
|
|
|
|
|
def get_elements(self) -> List[Dict[str, Any]]:
|
|
|
|
return [
|
2019-01-18 19:11:22 +01:00
|
|
|
{"id": 1, "elements": [{"name": "test/slide1", "id": 1}]},
|
|
|
|
{"id": 2, "elements": [{"name": "test/slide2", "id": 1}]},
|
2018-12-23 11:05:38 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
async def restrict_elements(
|
|
|
|
self, user_id: int, elements: List[Dict[str, Any]]
|
|
|
|
) -> List[Dict[str, Any]]:
|
|
|
|
return elements
|
|
|
|
|
|
|
|
|
2019-03-23 12:06:57 +01:00
|
|
|
async def slide1(
|
2020-05-15 18:24:21 +02:00
|
|
|
all_data_provider: ProjectorAllDataProvider,
|
|
|
|
element: Dict[str, Any],
|
|
|
|
projector_id: int,
|
2019-02-21 14:40:07 +01:00
|
|
|
) -> Dict[str, Any]:
|
2018-12-23 11:05:38 +01:00
|
|
|
"""
|
|
|
|
Slide that shows the general_event_name.
|
|
|
|
"""
|
2019-03-23 12:06:57 +01:00
|
|
|
return {
|
|
|
|
"name": "slide1",
|
2020-05-15 18:24:21 +02:00
|
|
|
"event_name": await get_config(all_data_provider, "general_event_name"),
|
2019-03-23 12:06:57 +01:00
|
|
|
}
|
2018-12-23 11:05:38 +01:00
|
|
|
|
|
|
|
|
2019-03-23 12:06:57 +01:00
|
|
|
async def slide2(
|
2020-05-15 18:24:21 +02:00
|
|
|
all_data_provider: ProjectorAllDataProvider,
|
|
|
|
element: Dict[str, Any],
|
|
|
|
projector_id: int,
|
2019-02-21 14:40:07 +01:00
|
|
|
) -> Dict[str, Any]:
|
2018-12-23 11:05:38 +01:00
|
|
|
return {"name": "slide2"}
|
|
|
|
|
|
|
|
|
2019-01-27 13:17:17 +01:00
|
|
|
register_projector_slide("test/slide1", slide1)
|
|
|
|
register_projector_slide("test/slide2", slide2)
|
2018-12-23 11:05:38 +01:00
|
|
|
|
|
|
|
|
2020-05-15 18:24:21 +02:00
|
|
|
class TestProjectorAllDataProvider:
|
|
|
|
def __init__(self, data):
|
|
|
|
self.data = data
|
2019-01-19 21:36:30 +01:00
|
|
|
|
2020-05-15 18:24:21 +02:00
|
|
|
async def get(self, collection: str, id: int) -> Optional[Dict[str, Any]]:
|
|
|
|
collection_data = await self.get_collection(collection)
|
|
|
|
return collection_data.get(id)
|
2019-01-19 21:36:30 +01:00
|
|
|
|
2020-05-15 18:24:21 +02:00
|
|
|
async def get_collection(self, collection: str) -> Dict[int, Dict[str, Any]]:
|
|
|
|
return self.data.get(collection, {})
|
|
|
|
|
|
|
|
async def exists(self, collection: str, id: int) -> bool:
|
|
|
|
return (await self.get(collection, id)) is not None
|
|
|
|
|
|
|
|
|
|
|
|
def get_all_data_provider(data) -> ProjectorAllDataProvider:
|
|
|
|
data[TConfig().get_collection_string()] = {
|
|
|
|
element["id"]: element for element in TConfig().get_elements()
|
|
|
|
}
|
|
|
|
data[TUser().get_collection_string()] = {
|
|
|
|
element["id"]: element for element in TUser().get_elements()
|
2019-01-19 21:36:30 +01:00
|
|
|
}
|
2020-05-15 18:24:21 +02:00
|
|
|
return cast(ProjectorAllDataProvider, TestProjectorAllDataProvider(data))
|